mysql root password

"""
centos:
mysql忘记root密码解决

1.修改MySQL的登录设置:
# vim /etc/my.cnf
在[mysqld]的段中加上一句:skip-grant-tables
例如:
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
skip-grant-tables

2.重启mysql
systemctl restart mysqld.service

3.登录mysql
mysql

4.修改root用户密码:
先将密码设置为空
update user set authentication_string='' where user='root'
再修改密码
ALTER user 'root'@'localhost' IDENTIFIED BY 'Cliu123#'
如果遇到The MySQL server is running with the --skip-grant-tables option
so it cannot execute this statement 则刷新权限即可(FLUSH PRIVILEGES)
注意: 一定不要采取如下形式该密码:
use mysql;
update user set authentication_string="newpassword" where user="root";
这样会给user表中root用户的authentication_string字段下设置了newpassword值;

当再使用ALTER USER 'root'@'localhost' IDENTIFITED BY 'newpassword'时会报错的;

因为authentication_string字段下只能是mysql加密后的41位字符串密码;其他的会报格式错误;
5.编辑my.cnf文件删掉skip-grant-tables 这一行

6.重启mysql

为用户授权并用于远程连接
GRANT ALL PRIVILEGES ON *.* TO 'tny'@'localhost' IDENTIFIED BY 'Test123456!' WITH GRANT OPTION;
GRANT ALL PRIVILEGES ON *.* TO 'tny'@'10.18.192.52' IDENTIFIED BY 'Test123456!' WITH GRANT OPTION;
mysql8.0给用户授权时需要先创建用户:
create user 'zac'@'%' identified by 'Za888888!';
GRANT EXECUTE,INSERT,SELECT,UPDATE ON *.* TO 'tny'@'%';
grant on tpservice22.* to 'tny'@'%' ;
客户端使用密码验证,进行登录
ALTER USER 'tny'@'%' IDENTIFIED WITH mysql_native_password BY 'Za888888!';
FLUSH PRIVILEGES;
将用户加入组
usermod -a -G mysql root

grant all privileges on *.* to 'root'@'10.18.192.52' identified by "Test123456!" ;
"""

上一篇:微信小程序--缓存,支持过期时间的二次开发封装


下一篇:内核开发知识第一讲.内核中的数据类型.重要数据结构.常用内核API函数.