1. 程式人生 > 其它 >mysql5.6.24 版本上建立例項並授權操作

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 [email protected].% |
+-----------------------------------------------------------------------------------------------------------------------+
| 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>

完工