zhangrui.i
zhangrui.i
发布于 2024-06-21 / 4 阅读
0
0

Linux-centos安装mysql

1. 卸载原有的环境

yum remove mariadb* -y

rm -rf /etc/my.cnf
rm -rf /var/lib/mysql/

yum remove mysql* -y

rm -rf /etc/my.cnf
rm -rf /var/lib/mysql/
rm -rf /var/log/mysqld.log

2. 配置yum仓库

wget https://repo.mysql.com//mysql80-community-release-el7-7.noarch.rpm

sudo rpm -Uvh mysql80-community-release-el7-7.noarch.rpm

# 检查yum仓库状态
yum repolist all |grep enable

3. 安装mysql

# 检查mysql默认安装版本
yum repolist enabled | grep mysql

#更新mysql密钥
rpm --import https://repo.mysql.com/RPM-GPG-KEY-mysql-2023

# 使用yum直接安装mysql
yum install mysql-community-server -y

# 启动mysql服务,并设置开机自启
systemctl enable --now mysqld

# 检查mysql服务状态
systemctl status mysqld

4. 登录mysql

# 获取随机生成的登录密码
grep 'temporary password' /var/log/mysqld.log

mysql -uroot -p

> UPDATE mysql.user SET Host='%' WHERE User='root' AND Host='localhost';

# 修改本地用户’root’@‘localhost’ 的密码
> ALTER USER 'root'@'%' IDENTIFIED BY 'Root.36#336';
> FLUSH PRIVILEGES;

5. 配置文件设置和防火墙

a. 确认 my.cnf 文件中的 bind-address

确保 my.cnf 文件中 bind-address 配置项设置为 0.0.0.0 或者注释掉:

[mysqld] 
bind-address = 0.0.0.0

修改后,重新启动 MySQL 服务:

systemctl restart mysqld

b. 防火墙设置

确保防火墙允许 MySQL 端口(默认是 3306)的连接。

firewall-cmd --zone=public --add-port=3306/tcp --permanent

firewall-cmd --reload

参考:

https://blog.csdn.net/ichen820/article/details/139621748

https://blog.csdn.net/jks212454/article/details/131882628


评论