CentOS7安装和配置MySQL5.7
查看yum是否安装过mysql yum list installed mysql*
通过命令卸载:
yum remove mysql-community-client mysql-community-common mysql-community-libs mysql-community-libs-compat mysql-community-server mysql57-community-release rm -rf /var/lib/mysql rm /etc/my.cnf
检查RPM包
rpm -qa | grep -i mysql
卸载RPM包:
rpm -e mysql57-community-release-el7-9.noarch rpm -e mysql-community-server-5.7.17-1.el7.x86_64 rpm -e mysql-community-libs-5.7.17-1.el7.x86_64 rpm -e mysql-community-libs-compat-5.7.17-1.el7.x86_64 rpm -e mysql-community-common-5.7.17-1.el7.x86_64 rpm -e mysql-community-client-5.7.17-1.el7.x86_64
cd /var/lib/ rm -rf mysql/
清除余项
whereis mysql
mysql: /usr/bin/mysql /usr/lib64/mysql /usr/local/mysql /usr/share/mysql /usr/share/man/man1/mysql.1.gz
#删除上面的文件夹
rm -rf /usr/bin/mysql
删除配置
rm –rf /usr/my.cnf rm -rf /root/.mysql_sercret
剩余配置检查
chkconfig --list | grep -i mysql chkconfig --del mysqld
根据上面的列表,删除 ,如:mysqld
如果有装MariaDB,参考同样方式卸载。
安装:
wget http://repo.mysql.com/mysql57-community-release-el7-10.noarch.rpm sudo rpm -ivh mysql57-community-release-el7-10.noarch.rpm
接下来使用yum安装
更新yum软件包
yum check-update
更新软件
yum update
yum update 更新报错解决
当在CentOS 7中使用yum update更新软件时,可能会遇到如下错误信息:
Error: Delta RPMs disabled because /usr/bin/applydeltarpm not installed.
解决这个问题需要安装deltarpm,可以先通过如下命令查找该包的包名:
yum provides '*/applydeltarpm'
然后用如下命令安装即可解决:
yum install deltarpm
安装mysql
yum install mysql mysql-server
接下来是漫长的等待。如果中途关机,或者下载挂了,请执行卸载步骤后,再来一次。
完成后
给root上密码
获取MySQL的临时密码
为了加强安全性,MySQL5.7为root用户随机生成了一个密码,在error log中,关于error log的位置,如果安装的是RPM包,则默认是/var/log/mysqld.log。
只有启动过一次mysql才可以查看临时密码
grep 'temporary password' /var/log/mysqld.log
```
[root@localhost etc]# grep 'temporary password' /var/log/mysqld.log
2019-01-10T01:58:42.323205Z 1 [Note] A temporary password is generated for root@localhost: de-cr(6g/_E=
```
所以临时密码为:de-cr(6g/_E=
使用临时密码登陆成功后,立刻修改密码
```
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY '123456';
ERROR 1819 (HY000): Your password does not satisfy the current policy requirements
```
必须修改两个全局参数:
首先,修改validate_password_policy参数的值
mysql> set global validate_password_policy=0;
再修改密码的长度
mysql> set global validate_password_length=1;
再次执行修改密码就可以了
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY '123456';
初始化一个新库并给用户授权:
CREATE SCHEMA `xpy` DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci ;
创建用户并授权:
grant all privileges on `xpy`.* to 'xpyopr'@'%' identified by 'xpy123456';