参考了博客: https://blog.csdn.net/weixin_43864927/article/details/103366309
借鉴了别人的经验,自己也有碰到其他状况,记录下来,怕自己忘了..
后面自己写了一个新的安装方法,更好用
centos7安装mysql5.7.37详细步骤二_lanren312的博客-CSDN博客
1、检查服务器是否已经安装MySQL
检查服务器是否已经安装MySQL
yum list installed | grep mysql
//如果检查出来有的话就使用下面这个命令删除
yum -y remove mysql-libs.x86_64
2、下载地址
wget http://repo.mysql.com/mysql57-community-release-el7-8.noarch.rpm
3、解压并安装,一路y
rpm -ivh mysql57-community-release-el7-8.noarch.rpm
yum install mysql-server
4、执行yum install mysql-server报错
warning: /var/cache/yum/x86_64/7/mysql57-community/packages/mysql-community-server-5.7.37-1.el7.x86_64.rpm: Header V4 RSA/SHA256 Signature, key ID 3a79bd29: NOKEY
Retrieving key from file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
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.
Failing package is: mysql-community-server-5.7.37-1.el7.x86_64
GPG Keys are configured as: file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
执行这句就可以了 rpm --import https://repo.mysql.com/RPM-GPG-KEY-mysql-2022
再执行 yum install mysql-server
5、查看mysql版本
mysql -V
6、启动mysql服务
//启动MySQL服务
service mysqld start
//查看MySQL服务状态
service mysqld status
//关闭
service mysqld stop
//重启
service mysqld restart
7、查看并修改初始密码
grep "password" /var/log/mysqld.log
mysql -u root -p
8、修改初始密码
use mysql
ALTER USER USER() IDENTIFIED BY 'xxxxxxx'; ## 最后的分号一定不要忘了
9、开启mysql远程访问权限
update user set host = '%' where user = 'root';
或者
update mysql.user set host = '%' where user = 'root';
10、最重要一步刷新,在不退出mysql输入 flush privileges;
写到最后: 使用docker安装mysql应该会更简单,下次可以试试。
11、升级到8.0.30
我的另一篇博客:
https://blog.csdn.net/lanren312/article/details/126944517
12、防火墙
centos7会默认开启防火墙,要在防火墙中打开对应的端口
firewall-cmd --state ## 查看防火墙状态
firewall-cmd --list-ports ## 查看已经开放的端口
firewall-cmd --zone=public --add-port=3306/tcp --permanent ## 开启3306端口
firewall-cmd --reload ## 重启防火墙 (重新开启端口后一定要重启防火墙,再查看开放的端口)