一、安装
#获取安装用的Yum Repository
wget -i -c http://dev.mysql.com/get/mysql57-community-release-el7-10.noarch.rpm
yum -y install mysql57-community-release-el7-10.noarch.rpm
#安装MySQL服务
yum -y install mysql-community-server
#查看版本
mysql -v
#启动mysql
systemctl start mysqld.service
#找回初始密码并登录
grep 'temporary password' /var/log/mysqld.log
mysql -uroot -p
#注意;找不到初始密码及其他情况参考下文"修改密码"
#使用初始密码登录后需要先修改一次密码后才能操作
ALTER USER 'root'@'localhost' IDENTIFIED BY '新密码';
#为避免Repository每次yum操作都会自动更新
yum -y remove mysql57-community-release-el7-10.noarch
二、修改密码
#1.找回密码
grep 'temporary password' /var/log/mysqld.log
#2.强制修改密码
systemctl stop mysqld #停止服务
systemctl set-environment MYSQLD_OPTS="--skip-grant-tables" #跳过密码
systemctl start mysqld #启动服务
mysql -u root #登录
UPDATE mysql.user SET authentication_string = PASSWORD('新密码') WHERE User = 'root' AND Host = 'localhost'; #设置新密码
FLUSH PRIVILEGES; #刷新权限
quit #退出
#3.用操作系统账号修改密码
mysql -uroot -p #使用centos账号密码登录
UPDATE mysql.user SET authentication_string = PASSWORD('新密码') WHERE User = 'root' AND Host = 'localhost'; #设置新密码
FLUSH PRIVILEGES; #刷新权限
quit #退出
三、修改远程连接权限(为了使用navicat)
#选择mysql
use mysql;
#授权远程连接
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'YYBrhr_2018' WITH GRANT OPTION;
#注意:如果navicat远程连接报1521错误
GRANT ALL ON *.* TO 'root'@'%'; #远程连接授权
ALTER USER 'root'@'%' IDENTIFIED BY 'password' PASSWORD EXPIRE NEVER; #更改加密规则
ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY '123456'; #更改密码
FLUSH PRIVILEGES; #刷新权限