mysql password_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!" ;

"""

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值