Centos7 安装 MySQL5.7踩坑实录
1.使用 wget 获取 rpm
-
wget -i -c http://dev.mysql.com/get/mysql57-community-release-el7-10.noarch.rpm
-
yum -y install mysql57-community-release-el7-10.noarch.rpm
-
yum -y install mysql-community-server
这里可能会出现问题,没有 yum, 或者没有 wget,都需要自己预先准备好环境
其次我还遇到了如下问题:
The GPG keys listed for the “MySQL 5.7 Community Server” repository are already installed but they are not correct for this package.
Check that the correct key URLs are configured for this repository
找了很多方法,发现是mysql 的证书过期了,解决方法如下:
执行这个语句: rpm --import https://repo.mysql.com/RPM-GPG-KEY-mysql-2022
或者 yum install mysql-community-server --nogpgcheck 也行
然后就需要启动并查看状态MySQL:
systemctl start mysqld.service
systemctl status mysqld.service
5.7后mysql的密码设置变得复杂了,如果还想设置 123456,root 这种,需要修改一下配置
首先先查询默认初始化的密码:
grep “password” /var/log/mysqld.log,然后 用 mysql -u root -p 登录;
修改密码:
ALTER USER ‘root’@‘localhost’ IDENTIFIED BY ‘my password’;
最后开启远程访问 (把下面的my passrod替换成自己的密码)
grant all privileges on . to ‘root’@’%’ identified by ‘my password’ with grant option;
flush privileges;
exit
注意防火墙,3306端口啥的需要打开!