暂无图片
暂无图片
暂无图片
暂无图片
暂无图片

MySQL之修改root密码

原创 何权林 2020-04-16
914

环境:CentOS7.6 MySQL5.7.26(RPM安装)

没有忘记root密码:
方法一:update方式修改表mysql.user(不建议使用)
mysql> update mysql.user set authentication_string=password(‘Aa&123456’) where Host=‘localhost’ and User=‘root’;

mysql> flush privileges;
或重启MySQL服务

[root@localhost ~]# mysql -uroot -p’Aa&123456’
注:不建议通过直接修改表的方式修改密码。

方式二:set方式直接修改密码
mysql> set password=password(‘Aa#123456’);
或者
mysql> set password for root@localhost=password(‘Aa#123456’);

[root@localhost ~]# mysql -uroot -p’Aa#123456’

方式三:mysqladmin工具修改(不建议使用)
[root@localhost ~]# mysqladmin -uroot -p’Aa#123456’ password ‘Aa$123456’
mysqladmin: [Warning] Using a password on the command line interface can be insecure.
Warning: Since password will be sent to server in plain text, use ssl connection to ensure password safety.

[root@localhost ~]# mysql -uroot -p’Aa$123456’
注:不建议使用,因为命令行暴漏了密码。

忘记root密码:
方式一:修改配置文件/etc/my.cnf
1、修改vim /etc/my.cnf
在[mysqld]下添加如下:
skip-grant-tables

2、重启mysql服务
systemctl restart mysqld

3、登陆mysql,修改密码
mysql -uroot

mysql> update mysql.user set authentication_string=password(‘Aa!123456’) where Host=‘localhost’ and user=‘root’;
注:好像只有这种方式能修改密码

4、退出mysql,修改my.cnf,删除skip-grant-tables,重启服务后登陆。
vim my.cnf

systemctl restart mysqld

[root@localhost ~]# mysql -uroot -p’Aa!123456’

「喜欢这篇文章,您的关注和赞赏是给作者最好的鼓励」
关注作者
【版权声明】本文为墨天轮用户原创内容,转载时必须标注文章的来源(墨天轮),文章链接,文章作者等基本信息,否则作者和墨天轮有权追究责任。如果您发现墨天轮中有涉嫌抄袭或者侵权的内容,欢迎发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。

评论