ubuntu mysql 遠程鏈接

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

參考連接:

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

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

本機ip: 192.168.1.248ubuntu

遠程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 Liuide

2016-11-4, Shenzhen測試

相關文章
相關標籤/搜索