阿里云centos8安装mysql5.7
2021-06-18 17:59:13
一、检查系统环境
1、检查Centos版本
[root@iZwz91ua0udzucg7foj0ffZ ~]# cat /etc/redhat-release CentOS Linux release 8.3.2011
2、检查是否安装过MySQL
[root@iZ8vb5ha9qczjmh83yzk6zZ ~]# systemctl status mysqld.service Unit mysqld.service could not be found.
[root@iZ8vb5ha9qczjmh83yzk6zZ ~]# find / -name my.cnf [root@iZ8vb5ha9qczjmh83yzk6zZ ~]#
二、下载并安装MySQL
1、下载MySQL官方的Yum Repository
[root@iZ8vb5ha9qczjmh83yzk6zZ ~]# wget -i -c http://dev.mysql.com/get/mysql57-community-release-el7-10.noarch.rpm
2、安装Yum Repository
[root@iZ8vb5ha9qczjmh83yzk6zZ ~]# yum -y install mysql57-community-release-el7-10.noarch.rpm
3、安装MySQL
[root@iZwz91ua0udzucg7foj0ffZ mysql]# yum -y install mysql-community-server
安装时报错,All matches were filtered out by modular filtering for argument: mysql-community-server
Error: Unable to find a match: mysql-community-server
解决办法:先执行 yum module disable mysql,然后再执行yum -y install mysql-community-server
https://blog.csdn.net/Dreamlike_/article/details/108449205
报错:
Public key for mysql-community-common-5.7.42-1.el7.x86_64.rpm is not installed Failing package is: mysql-community-common-5.7.42-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
4、卸载Yum Repository
[root@iZ8vb5ha9qczjmh83yzk6zZ ~]# yum -y remove mysql57-community-release-el7-10.noarch
三、配置MySQL
1、查看MySQL状态
[root@iZ8vb5ha9qczjmh83yzk6zZ ~]# systemctl status mysqld.service
2、启动MySQL
[root@iZ8vb5ha9qczjmh83yzk6zZ ~]# systemctl start mysqld.service
3、登录MySQL
[root@iZ8vb5ha9qczjmh83yzk6zZ ~]# grep "password" /var/log/mysqld.log
临时密码是iIn>yP=iE1&q
[root@iZ8vb5ha9qczjmh83yzk6zZ ~]# mysql -uroot –p
Enter password:iIn>yP=iE1&q
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'MySQL%57';
四、开启MySQL远程访问
执行以下命令开启远程访问限制(注意:下面命令开启的是%代表所有用户,如要开启某一个IP,用IP代替%)
mysql> grant all privileges on *.* to 'root'@'%' identified by '1qazXSW@15626141631' with grant option;
mysql> flush privileges;
五、在防火墙中添加3306端口
[root@iZ8vb5ha9qczjmh83yzk6zZ ~]# firewall-cmd --zone=public --add-port=3306/tcp –permanent firewall-cmd --permanent --add-port=6859/tcp firewall-cmd --reload
六、修改配置文件
[root@iZ8vb5ha9qczjmh83yzk6zZ ~]# find / -name my.cnf
进入文件后,新增以下代码
[client] default-character-set = utf8mb4 [mysql] default-character-set = utf8mb4 [mysqld] character-set-client-handshake = FALSE character-set-server = utf8mb4 collation-server = utf8mb4_unicode_ci
[root@iZ8vb5ha9qczjmh83yzk6zZ ~]# systemctl restart mysqld.service
常用命令