本文详细介绍了 CentOS 7 系统中安装 MySQL 5.7 的详细步骤,并配置远程连接。
- rpm -qa|grep -i mysql
-
如果有,全部删除所列的内容,直至rpm -qa|grep -i mysql时没有内容
- rpm -ev mysql-community-libs-5.6.37-2.el7.x86_64
-
- wget http://repo.mysql.com/mysql57-community-release-el7-8.noarch.rpm
-
- rpm --import https://repo.mysql.com/RPM-GPG-KEY-mysql-2022
-
- rpm -ivh mysql57-community-release-el7-8.noarch.rpm --nodeps --force
-
- yum install mysql-server
-
- systemctl start mysqld
-
- service mysqld status
-
查看默认密码
- grep 'temporary password' /var/log/mysqld.log
- mysql -u root -p
- mysql> Enter password: (输入刚才查询到的随机密码)
- mysql> SET PASSWORD FOR 'root'@'localhost'= "Root-123";
- mysql> exit;
-
用root新密码登录:
- mysql -u root -pRoot-123
-
允许使用用户名root密码Root-123456从任何主机连接到mysql服务器
- mysql>GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'Root-123456' WITH GRANT OPTION;
- mysql>FLUSH PRIVILEGES;
- mysql>exit;
-
开启防火墙 MySQL 3306 端口的外部访问
- firewall-cmd --zone=public --add-port=3306/tcp --permanent
- firewall-cmd --reload
-