本文借鑒https://blog.csdn.net/shenhonglei1234/article/details/84786443
因為mysql升級到>8.0.13后, 授權指令要分開執行:
#創建賬戶(此例為root)
create user 'root'@'%' identified by 'password';
#賦予權限,with grant option這個選項表示該用戶可以將自己擁有的權限授權給別人
grant all privileges on *.* to 'root'@'%' with grant option;
#改密碼&授權超用戶,flush privileges 命令本質上的作用是將當前user和privilige表中的用戶信息/權限設置從mysql庫(MySQL數據庫的內置庫)中提取到內存里
flush privileges;
還想在這一步驟中獲取更多信息的話可以這樣做:
查看某個用戶的權限:
show grants for username@host; #用戶名@主機
查看所有用戶:
select host,user from mysql.user;
Mysql用戶創建:
使用create user命令創建:
create user '用戶名'@'主機' identified by '密碼';