首页 > 代码库 > 修改MySQL中权限,为远程授权

修改MySQL中权限,为远程授权

在进入mysql之后,输入相应的语句:

GRANT ALL PRIVILEGES ON *.* TO myuser@% IDENTIFIED BY mypassword WITH GRANT OPTION;

其中myusermypassword 需要替换成实际的用户名和密码。
例如GRANT ALL PRIVILEGES ON *.* TO root@% IDENTIFIED BY admin WITH GRANT OPTION;

可能会报错,如下:

ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.

 

改正:

mysql> set password=password(admin);
Query OK, 0 rows affected, 1 warning (0.01 sec)

mysql> GRANT ALL PRIVILEGES ON *.* TO root@% IDENTIFIED BY admin WITH GRANT OPTION; FLUSH PRIVILEGES;
Query OK, 0 rows affected, 1 warning (0.00 sec)

Query OK, 0 rows affected (0.00 sec)

mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.00 sec)

mysql> quit;
Bye

成功修改

修改MySQL中权限,为远程授权