当前位置: 移动技术网 > 科技>操作系统>windows > 命令行下创建MySQL数据库与创建用户以及授权

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

2019年06月19日  | 移动技术网科技  | 我要评论

战场原蔡明,网游之龙傲天下,飞狐外传下载

先以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,insert,update,delete,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
版权声明:本文为博主原创文章,转载请附上博文链接!

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网