mysql 忘记密码、授权什么的

mysql忘记Root密码了,怎么办

1. 修改配置

修改配置文件my.cnf,在配置文件*[mysqld]*下添加skip-grant-tables

sudo nano /etc/mysql/mysql.conf.d/mysqld.cnf

2. 重启服务

sudo service mysql restart

3.空密码连接

mysql -u root

执行

use mysql;
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '123456';  --'

update user set authentication_string = NULL where user = 'root';

4. 恢复mysqld.cnf,重启mysql服务

登录

mysql -u root -p

如果不成功,多试几次。

对用户授权

GRANT ALL PRIVILEGES ON *.* TO 'myuser'@'%' IDENTIFIED BY 'mypassword' WITH GRANT OPTION;  
FLUSH PRIVILEGES; 

你可能感兴趣的:(Linux相关,mysql)