命令行下创建MySQL数据库与创建用户以及授权

先以root用户登录mysql:

C:\Users\XXX>mysql -u root -p

输入密码后登录,接下来操作如下:

1、创建数据库

语法:create schema [数据库名称] default character set utf8 collate utf8_general_ci;

  采用create schema和create database创建数据库的效果一样。

示例:create schema spring_boot_demo default character set utf8 collate utf8_general_ci;

2、创建用户

语法:create user '[用户名称]'@'%' identified by '[用户密码]';

  密码8位以上,包括:大写字母、小写字母、数字、特殊字符

  %:匹配所有主机,该地方还可以设置成‘localhost’,代表只能本地访问,例如root账户默认为‘localhost‘

示例:create user 'szh'@'localhost' identified by '123456';

3、用户授权数据库

grant select,insert,update,delete,create on [数据库名称].* to [用户名称]@'%';

  *代表整个数据库

示例:grant select,create on spring_boot_demo.* to szh@'localhost';

4、立即启用修改

flush  privileges ;

 

5、取消用户szh所有数据库(表)的所有权限

revoke all on *.* from szh;

6、删除用户szh

delete from mysql.user where user='szh';

7、删除数据库

drop database [schema名称|数据库名称];

 

PS : 在操作过程中如果遇到错误

"The MySQL server is running with the --skip-grant-tables option so it cannot execute this statement"

则先进行一下刷新操作:

mysql> flush privileges; --这样就可以接着操作了


---------------------
作者:忧国一小民
来源:CSDN
原文:https://blog.csdn.net/sunzhenhua0608/article/details/80382960
版权声明:本文为博主原创文章,转载请附上博文链接!

相关文章

文章浏览阅读2.2k次,点赞6次,收藏20次。在我们平时办公工作...
文章浏览阅读1k次。解决 Windows make command not found 和...
文章浏览阅读3.2k次,点赞2次,收藏6次。2、鼠标依次点击“计...
文章浏览阅读1.3w次。蓝光版属于高清版的一种。BD英文全名是...
文章浏览阅读974次,点赞7次,收藏8次。提供了更强大的功能,...
文章浏览阅读1.4w次,点赞5次,收藏22次。如果使用iterator的...