【MySQL】更改用户授权访问

数据库连接
mysql -uroot -p

查询当前用户host设置
select user,host from mysql.user;

创建新用户,密码及host
CREATE USER 'root'@'192.168.1.1' IDENTIFIED WITH mysql_native_password BY '你的密码';

给用户付权限
GRANT ALL PRIVILEGES ON *.* TO 'root'@'192.168.1.1' WITH GRANT OPTION; 

将之前的host改为localhost
update mysql.user set host = 'localhost' where user = 'root' and host = '%'; 

检查设置
select user,host from mysql.user; 

刷新权限 
FLUSH PRIVILEGES;

 

 
posted @ 2024-11-15 15:48    阅读(8)  评论(0编辑  收藏  举报