mysql -u root -p mysql>use mysql; mysql>update user set host = '%' where user = 'root'; mysql>select host, user from user; FLUSH PRIVILEGES;
授权法
1 2 3 4 5 6 7 8
#所有权限 mysql>GRANT ALL PRIVILEGES ON *.* TO 'root'@'%'WITH GRANT OPTION #指定用户指定密码 mysql>GRANT ALL PRIVILEGES ON *.* TO 'myuser'@'%'IDENTIFIED BY 'mypassword' WI TH GRANT OPTION; #指定ip指定用户 mysql>GRANT ALL PRIVILEGES ON *.* TO 'myuser'@'192.168.1.3'IDENTIFIED BY 'mypassword' WITH GRANT OPTION;
#修改加密规则 ALTER USER 'root'@'localhost' IDENTIFIED BY 'password' PASSWORD EXPIRE NEVER; ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'password'; #重新设置密码 ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY '新的密码';
#重新初始化登录帐户 vim /etc/my.cnf.d --增加 skip-grant-tables --退出后重启 systemctl stop mysqld systemctl start mysqld --开始重置密码 mysql -uroot -p --输入任意密码 --必须先执行 flush privileges,否则会报The MySQL server is running with the --skip-grant-tables option so it cannot execute this statement flush privileges; ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'tw369.com'; UPDATE USER SET host ="%" where user = "root"; flush privileges; exit #启动服务 删除配置文件的 skip-grant-tables