国产成人精品亚洲777人妖,欧美日韩精品一区视频,最新亚洲国产,国产乱码精品一区二区亚洲

您的位置:首頁(yè)技術(shù)文章
文章詳情頁(yè)

mysql中g(shù)rant all privileges on賦給用戶遠(yuǎn)程權(quán)限方式

瀏覽:120日期:2023-05-05 10:12:04
目錄
  • mysql grant all privileges on賦給用戶遠(yuǎn)程權(quán)限
  • mysql授權(quán)語(yǔ)句說(shuō)明grant all privileges、創(chuàng)建用戶、刪除用戶
  • 總結(jié)

mysql grant all privileges on賦給用戶遠(yuǎn)程權(quán)限

mysql中g(shù)rant all privileges on賦給用戶遠(yuǎn)程權(quán)限

  • 改表法。

當(dāng)你的帳號(hào)不允許從遠(yuǎn)程登陸,只能在localhost連接時(shí)。這個(gè)時(shí)候只要在mysql服務(wù)器上,更改 mysql 數(shù)據(jù)庫(kù)里的 user 表里的 host 項(xiàng),從localhost"改成%即可實(shí)現(xiàn)用戶遠(yuǎn)程登錄

在安裝mysql的機(jī)器上運(yùn)行:

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從任何主機(jī)連接到mysql服務(wù)器的話。

在安裝mysql的機(jī)器上運(yùn)行:

1. GRANT ALL PRIVILEGES ON *.* TO "user"@"%" IDENTIFIED BY "mypwd" WITH
      GRANT OPTION;  
2.FLUSH   PRIVILEGES;
模板:
grant all privileges on 庫(kù)名.表名 to "用戶名"@"IP地址" identified by "密碼" with grant option;
flush privileges;
  • 如果你想允許用戶user從ip為192.168.1.4的主機(jī)連接到mysql服務(wù)器,并使用mypwd作為密碼

在安裝mysql的機(jī)器上運(yùn)行:

?GRANT ALL PRIVILEGES ON *.* TO "user"@"192.168.1.3" IDENTIFIED BY "mypwd" WITH GRANT OPTION; ??
?FLUSH ? PRIVILEGES;

注意授權(quán)后必須FLUSH PRIVILEGES;否則無(wú)法立即生效。

高版本數(shù)據(jù)庫(kù)不能按照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)建遠(yuǎn)程用戶,再授權(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)語(yǔ)句說(shuō)明grant all privileges、創(chuàng)建用戶、刪除用戶

mysql的賦權(quán)語(yǔ)句:

grant all privileges on *.* to "root"@"%" identified by "123456" with grant option;
  • all  privileges   ==》  表示所有的權(quán)限 ,增刪改查權(quán)限全部都有了
  • *.*                     ==>  所有的數(shù)據(jù)庫(kù)下面所有的表
  • root@%   ==》  所有數(shù)據(jù)庫(kù)下面所有的表,所有的權(quán)限,全部都給root用戶    % 表示root用戶可以在任意機(jī)器上面進(jìn)行連接登錄
  • identified by '123456'   ==》遠(yuǎn)程登錄連接的密碼

刷新權(quán)限列表:flush   privileges

CREATE DATABASE 數(shù)據(jù)庫(kù)名;
CREATE USER "用戶名"@"%" IDENTIFIED BY "密碼"; ? ?
GRANT all privileges ON 數(shù)據(jù)庫(kù)名.* to "用戶名"@"%" identified by "密碼" WITH GRANT OPTION;?
flush privileges;

創(chuàng)建用戶:CREATE USER 'jack'@'localhost' IDENTIFIED BY 'test123';

查看數(shù)據(jù)庫(kù)中已經(jīng)創(chuàng)建的用戶:select user,host from user;--user表在數(shù)據(jù)庫(kù)自帶的、名字為mysql的數(shù)據(jù)庫(kù)中

刪除用戶:delete from user where user = 'jack'; 

drop user ‘jack"@"%";?

drop  user  會(huì)將該用戶的信息全部刪掉,而 delete  只會(huì)清除user表,其他的比如db表中的信息還是存在。

清除緩存:FLUSH PRIVILEGES

總結(jié)

以上為個(gè)人經(jīng)驗(yàn),希望能給大家一個(gè)參考,也希望大家多多支持。

標(biāo)簽: MySQL
主站蜘蛛池模板: 巴林左旗| 临潭县| 永靖县| 漳浦县| 五大连池市| 邢台县| 独山县| 鄂尔多斯市| 永靖县| 芮城县| 孟州市| 平度市| 成安县| 澄城县| 洞口县| 张家川| 崇义县| 民县| 莎车县| 井研县| 新余市| 通许县| 和平区| 赤城县| 军事| 普洱| 孟村| 叶城县| 镇远县| 湄潭县| 全南县| 常州市| 佛坪县| 武强县| 双峰县| 油尖旺区| 会宁县| 庆阳市| 新河县| 德惠市| 莱芜市|