1、检查Centos版本
cat /etc/redhat-release
2、检查是否安装过MySQL
systemctl status mysqld.service
出现Unit mysqld.service could not be found.
表示没有安装
3、下载MySQL官方的Yum Repository
wget -i -c http://dev.mysql.com/get/mysql57-community-release-el7-10.noarch.rpm
4、安装Yum Repository
yum -y install mysql57-community-release-el7-10.noarch.rpm
5、安装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
6、卸载Yum Repository
由于每次 yum 操作都会自动更新,需要把这个卸载掉
yum -y remove mysql57-community-release-el7-10.noarch
7、查看MySQL状态
systemctl status mysqld.service
8、启动myql
systemctl start mysqld.service
9、查看mysql 临时密码
grep "password" /var/log/mysqld.log
临时密码是:iIn>yP=iE1&q
mysql -uroot –p
Enter password:iIn>yP=iE1&q
登录成功后:密码必须包含大小写字母、数字和特殊字符,不然修改密码失败
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'MySQL%57';
10、开启MySQL远程访问
执行以下命令开启远程访问限制(注意:下面命令开启的是%代表所有用户,如要开启某一个IP,用IP代替%)
mysql> grant all privileges on *.* to 'root'@'%' identified by 'MySQL%57' with grant option;
11、执行刷新命令
mysql> flush privileges;
12、在防火墙中添加3306端口
firewall-cmd --zone=public --add-port=3306/tcp –permanent
刷新防火墙
firewall-cmd --reload
阿里云服务器安全组开启3306端口