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.创建新用户

2.1.方法一 linux命令行创建mysql新用户

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

备注上面@后的命令解释

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

这样的创建命令,默认会看到下面的两个库,看不到任何其它的数据库:

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

2.2.方法2 使用mysql客户端HeidiSql创建

使用root用户登录mysql数据库

2.2.1 点击角色用户头像

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

2.2.2. 添加

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

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


点击保存即可

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>