MySQL常用语句(三):创建用户与权限赋予

admin 2024-05-15 105 阅读 0评论

1、create user 'test_1'@'localhost' identified by '123456';

创建用户

验证:

退出当前登录,使用

mysql -utest_1 -p123456

如果能登录,则证明创建成功

2、select user,host,password from mysql.user;

显示当前实例所有用户的信息

3、delete from mysql.user where user ='test_1';

删除用户

flush privileges;

刷新权限

4、create user 'test_2'@'localhost';

set password for 'test_2'@'localhost'=password('123456');

添加/更改密码

5、update mysql.user set password=password('abcdef') where user='test_2';

更新密码

flush privileges;

6、grant select on china.t2 to 'tws'@'192.168.11.114' identified by '123456';

允许192.168.11.114通过用户名tws、密码123456连接到数据库服务器,可读取数据库china中t2表的数据

flush privileges;

7、grant update(name) on china.t2 to 'tws'@'192.168.11.114';

允许192.168.11.114连接到数据库,并且能修改china库中t2表name字段的值(注:后面未添加identity by是因为在第6条已经为tws用户添加密码)

flush privileges;

8、revoke update(name) on china.t2 from 'tws'@'192.168.11.114';

撤销用户tws更新t2表中name字段的权限。

flush privileges;

9、show grants for 'tws'@'192.168.11.114';

查看该用户的权限

发表评论

快捷回复: 表情:
Addoil Applause Badlaugh Bomb Coffee Fabulous Facepalm Feces Frown Heyha Insidious KeepFighting NoProb PigHead Shocked Sinistersmile Slap Social Sweat Tolaugh Watermelon Witty Wow Yeah Yellowdog
提交
评论列表 (有 0 条评论, 105人围观)