Centos7 MySQL8安全模式修改超级管理员密码
1.1、修改配置文件免密码登录mysql
vim /etc/my.cnf
1.2、在 [mysqld]最后加上如下语句 并保持退出文件;
skip-grant-tables
1.3 、重启mysql服务:
systemctl restart mysqld.service
1.4、免密码登录到mysql上;直接在命令行上输入:
mysql
//或者
mysql -u root -p
//password直接回车
1.5、查看数据库,选择mysql 数据库:
#查看数据库
show databases
#选择mysql 数据库
use mysql
1.6、查看当前系统用户相关信息,在mysql数据库的user表中;
select host, user, authentication_string, plugin from user;
host: 允许用户登录的ip‘位置’%表示可以远程;
user:当前数据库的用户名;
authentication_string: 用户密码;在mysql 5.7.9以后废弃了password字段和password()函数;
plugin: 密码加密方式;
1.7、如果当前root用户authentication_string字段下有内容,先将其设置为空;
use mysql;
update user set authentication_string='' where user='root';
1.8、 退出mysql, 删除/etc/my.cnf文件最后的 skip-grant-tables 重庆mysql服务;
#重启mysql 服务
systemctl restart mysqld.service
1.9、使用root用户进行登录,因为上面设置了authentication_string为空,所以可以免密码登录;
mysql -u root -p
passwrod:直接回车;
2.0、使用ALTER修改root用户密码;
ALTER user 'root'@'localhost' IDENTIFIED BY 'Qian123#'
至此修改成功; 从新使用用户名密码登录即可;
1.本站遵循行业规范,任何转载的稿件都会明确标注作者和来源;2.本站的原创文章,请转载时务必注明文章作者和来源,不尊重原创的行为我们将追究责任;3.作者投稿可能会经我们编辑修改或补充。