方法一(命令): 語法:mysql
CREATE USER '用戶名'@'主機ip地址' IDENTIFIED BY '密碼';
複製代碼
實例: 添加dog用戶, 密碼123456sql
CREATE USER 'dog'@'localhost' IDENTIFIED BY '123456';
複製代碼
方法二(改表, 須要刷新權限): 語法:數據庫
insert into mysql.user(host,user,password) values("主機ip地址","用戶名",password("密碼"));
flush privileges;
複製代碼
實例: 添加cat用戶, 密碼123456ide
insert into mysql.user(host,user,password) values("localhost","cat",password("123456"));
flush privileges;
複製代碼
SELECT HOST, USER, PASSWORD FROM mysql.USER;
複製代碼
方式一(改表, 須要刷新權限):post
Delete FROM mysql.user Where User='用戶名' and Host='主機ip地址';
flush privileges;
複製代碼
刪除用戶cat測試
Delete FROM mysql.user Where User='cat' and Host='localhost';
flush privileges;
複製代碼
方式二(命令):spa
DROP USER '用戶名'@'主機ip地址';
複製代碼
刪除用戶dogcode
DROP USER 'dog'@'localhost';
複製代碼
建立一個用戶叫Trident(海皇戟)cdn
insert into mysql.user(host,user,password) values("localhost","Trident",password("123456"));
flush privileges;
複製代碼
方式一(改表, 須要刷新權限):blog
update mysql.user set user = '新名字' where user = '原來的名字';
flush privileges;
複製代碼
更名Aegis(宙斯盾)
update mysql.user set user = 'Aegis' where user = 'Trident';
flush privileges;
複製代碼
方式二(命令):
rename user '原來的用戶名'@'主機ip地址' to '新名字'@'主機ip地址';
複製代碼
再改回Trident(海皇戟)
rename user 'Aegis'@'localhost' to 'Trident'@'localhost';
複製代碼
方式一(命令):
set password for '用戶名'@'主機ip地址' = password('新密碼');
複製代碼
把''海皇戟''用戶的密碼改爲"root"
set password for 'Trident'@'localhost' = password('root');
複製代碼
方式二(改表, 須要刷新權限):
UPDATE `mysql`.`user` SET `Password` = password('新密碼') where user = '用戶名' and host = 'localhost';
FLUSH PRIVILEGES;
複製代碼
把'海皇戟'用戶的密碼再次改爲"123456"
UPDATE `mysql`.`user` SET `Password` = password('123456') where user = 'Trident' and host = 'localhost';
FLUSH PRIVILEGES;
複製代碼