1. 使用root進(jìn)入mysql
mysql -uroot -p123456
2 查看用戶表
select host, user, plugin from mysql.user;
// 返回如下 % 是主機(jī)地址赞别,可遠(yuǎn)程 caching_sha2_password 是加密規(guī)則
+-----------+------------------+-----------------------+
| host | user | plugin |
+-----------+------------------+-----------------------+
| % | root | caching_sha2_password |
| % | z2 | mysql_native_password |
| % | zhangsan | caching_sha2_password |
| localhost | mysql.infoschema | caching_sha2_password |
| localhost | mysql.session | caching_sha2_password |
| localhost | mysql.sys | caching_sha2_password |
| localhost | root | caching_sha2_password |
+-----------+------------------+-----------------------+
show databases; // 查看數(shù)據(jù)庫(kù), 除test-v2 數(shù)據(jù)庫(kù),其余四個(gè)為 mysql 默認(rèn)數(shù)據(jù)庫(kù)礼患,其中mysql.user表可以操作用戶信息
+--------------------+
| Database |
+--------------------+
| test-v2 |
| information_schema |
| mysql |
| performance_schema |
| sys |
+--------------------+
3. 創(chuàng)建新用戶 and 修改用戶密碼\刪除用戶
// 創(chuàng)建用戶 zhangsan 密碼為123456
// 注意修改用戶密碼早像、主機(jī)也可以用此條命令
CREATE USER IF NOT EXISTS 'zangsan'@'%' IDENTIFIED WITH mysql_native_password BY '123456';
// mysql 返回此行 表示命令成功
Query OK, 0 rows affected (0.17 sec)
// 修改用戶密碼
alter user 'zhangsan'@'%' identified with caching_sha2_password by '110112';
// 刪除用戶沒(méi)有引號(hào)
drop user zhangsan;
4. 增加用戶權(quán)限
// 給用戶 zhangsan 權(quán)限
grant SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, RELOAD, INDEX,
ALTER,CREATE VIEW, SHOW VIEW, EVENT, TRIGGER, CREATE TABLESPACE
ON *.* TO 'zhangsan'@'%';
-- 查看權(quán)限
show grants for zhangsan;
-- 收回用戶zhangsan的所有權(quán)限
revoke all privileges on *.* from zhangsan;
var code = "2990acd3-900c-458b-8ca6-792d3359c0ca"