2011-11-22 53 views
0

我的程序與遠程MySQL服務器一起工作,我想在我的計算機上創建一個本地代理服務器以使事情更快(連接池連接,緩存查詢等)。我去過的文檔:http://dev.mysql.com/doc/refman/5.1/en/mysql-proxy.html遠程MySQL服務器的mysql-proxy

我跑,一個控制檯上:

[email protected]:~$ mysql-proxy --proxy-backend-addresses=$MYSQL --log-level=debug2011-11-22 09:43:30: (message) mysql-proxy 0.8.2 started 
2011-11-22 09:43:30: (debug) max open file-descriptors = 1024 
2011-11-22 09:43:30: (message) proxy listening on port :4040 
2011-11-22 09:43:30: (message) added read/write backend: qa-srv:3308 

而另一控制檯上:

[email protected]:~$ mysql --user root --host=localhost --port=4040 
Welcome to the MySQL monitor. Commands end with ; or \g. 
Your MySQL connection id is 81 
Server version: 5.1.41-3ubuntu12.10 (Ubuntu) 

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. 

mysql> show databases; 

然而,也看不到遠程服務器上的數據庫(QA -srv)我在本地服務器上看到了數據庫!

我也試過這樣:

[email protected]:~$ mysql --user root --host=qa-srv --port=4040 
ERROR 2003 (HY000): Can't connect to MySQL server on 'qa-srv' (111) 

我也試過運行代理,而不是MySQL守護程序:

[email protected]:~$ sudo service mysql stop 
mysql stop/waiting 
[email protected]:~$ mysql-proxy --proxy-backend-addresses=$MYSQL --log-level=debug --proxy-address=0.0.0.0:3306 
2011-11-22 14:14:25: (message) mysql-proxy 0.8.2 started 
2011-11-22 14:14:25: (debug) max open file-descriptors = 1024 
2011-11-22 14:14:25: (message) proxy listening on port 0.0.0.0:3306 
2011-11-22 14:14:25: (message) added read/write backend: qa-srv:3308 

而另一控制檯上:

[email protected]:~$ mysql --user root 
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2) 

我怎樣才能告訴我的mysql客戶端通過本地代理連接到遠程服務器?

回答

2

萬歲!我找到了解決方案。

在控制檯答:

[email protected]:~$ mysql-proxy --proxy-backend-addresses=qa-srv:3308 --log-level=debug --proxy-address=127.0.0.1:3306 
2011-11-22 18:55:02: (message) mysql-proxy 0.8.2 started 
2011-11-22 18:55:02: (debug) max open file-descriptors = 1024 
2011-11-22 18:55:02: (message) proxy listening on port 127.0.0.1:3306 
2011-11-22 18:55:02: (message) added read/write backend: qa-srv:3308 

在控制檯B:

[email protected]:~$ mysql -u <username-on-remote-database> -h 127.0.0.1 

,或者,如果你仍然想在本地數據庫的活動:

在控制檯答:

[email protected]:~$ mysql-proxy --proxy-backend-addresses=qa-srv:3308 --log-level=debug 
2011-11-22 18:55:02: (message) mysql-proxy 0.8.2 started 
2011-11-22 18:55:02: (debug) max open file-descriptors = 1024 
2011-11-22 18:55:02: (message) proxy listening on port 127.0.0.1:3306 
2011-11-22 18:55:02: (message) added read/write backend: qa-srv:3308 

在控制檯B上:

[email protected]:~$ mysql -u <username-on-remote-database> -h 127.0.0.1 -P 4040 
+0

這對我而言並不適用於0.8.5 –