在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