mysql中g(shù)rant?all?privileges?on賦給用戶遠程權(quán)限方式
mysql grant all privileges on賦給用戶遠程權(quán)限
mysql中g(shù)rant all privileges on賦給用戶遠程權(quán)限
- 改表法。
當你的帳號不允許從遠程登陸,只能在localhost連接時。這個時候只要在mysql服務(wù)器上,更改 mysql 數(shù)據(jù)庫里的 user 表里的 host 項,從localhost"改成%即可實現(xiàn)用戶遠程登錄
在安裝mysql的機器上運行:
1. mysql -u root -p
2. select host,user from user where user='root';
3. update user set host = '%' where user='root' and host='localhost';
4. select host, user from user where user='root';
- 授權(quán)法
[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
- 授權(quán)法。
例如,你想user使用mypwd從任何主機連接到mysql服務(wù)器的話。
在安裝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服務(wù)器,并使用mypwd作為密碼
在安裝mysql的機器上運行:
?GRANT ALL PRIVILEGES ON *.* TO 'user'@'192.168.1.3' IDENTIFIED BY 'mypwd' WITH GRANT OPTION; ?? ?FLUSH ? PRIVILEGES;
注意授權(quán)后必須FLUSH PRIVILEGES;否則無法立即生效。
高版本數(shù)據(jù)庫不能按照grant all privileges on *.* to "root"@"%" identified by "xxxx";去修改用戶權(quán)限
mysql> SELECT @@VERSION; +-----------+ | @@VERSION | +-----------+ | 8.0.14 ? ?| +-----------+ 1 row in set (0.00 sec)
高版本修改用戶權(quán)限方法:
# 先創(chuàng)建遠程用戶,再授權(quán) 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)
再次查看發(fā)現(xiàn)有了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授權(quán)語句說明grant all privileges、創(chuàng)建用戶、刪除用戶
mysql的賦權(quán)語句:
grant all privileges on *.* to 'root'@'%' identified by '123456' with grant option;
- all privileges ==》 表示所有的權(quán)限 ,增刪改查權(quán)限全部都有了
- *.* ==> 所有的數(shù)據(jù)庫下面所有的表
- root@% ==》 所有數(shù)據(jù)庫下面所有的表,所有的權(quán)限,全部都給root用戶 % 表示root用戶可以在任意機器上面進行連接登錄
- identified by '123456' ==》遠程登錄連接的密碼
刷新權(quán)限列表:flush privileges
CREATE DATABASE 數(shù)據(jù)庫名; CREATE USER '用戶名'@'%' IDENTIFIED BY '密碼'; ? ? GRANT all privileges ON 數(shù)據(jù)庫名.* to '用戶名'@'%' identified by '密碼' WITH GRANT OPTION;? flush privileges;
創(chuàng)建用戶:CREATE USER 'jack'@'localhost' IDENTIFIED BY 'test123';
查看數(shù)據(jù)庫中已經(jīng)創(chuàng)建的用戶:select user,host from user;--user表在數(shù)據(jù)庫自帶的、名字為mysql的數(shù)據(jù)庫中
刪除用戶:delete from user where user = 'jack';
drop user ‘jack'@'%';?
drop user 會將該用戶的信息全部刪掉,而 delete 只會清除user表,其他的比如db表中的信息還是存在。
清除緩存:FLUSH PRIVILEGES
總結(jié)
以上為個人經(jīng)驗,希望能給大家一個參考,也希望大家多多支持腳本之家。
相關(guān)文章
MySQL數(shù)據(jù)庫使用mysqldump導(dǎo)出數(shù)據(jù)詳解
mysqldump是mysql用于轉(zhuǎn)存儲數(shù)據(jù)庫的實用程序。它主要產(chǎn)生一個SQL腳本,其中包含從頭重新創(chuàng)建數(shù)據(jù)庫所必需的命令CREATE TABLE INSERT等。接下來通過本文給大家介紹MySQL數(shù)據(jù)庫使用mysqldump導(dǎo)出數(shù)據(jù)詳解,需要的朋友一起學(xué)習(xí)吧2016-04-04關(guān)于k8s環(huán)境部署mysql主從的問題
這篇文章主要介紹了k8s環(huán)境部署mysql主從的問題,本文給大家介紹的非常詳細,對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下2022-03-03MySQL優(yōu)化表時提示 Table is already up to date的解決方法
這篇文章主要介紹了MySQL優(yōu)化表時提示 Table is already up to date的解決方法,需要的朋友可以參考下2016-11-11gearman + mysql方式實現(xiàn)持久化操作示例
這篇文章主要介紹了gearman + mysql方式實現(xiàn)持久化操作,簡單描述了持久化的概念、原理,并結(jié)合實例形式分析了gearman + mysql持久化操作相關(guān)實現(xiàn)技巧,需要的朋友可以參考下2020-02-02