一、MYSQL安装
1.下载安装包
下载地址:
MySQL :: Download MySQL Community Server
2.登录root用户
2.1 关闭selinux
vi /etc/selinux/config
SELINUX =disabled
保存退出(按esc,再:wq)
2.2 关闭防火墙
#如果想永久停止防火墙,执行下面操作#停止firewall
systemctl stop firewalld.service
#禁止firewall开机启动
systemctl disable firewalld.service
#查看防火墙状态(关闭后显示notrunning,开启后显示running)
firewall-cmd --state
2.3 重启(reboot)
3.卸载自带的mariadb
3.1 rpm -qa | grep mariadb
3.2 rpm -e --nodeps (mariadb上一步查询的结果)
4.解压tar包,安装rpm
4.1 创建目录 mkdir -p /repo
4.2 上传mysql安装包至此目录
4.3 tar -vxf mysql-5.7.25-1.el7.x86_64.rpm-bundle.tar
4.4 使用rpm -ivh命令依次进行安装;以下步骤需要root权限。且因包之间的依赖关系,各rpm命令必须按序执行。
rpm -ivh mysql-community-common-5.7.20-1.el7.x86_64.rpm
rpm -ivh mysql-community-libs-5.7.20-1.el7.x86_64.rpm
rpm -ivh mysql-community-client-5.7.20-1.el7.x86_64.rpm
rpm -ivh mysql-community-server-5.7.20-1.el7.x86_64.rpm
注意:
#### 安装mysql-community-server-5.7.20-1.el7.x86_64.rpm前需要安装libaio-0.3.107-10.el6.x86_64.rpm
下载地址:http://mirror.centos.org/centos/6/os/x86_64/Packages/libaio-0.3.107-10.el6.x86_64.rpm
rpm -ivh libaio-0.3.107-10.el6.x86_64.rpm(若在有网情况下可执行yum install libaio)
如果提示缺少net-tools:rpm -ivh net-tools-2.0-0.24.20131004git.el7.x86_64.rpm
5.查看安装情
rpm -qa|grep mysql
6.初始化和启动数据库;数据库初始化有时候反应会比较慢,请耐心等待。初始化成功后会生成一个随机密码
mysqld --initialize --user=mysql
以下命令查看生成的密码
grep 'temporary password' /var/log/mysqld.log
7.启动mysql
1.启动:systemctl start mysqld
2.查看状态:service mysqld status
3.停止服务:systemctl stop firewalld.service
4.重启MySQL: systemctl restart mysqld
8.修改root密码 登陆mysql数据库,登陆时,复制以上生成的密码即可,蓝色部分为生成的密码
mysql -u root -p
mysql> Enter password: (输入刚才查询到的随机密码)
mysql> SET PASSWORD FOR 'root'@'localhost'= "123456";
mysql> exit
9.设置远程登录
1.登陆mysql数据库:mysql -u root -p
2.查看user表:mysql> use mysql;
3.设置远程连接
mysql> grant all privileges on *.* to root@'%' identified by "password";
Query OK, 0 rows affected (0.00 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
10.设置自动启动
systemctl enable mysqld
11.修改权限
切换到 mysql 数据库:mysql > use mysql;
查询要修改的数据:mysql >selcet host,user,password from user;
将 host 的数据改为 % :mysql >update user set host='%' where user='root';
刷新用户权限表:mysql >flush privileges;
检验更改的权限:mysql >select host,user,password from uesr where user='root';
二、导入数据库
1、首先建空数据库
mysql>create database redmine3;
2、导入数据库
方法一:
(1)选择数据库
mysql>use redmine3;
(2)设置数据库编码
mysql>set names utf8;
(3)导入数据(注意sql文件的路径)
mysql>source /root/redmine3.sql;
方法二:
mysql -u用户名 -p密码 数据库名 < 数据库名.sql
#mysql -uabc_f -p redmine3 < redmine3.sql
修改validate_password_policy参数的值
mysql> set global validate_password_policy=0;
Query OK, 0 rows affected (0.00 sec)
validate_password_length(密码长度)参数默认为8,我们修改为1
mysql> set global validate_password_length=1;
Query OK, 0 rows affected (0.00 sec)
4,完成之后再次执行修改密码语句即可成功
mysql> alter user 'root'@'localhost' identified by '123456';
Query OK, 0 rows affected (0.00 sec)