mysql5.6.24 版本上创建实例并授权操作

以下操作命令和方法均是在 mysql5.6.24 版本上,其他版本略有差异。

一、登录mysql

[root@db-1-198 ~]# mysql -h127.0.0.1 -uroot -p'DbMingX28' -P3306 -S /tmp/mysql3306.sock
Warning: Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or g.
Your MySQL connection id is 26611867
Server version: 5.6.24-log MySQL Community Server (GPL)

Copyright (c) 2000, 2015, 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>

二、查看现有的数据库实例

mysql> show databases;
+------------------------+
| Database         |
+------------------------+
| information_schema |
| mysql |
| performance_schema |
| test |
+------------------------+
4 rows in set (0.01 sec)

三、创建数据库实例

mysql> show databases;
+------------------------+
| Database |
+------------------------+
| information_schema |
| mysql |
| performance_schema |
| test |
+------------------------+
4 rows in set (0.01 sec)

四、创建用户并授权该实例的所有权限给新创建的用户

mysql> grant all on wangming.* to 'wmuser'@'192.168.1.%' identified by 'Pz4p6uA13K';
Query OK, 0 rows affected (0.00 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.03 sec)

mysql> show grants for 'wmuser'@'192.168.1.%';
+-----------------------------------------------------------------------------------------------------------------------+
| Grants for wmuser@192.168.1.% |
+-----------------------------------------------------------------------------------------------------------------------+
| GRANT USAGE ON *.* TO 'wmuser'@'192.168.1.%' IDENTIFIED BY PASSWORD '*4C1597C9C4060CCA85B46F5851DFEEEAF2BE459F' |
| GRANT ALL PRIVILEGES ON `wmuser`.* TO 'wmuser'@'192.168.1.%' |
+-----------------------------------------------------------------------------------------------------------------------+
2 rows in set (0.00 sec)

五、使用新创建的用户测试登录

[root@db-1-198 ~]# mysql -h192.168.1.198 -uwmuser -p'Pz4p6uA13K' -P3306 -S /tmp/mysql3306.sock
Warning: Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or g.
Your MySQL connection id is 26612703
Server version: 5.6.24-log MySQL Community Server (GPL)

Copyright (c) 2000, 2015, 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> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| pre_assessrv_wl |
| test |
+--------------------+
3 rows in set (0.00 sec)

mysql>

完工

原文地址:https://www.cnblogs.com/xzlive/p/15152620.html