mysql中grant all privileges on賦給使用者遠端權限
改表法。
當你的帳號不允許從遠端登陸,只能在localhost連線時。這時候只要在mysql伺服器上,更改mysql 資料庫裡的user 表裡的host 項,從localhost"改成%即可實現用戶遠端登入
在安裝mysql的機器上運行:
1. mysql -u root -p
2. select host,user from user where user='root';
3. update user set host = '%' 其中 user= 'root' and host='localhost';
4. select host, user from user where user='root';
授權法
[root@aaa-server ~]# mysql -u root -p MariaDB [(none)]> grant all privileges on *.* to root@'%' identified by '123' with grant option; Query OK, 0 rows affected (0.00 sec) MariaDB [(none)]> flush privileges; Query OK, 0 rows affected (0.01 sec) MariaDB [(none)]> flush privileges; Query OK, 0 rows affected (0.00 sec) MariaDB [(none)]> exit Bye
授權法。
例如,你想要user使用mypwd從任何主機連接到mysql伺服器的話。
在安裝mysql的機器上運行:
1. GRANT ALL PRIVILEGES ON *.* TO 'user'@'%' IDENTIFIED BY 'mypwd' WITH GRANT OPTION; 2.FLUSH PRIVILEGES; 模板: grant all privileges on 库名.表名 to '用户名'@'IP地址' identified by '密码' with grant option; flush privileges;
如果你想允許用戶user從ip為192.168.1.4的主機連接到mysql伺服器,並使用mypwd作為密碼
在安裝mysql的機器上運行:
GRANT ALL PRIVILEGES ON *.* TO 'user'@'192.168.1.3' IDENTIFIED BY 'mypwd' WITH GRANT OPTION; FLUSH PRIVILEGES;
注意授權後必須FLUSH PRIVILEGES;否則無法立即生效。
高版本資料庫無法依照grant all privileges on *.* to "root"@"%" identified by "xxxx";去修改使用者權限
mysql> SELECT @@VERSION; +-----------+ | @@VERSION | +-----------+ | 8.0.14 | +-----------+ 1 row in set (0.00 sec)
高版本修改使用者權限方法:
# 先创建远程用户,再授权 mysql> create user 'root'@'%' identified by 'password'; Query OK, 0 rows affected (0.03 sec) mysql> grant all privileges on *.* to 'root'@'%' with grant option; Query OK, 0 rows affected (0.01 sec) mysql> flush privileges; Query OK, 0 rows affected (0.00 sec)
再次查看發現有了root %
mysql> select User,Host from user; +------------------+-----------+ | User | Host | +------------------+-----------+ | root | % | | mysql.infoschema | localhost | | mysql.session | localhost | | mysql.sys | localhost | | root | localhost | +------------------+-----------+ 5 rows in set (0.00 sec) ————————————————
mysql的賦權語句:
grant all privileges on *.* to 'root'@'%' identified by '123456' with grant option;
all privileges ==》 表示所有的權限,增刪改核權限全部都有了
刷新權限清單:flush privileges#
CREATE DATABASE 数据库名; CREATE USER '用户名'@'%' IDENTIFIED BY '密码'; GRANT all privileges ON 数据库名.* to '用户名'@'%' identified by '密码' WITH GRANT OPTION; flush privileges;
drop user ‘jack'@'%';
以上是mysql中grant all privileges on怎麼賦給使用者遠端權限的詳細內容。更多資訊請關注PHP中文網其他相關文章!