1.查看是否安装mysql
rpm -qa | grep mysql
这个时候说明没有安装
2.下载安装包
wget https://dev.mysql.com/get/mysql57-community-release-el7-11.noarch.rpm
3.安装软件源
yum -y localinstall mysql57-community-release-el7-11.noarch.rpm
4.安装服务端
yum install -y mysql-community-server
5.启动服务
systemctl start mysqld
6.查看mysql状态
systemctl status mysqld
//成功的话,状态会显示active(running)
7.相关命令
#关闭服务(建议设置开机自启)
systemctl stop mysqld
#开机自启设置
systemctl enable mysqld
#重新启动
systemctl daemon-reload
8.修改密码
查看临时密码
方法1:
cat /var/log/mysqld.log
方法2:
cat /var/log/mysqld.log|grep 'A temporary password'
登录
mysql -u root -h 127.0.0.1 -p
修改密码
set password for 'root'@'localhost'=password('密码要有大小写字母、数字和特殊符号,长度要大于8位');
9.设置远程登录
非本机无法连接
use mysql;
UPDATE user SET host='%' WHERE user='root';
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '你的密码' WITH GRANT OPTION;
FLUSH PRIVILEGES;
云服务器记得配置防火墙端口
我这里是腾讯云