News:三分天注定,七分靠打拼,爱拼才会赢!致力打造专业IT博客。如果你对本博客有任何意见或建议请联系作者,邮箱:blog@mymail.com.cn

MySQL 创建用户

逝水无痕 82 0 条

本篇文章主要是简单介绍如何使用 mysql 命令行创建和删除用户、对用户授权和撤销用户授权。

mysql.jpg

登录 mysql 服务器

/usr/local/mysql/bin/mysql -uroot -p 

查看现有的用户有哪些

select host,user from mysql.user;

创建用户

以 test 用户为例,并指定密码为 123456

create user test identified by '123456';

为用户授权

例一:为 test 用户授予 testdb 数据库的权限

grant all privileges on testdb.* to test@'%' identified by '123456';

grant all privileges on testdb.* to test@localhost identified by '123456';

例二:为 test 用户授予所有数据库的指定权限

grant select, insert, update, delete, create, drop, index, alter, show databases, create view, show view, event, trigger on *.* to test@'%' identified by '123456';

grant select, insert, update, delete, create, drop, index, alter, show databases, create view, show view, event, trigger on *.* to test@localhost identified by '123456';

查看用户的授权情况

show grants for test@'%';

show grants for test@localhost;

使配置生效

flush privileges;

如果想撤销授权

撤销授权的命令与授权命令十分相似,将命令中的 to 改为 from 即可

revoke all on testdb.* from test@'%';

revoke all on testdb.* from test@localhost;

如果想删除用户

drop user test@'%';

drop user test@localhost;
发表我的评论
icon_mrgreen.gificon_neutral.gificon_twisted.gificon_arrow.gificon_eek.gificon_smile.gificon_confused.gificon_cool.gificon_evil.gificon_biggrin.gificon_idea.gificon_redface.gificon_razz.gificon_rolleyes.gificon_wink.gificon_cry.gificon_surprised.gificon_lol.gificon_mad.gificon_sad.gificon_exclaim.gificon_question.gif

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址