mysql如何開啟遠端訪問?

2021-12-30 07:28:31 字數 3385 閱讀 8313

mysql -u root -p

welcome to the mysql monitor. commands end with ; or \g. 

your mysql connection id is 6 

server version: 5.6.23-log source distribution

copyright (c) 2000, 2015, oracle and/or its affiliates. all rights reserved.

oracle is a registered trademark of oracle corporation and/or its 

affiliates. other names may be trademarks of their respective 

owners.

type 『help;』 or 『\h』 for help. type 『\c』 to clear the current input statement.

mysql> use mysql;

database changed

mysql> select host,user,password from user;

| host | user | password |

| localhost | root | *6bb4837eb74329105ee4568dda7dc67ed2ca2ad9 |

| 127.0.0.1 | root | |

| ::1 | root | |

| localhost | | |

4 rows in set (0.00 sec)

mysql> update user set host=』%』 where user=』root』;

error 1062 (23000): duplicate entry 『%-root』 for key 『primary』

mysql> update user set host=』 %』 where user=』root』;

error 1062 (23000): duplicate entry 』 %-root』 for key 『primary』

mysql> select host,user from user where user=』root』;

| host | user |

| % | root |

| 127.0.0.1 | root |

| ::1 | root |

3 rows in set (0.00 sec)

mysql> flush privileges;

query ok, 0 rows affected (0.02 sec)

mysql> quit;

bye./etc/init.d/mysql restart

shutting down mysql. [ ok ] 

starting mysql. [ ok ]

mysql -u root -p

error 1045 (28000): access denied for user 『root』@』localhost』 (using password: y

es)mysql -u root -p

welcome to the mysql monitor. commands end with ; or \g.

your mysql connection id is 6 

server version: 5.6.23-log source distribution

copyright (c) 2000, 2015, oracle and/or its affiliates. all rights reserved.

oracle is a registered trademark of oracle corporation and/or its 

affiliates. other names may be trademarks of their respective 

owners.

type 『help;』 or 『\h』 for help. type 『\c』 to clear the current input statement. 

mysql> exit;

byemysqladmin -uroot password 123456

mysql -uroot -p123456

welcome to the mysql monitor. commands end with ; or \g. 

your mysql connection id is 6 

server version: 5.6.23-log source distribution

copyright (c) 2000, 2015, oracle and/or its affiliates. all rights reserved.

oracle is a registered trademark of oracle corporation and/or its 

affiliates. other names may be trademarks of their respective 

owners.

type 『help;』 or 『\h』 for help. type 『\c』 to clear the current input statement. 

mysql> grant all privileges on . to 『root』@』%』 identified by 『123456』 with gra

nt option;

query ok, 0 rows affected (0.00 sec)

mysql> flush privileges;

query ok, 0 rows affected (0.00 sec)

解釋下上面遇到的問題:

1.首先查詢有沒有開啟遠端訪問(可以讓任意ip通過root使用者訪問)

2.沒有開啟,則修改host=』%』,會報錯:error 1062 (23000): duplicateentry 』 %-root』for key』primary』

4.通過命令重新登入報錯:error 1045 (28000): access denied for user 『root』@』localhost』 (using password: yes),原因是密碼變成空了,重新設定密碼:mysqladmin -uroot password 123456

5.這個時候訪問還是報錯: host ip is not allowed to connect to this mysql。通過以下兩個命令即可解決,grant all privileges on . to 『root』@』%』 identified by 『123456』 with grant option;flush privileges;

mysql如何開啟遠端訪問

1 確定伺服器上的防火牆沒有阻止 3306 埠。mysql 預設的埠是 3306 需要確定防火牆沒有阻止 3306 埠,否則遠端是無法通過 3306 埠連線到 mysql 的。如果您在安裝 mysql 時指定了其他埠,請在防火牆中開啟您指定的 mysql 使用的埠號。2 增加允許遠端連線 mysql...

mysql 開啟遠端訪問 遠端訪問

select host,user,password from user 查詢使用者遠端訪問相關資訊 用root使用者登陸,然後 grant all privileges on to 建立的使用者名稱 identified by 密碼 flush privileges 重新整理剛才的內容 格式 gra...

MySQL 開啟遠端訪問

登入mysql mysql u root p 輸入密碼建立賬號 mysql use mysql mysql create user remote user identified by password 表示可以接受從任意ip的主機訪問,也可以寫成固定ip,這樣就只能從這個ip的機子訪問。為這個賬號賦...