ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、阅读、搜索等,送10W Token,即刻开启你的AI之旅 广告
1. 登录系统 ~~~ [root@izbp192gcqz9hrnj21lewuz ~]# mysql -uroot -**** -h47.96.121.127 -P 3306 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 15 Server version: 5.6.36 Source distribution Copyright (c) 2000, 2017, 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. 查看当前用户 ~~~ mysql> select user(); +--------------------+ | user() | +--------------------+ | root@47.96.121.127 | +--------------------+ 1 row in set (0.00 sec) ~~~ 3. 查看当前用户授权 ~~~ mysql> show grants for 'root'@'%'; +------------------------------------------------------------------+ | Grants for root@% | +------------------------------------------------------------------+ | GRANT USAGE ON *.* TO 'root'@'%' IDENTIFIED BY PASSWORD <secret> | | GRANT ALL PRIVILEGES ON `champion`.* TO 'root'@'%' | +------------------------------------------------------------------+ 2 rows in set (0.00 sec) ~~~ 4. 远程用户没有创建用户的权限 ~~~ mysql> CREATE USER 'log'@'*' IDENTIFIED BY 'log2018'; ERROR 1227 (42000): Access denied; you need (at least one of) the CREATE USER privilege(s) for this operation ~~~ ~~~ mysql> select user(); +--------------------+ | user() | +--------------------+ | root@47.96.121.127 | +--------------------+ 1 row in set (0.00 sec) ~~~ 5. 本机用户有创建用户的授权权限 ~~~ mysql> show grants for 'root'@'localhost'; +-----------------------------------------------------------------------------------------------------+ | Grants for root@localhost | +-----------------------------------------------------------------------------------------------------+ | GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' IDENTIFIED BY PASSWORD <secret> WITH GRANT OPTION | | GRANT PROXY ON ''@'' TO 'root'@'localhost' WITH GRANT OPTION | +-----------------------------------------------------------------------------------------------------+ 2 rows in set (0.00 sec) ~~~ 6. exit登出系统 ~~~ mysql> exit Bye ~~~ 7. 本地用户登陆 ~~~ [root@izbp192gcqz9hrnj21lewuz ~]# mysql -uroot -**** -hlocalhost -P 3306 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 16 Server version: 5.6.36 Source distribution Copyright (c) 2000, 2017, 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> select user(); +----------------+ | user() | +----------------+ | root@localhost | +----------------+ 1 row in set (0.00 sec) ~~~ 8. 创建新用户 ~~~ mysql> CREATE USER 'log'@'*' IDENTIFIED BY 'log2018'; Query OK, 0 rows affected (0.00 sec) ~~~ 9. 授权用户 ~~~ mysql> GRANT ALL PRIVILEGES ON champion.* TO log@"%" IDENTIFIED BY "log2018"; Query OK, 0 rows affected (0.00 sec) mysql> flush privileges; Query OK, 0 rows affected (0.00 sec) ~~~