官网:https://downloads.mysql.com/archives/community/
创建mysql文件夹
mkdir -p /usr/local/mysql
上传安装包至上面文件夹
解压
tar xvf mysql-5.7.9-1.el7.x86_64.rpm-bundle.tar
查找Mysql的MariaDB依赖
rpm -qa|grep mariadb
若是有,需要卸载。
rpm -e mariadb-libs-5.5.56-2.el7.x86_64 --nodeps
CentOS7默认安装MariaDb,必须要检查是否已经卸载。
依次安装mysql的rpm包(common,libs,client,server)
rpm -ivh mysql-community-common-5.7.9-1.el7.x86_64.rpm
rpm -ivh mysql-community-libs-5.7.9-1.el7.x86_64.rpm
rpm -ivh mysql-community-client-5.7.9-1.el7.x86_64.rpm
rpm -ivh mysql-community-server-5.7.9-1.el7.x86_64.rpm --force --nodeps
启动mysql
service mysqld start
查找初始密码
grep password /var/log/mysqld.log
连接mysql
mysql -uroot -p
然后输入上面的密码
修改密码
ALTER USER 'root'@'localhost' IDENTIFIED BY 'xxxx';
修改mysql访问权限
use mysql;
然后更改用户的访问权限(%代表任何地址都可以访问)
update user set host='%' where user = 'root';
最后刷新权限缓存,立即生效
flush privileges;
加入防火墙白名单端口3306
firewall-cmd --zone=public --add-port=3306/tcp --permanent
firewall-cmd --reload
验证