MySQL 新建用户,为用户授权,指定用户访问数据库
时间:2019-12-08 00:49:16
收藏:0
阅读:372
1.登录MySQL
mysql -u root -p
2.添加新用户(允许所有ip访问)
create user ‘test‘@‘*‘ identified by ‘123456‘;
#test:用户名,*:所有ip地址,123456:密码
3.创建数据库
CREATE DATABASE test_db DEFAULT CHARSET utf8mb4 COLLATE utf8mb4_general_ci;
4.为新用户分配权限
grant all privileges on `test_db`.* to ‘test‘@‘%‘ identified by ‘123456‘;
#授权给用户test,数据库test_db相关的所有权限,并且该用户test在所有网络IP上都有权限,%是指没有网络限制
5.刷新权限
flush privileges;
6. 修改用户的IP访问权限
use mysql;
update user set host = ‘%‘ where user =‘test‘;
原文:https://www.cnblogs.com/faberbeta/p/mysql002.html
评论(0)