ubuntu mysql 遠程連接


最近需要遠程連接mysql服務器,先進行簡單的測試,過程記錄於此。

參考鏈接:

  http://blog.chinaunix.net/uid-28458801-id-3445261.html

  http://stackoverflow.com/questions/1420839/cant-connect-to-mysql-server-error-111

本機ip: 192.168.1.248

遠程ip: 192.168.1.249

mysql服務器配置

# 1.更改配置文件

#因為遠程mysql服務器,設置只監聽本地的端口,更改mysql配置文件,注釋掉下面的一行。打開遠程服務器的配置文件.
sudo vi /etc/mysql/my.cnf # 注釋下面一行。
# bind-address = 127.0.0.1
# 如果沒注釋上面的一行,客戶端連接時,會出現如下錯誤。
ERROR 2003 (HY000): Can't connect to MySQL server on '192.168.1.249' (111)

# 2. 打開mysql服務
sudo service /etc/init.d/mysql start

# 3. 配置mysql服務器
qt@tony:~/Desktop$ mysql -u root -p 
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 36
Server version: 5.5.53-0ubuntu0.12.04.1 (Ubuntu)

Copyright (c) 2000, 2016, 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;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed

# 允許用戶的ip是192.168.1.248,使用用戶名為 tony, 密碼是 password進行登錄。

mysql> grant all PRIVILEGES on *.* to tony@'192.168.1.248' identified by 'password';
Query OK, 0 rows affected (0.00 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.01 sec)

mysql> quit
Bye

mysql客戶端連接

# 連接出現錯誤。
# error1:
ERROR 1045 (28000): Access denied for user 'tony'@'aplex-2.local' (using password: YES)
# 我這邊得情況是本地的ip沒有配置,從新配置ip.
sudo ifconfig eth0 192.168.1.248.

# 連接
# 以服務器設置的用戶名登錄
Qt@tony:~$ mysql -h 192.168.1.248 -u tony -p
Enter password: 
# 或者以root用戶登錄
Qt@tony:~$ mysql -h 192.168.1.249 -u tony -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 37
Server version: 5.5.53-0ubuntu0.12.04.1 (Ubuntu)

Copyright (c) 2000, 2016, 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> 

Tony Liu

2016-11-4, Shenzhen


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM