MySQL添加用户、为用户分配权限

原文地址:https://blog.csdn.net/qq_31759205/article/details/80575540

登录MySQL

登录本地用户

mysql -u root -p

登录外网用户(需要注意服务器可能只允许本地登录,需要修改响应的配置文件)

mysql -u zhrt -h 10.64.6.4 -p

添加用户

1.允许本地访问的用户(127.0.0.1)

create user zhrt@localhost identified by '123456';  

2.允许外网IP访问的用户

create user 'zhrt'@'%' identified by '123456'; 

用户分配权限

授予用户在本地服务器对该数据库的全部权限

grant all privileges on dbname.* to zhrt@localhost identified by '123456';

授予用户通过外网IP对于该数据库的全部权限

grant all privileges on dbname.* to 'zhrt'@'%' identified by '123456';  

刷新权限

flush privileges;  

 

修改用户密码

update mysql.user set authentication_string=password('123456') where user='root';
flush privileges;  

 

posted @ 2020-06-05 19:21  kszsa  阅读(422)  评论(0编辑  收藏  举报