【问题标题】:mysql-proxy for a remote MySQL server用于远程 MySQL 服务器的 mysql-proxy
【发布时间】:2011-11-22 07:51:18
【问题描述】:

我的程序与远程 MySQL 服务器一起工作,我想在我的计算机上创建一个本地代理服务器以加快速度(池连接、缓存查询等)。我查看了文档:http://dev.mysql.com/doc/refman/5.1/en/mysql-proxy.html

我在一个控制台上运行:

erelsgl@ubuntu:~$ 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

在另一个控制台上:

erelsgl@ubuntu:~$ 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) 上的数据库,而是看到了本地服务器上的数据库!

我也试过这个:

erelsgl@ubuntu:~$ mysql --user root --host=qa-srv --port=4040
ERROR 2003 (HY000): Can't connect to MySQL server on 'qa-srv' (111)

我也尝试运行代理而不是 mysql 守护进程:

erelsgl@ubuntu:~$ sudo service mysql stop
mysql stop/waiting
erelsgl@ubuntu:~$ 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

在另一个控制台上:

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

如何告诉我的 mysql 客户端通过本地代理连接到远程服务器?

【问题讨论】:

    标签: mysql-proxy


    【解决方案1】:

    万岁!我找到了解决方案。

    在控制台 A 上:

    erelsgl@ubuntu:~$ 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 上:

    erelsgl@ubuntu:~$ mysql -u <username-on-remote-database> -h 127.0.0.1
    

    或者,如果您仍然希望本地数据库处于活动状态:

    在控制台 A 上:

    erelsgl@ubuntu:~$ 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 上:

    erelsgl@ubuntu:~$ mysql -u <username-on-remote-database> -h 127.0.0.1 -P 4040
    

    【讨论】:

      猜你喜欢
      • 2012-12-13
      • 2017-04-21
      • 2018-02-02
      • 2016-06-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-11-12
      • 1970-01-01
      相关资源
      最近更新 更多