在MySQL 5.7.6+中,以前的創建新用戶,設置密碼的語句已經被deprecated
了,所以現在已經不推薦使用:
GRANT ALL PRIVILEGES ON mydb.* TO 'username'@'localhost' IDENTIFIED BY 'myPassword';
MySQL官方文檔中提到
However, use of GRANT to create accounts or define nonprivilege
characteristics is deprecated as of MySQL 5.7.6. Instead, perform
these tasks using CREATE USER or ALTER USER.
所以,目前推薦使用CREATE USER
來創建用戶,ALTER USER
來修改密碼:
CREATE USER username IDENTIFIED BY 'myPassword';
MySQL會使用默認的插件來對myPassword
加密。
若要修改用戶密碼,推薦的方式是使用ALTER USER
而非舊的SET PASSWORD
語法:
ALTER USER username IDENTIFIED BY 'myNewPassword';
以上兩個語法可以參考:
https://dev.mysql.com/doc/refman/5.7/en/create-user.html
https://dev.mysql.com/doc/refman/5.7/en/set-password.html