MySQL數(shù)據(jù)庫怎么實(shí)現(xiàn)遠(yuǎn)程連接訪問
以下的文章主要介紹的是實(shí)現(xiàn)MySQL遠(yuǎn)程連接的實(shí)際操作流程,本文主要是由其相關(guān)的實(shí)際應(yīng)用代碼來引出MySQL遠(yuǎn)程連接的具體操作步驟,以下就是文章的主要內(nèi)容描述,希望會(huì)給你帶來一些幫助在此方面。
1、進(jìn)入MySQL,創(chuàng)建一個(gè)新用戶root,密碼為root:
格式:grant 權(quán)限 on 數(shù)據(jù)庫名.表名 to 用戶@登錄主機(jī) identified by "用戶密碼";
grant select,update,insert,delete on *.* to root@192.168.1.12 identified by "root";
原先數(shù)據(jù)表結(jié)構(gòu)
MySQL> use MySQL;
Database changed
MySQL> select host,user,password from user;
+-----------+------+-------------------------------------------+
| host | user | password |
+-----------+------+-------------------------------------------+
| localhost | root | *81F5E21E35407D884A6CD4A731AEBFB6AF209E1B |
+-----------+------+-------------------------------------------+
執(zhí)行上述語句后結(jié)果
MySQL> use MySQL;
Database changed
MySQL> select host,user,password from user;
+--------------+------+-------------------------------------------+
| host | user | password |
+--------------+------+-------------------------------------------+
| localhost | root | *81F5E21E35407D884A6CD4A731AEBFB6AF209E1B |
| 192.168.1.12 | root | *81F5E21E35407D884A6CD4A731AEBFB6AF209E1B |
+--------------+------+-------------------------------------------+
2 rows in set (0.00 sec)
可以看到在user表中已有剛才創(chuàng)建的root用戶。host字段表示登錄的主機(jī),其值可以用IP,也可用主機(jī)名,
(1)有時(shí)想用本地IP登錄,那么可以將以上的Host值改為自己的Ip即可。
2、實(shí)現(xiàn)MySQL遠(yuǎn)程連接(授權(quán)法)
將host字段的值改為%就表示在任何客戶端機(jī)器上能以root用戶登錄到MySQL服務(wù)器,建議在開發(fā)時(shí)設(shè)為%。
update user set host = ’%’ where user = ’root’;
將權(quán)限改為ALL PRIVILEGES
MySQL> use MySQL;
Database changed
MySQL> grant all privileges on *.* to root@'%' identified by "root";
Query OK, 0 rows affected (0.00 sec)
MySQL> select host,user,password from user;
+--------------+------+-------------------------------------------+
| host | user | password |
+--------------+------+-------------------------------------------+
| localhost | root | *81F5E21E35407D884A6CD4A731AEBFB6AF209E1B |
| 192.168.1.12 | root | *81F5E21E35407D884A6CD4A731AEBFB6AF209E1B |
| % | root | *81F5E21E35407D884A6CD4A731AEBFB6AF209E1B |
+--------------+------+-------------------------------------------+
3 rows in set (0.00 sec)
這樣機(jī)器就可以以用戶名root密碼root遠(yuǎn)程訪問該機(jī)器上的MySQL.
3、實(shí)現(xiàn)MySQL遠(yuǎn)程連接(改表法)
use MySQL;
update user set host = '%' where user = 'root';
這樣在遠(yuǎn)端就可以通過root用戶訪問MySQL.
關(guān)鍵詞:MySQL,數(shù)據(jù)庫
閱讀本文后您有什么感想? 已有 人給出評價(jià)!
- 1
- 1
- 1
- 1
- 1
- 1