mysql 用户权限之创建新用户并给授权指定的数据库权限

1.使用mysql命令登录root用户

[root@izwz91h49n3mj8r232gqwez ~]# mysql -u root -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 36
Server version: 5.6.42-log MySQL Community Server (GPL)

Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> 

2.创建新用户

CREATE USER 'mindoc_db_read'@'%' IDENTIFIED BY 'mindoc_db_read@123'; 

备注上面@后的命令解释

'%' - 所有情况都能访问
‘localhost’ - 本机才能访问
’111.222.33.44- 指定 ip 才能访问

这样的创建命令,默认会看到下面的两个库,看不到任何其它的数据库:
在这里插入图片描述

3.给用户授予权限

grant all on 数据库名.数据库表 to 用户名@'%'  identified by "密码";

备注

all 可以替换为 select,delete,update,create,drop
数据库名 所有的 用*
数据库表 所有的 用*

example1
给mindoc_db_read用户对mindoc_db所有表的查询权限

mysql> grant select on mindoc_db.* to mindoc_db_read@'%'  identified by "mindoc_db_read@123";
Query OK, 0 rows affected (0.01 sec)

mysql> 

猜你喜欢

转载自blog.csdn.net/u014636209/article/details/84824592