# 1、获取临时密码grep'temporary password' /var/log/mysqld.log
# 2、通过临时密码登录MySQL,进行修改密码操作
mysql -uroot -p
# 3、修改密码
update mysql.user setauthentication_string=password('123456') where user='root';# 4、授权远程访问
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '123456' WITH GRANT OPTION;
flush privileges;exit;
异常
初始密码异常
1)vim /etc/my.cnf
skip-grant-tables # 添加这一行service mysqld restart
mysql -u root
update mysql.user setauthentication_string=password('root') where user='root';
flush privileges;exit2) vim /etc/my.cnf
skip-grant-tables # 删除这一行service mysqld restart
密码太简单异常
# 因为MySQL的密码规则需要很复杂,我们一般自己设置的不会设置成这样,所以我们全局修改一下
mysql>set global validate_password_policy=0;
mysql>set global validate_password_length=1;# 这时候我们就可以自己设置想要的密码了
ALTER USER'root'@'localhost' IDENTIFIED BY '123456';
用户异常
#1、问题:ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=217/USER)
解决:vim /usr/lib/systemd/system/mysqld.service
User=root
Group=root
systemctl daemon-reload # 刷新#2、$MYSQLD_OPTS (code=exited, status=1/FAILURE)
解决:vim /etc/my.cnf
user=root #新增一行#3、The GPG keys listed for the "MySQL 5.7 Community Server" repository are already installed but they are not correct for this package. Check that the correct key URLs are configured for this repository.
解决:vim /etc/yum.repos.d/mysql-community.repo
gpgcheck=0#跳过验证