参考:
https://blog.csdn.net/qq_15585305/article/details/129889474
# 先确保自己有授权权限
mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' WITH GRANT OPTION;
Query OK, 0 rows affected (0.00 sec)
# 更新一下权限
mysql> flush privileges;
Query OK, 0 rows affected (0.01 sec)
# 查询自己是否有权限
mysql> SELECT host,user,Grant_priv,Super_priv FROM mysql.user;
+---------------+------------------+------------+------------+
| host | user | Grant_priv | Super_priv |
+---------------+------------------+------------+------------+
| localhost | root | Y | Y |
+---------------+------------------+------------+------------+
7 rows in set (0.00 sec)
# 创建新用户
mysql> use mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
# 这里的localhost换成%通配符,匹配所有host
mysql> CREATE USER 'root'@'%' IDENTIFIED BY '你的密码';
Query OK, 0 rows affected (0.13 sec)
# 授予新用户权限
mysql> grant all on *.* to 'root'@'%';
Query OK, 0 rows affected (0.01 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.01 sec)