首先需要安装并配置完成MySQL数据库,MySQL具备轻量级的优势,简单安装。
首先,登录数据库。
先登录数据库
hushouyue@BigMay ~ % mysqlsh --sql -h localhost -uroot -p
MySQL Shell 8.0.23 Copyright (c) 2016, 2021, Oracle and/or its affiliates. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type '\help' or '\?' for help; '\quit' to exit. Creating a session to 'root@localhost' Fetching schema names for autocompletion... Press ^C to stop. Your MySQL connection id is 71 (X protocol) Server version: 8.0.23 MySQL Community Server - GPL No default schema selected; type \use <schema> to set one.
MySQL localhost:33060+ ssl SQL >
or
~% mysql -uroot -p
创建新的用户
MySQL localhost:33060+ ssl SQL > CREATE user demo IDENTIFIED by 'password'; #创建用户设置密码
Query OK, 0 rows affected (0.1277 sec)
MySQL localhost:33060+ ssl SQL > CREATE user 'demo'@'%'; #创建用户不设置密码
查看用户的权限
MySQL localhost:33060+ ssl SQL > SHOW GRANTS for demo; #查看demo用户的权限
+----------------------------------+
| Grants for demo@% |
+----------------------------------+
| GRANT USAGE ON *.* TO `demo`@`%` |
+----------------------------------+
1 row in set (0.0030 sec)
给用户demo授予 select和update的权限
MySQL localhost:33060+ ssl SQL > GRANT SELECT,update on *.* to 'demo'@'%' with grant option; #给用户demo设置select、update的权限
Query OK, 0 rows affected (0.0180 sec)
全局的权限
grant all privileges on *.* to 'demo'@'%' with grant option; #给用户demo授全局的权限
更改用户名的密码
MySQL localhost:33060+ ssl SQL > ALTER user 'demo'@'%' IDENTIFIED by 'qqqqqq'; #更改用户demo的密码
Query OK, 0 rows affected (0.0096 sec)
MySQL localhost:33060+ ssl SQL > FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.0209 sec)
更改用户名
MySQL localhost:33060+ ssl SQL > RENAME user 'demo'@'%' to 'demo0'@'%';
Query OK, 0 rows affected (0.0042 sec)
MySQL localhost:33060+ ssl SQL > SELECT user,host from mysql.user;
+------------------+-----------+
| user | host |
+------------------+-----------+
| demo0 | % |
| root | % |
| mysql.infoschema | localhost |
| mysql.session | localhost |
| mysql.sys | localhost |
+------------------+-----------+
删除用户
MySQL localhost:33060+ ssl SQL > DROP user 'demo0'@'%';
Query OK, 0 rows affected (0.0055 sec)
网友评论