$ mysql -u root -p
mysql> use mysql;
mysql> select Host,User from mysql.user;
# 创建用户并设置密码
mysql> create user "wordpress" identified by "password";
# MySQL 8使用如下命令
# mysql> create user "wordpress" identified with mysql_native_password by "password";
#更改用户访问是外网访问还是只能本地访问
mysql> update mysql.user set Host="localhost" where User="wordpress";
# 更新密码,5.7的数据库使用'authentication_string'字段替代了'Password'字段
mysql> update user set authentication_string=password("pass") where User="wordpress" and Host="localhost";
# MySQL 8 不能使用上面的命令修改密码,只能在创建的时候设置密码,可以先删除再创建
# drop user "wordpress";
# 如果没这一行可能也会报一个错误,因此需要运行这一行
mysql> update user set plugin="mysql_native_password";
mysql> select Host,User from mysql.user;
# 授予用户访问Wordpress数据库的权限
mysql> grant all privileges on wordpress.* to "wordpress"@"localhost" identified by "pass";
# MySQL 8使用如下命令
# mysql> grant all privileges on wordpress.* to "wordpress";
# 刷新权限
mysql> flush privileges;
参考链接