====== Proxy local mysql socket over the network ======
As an user of [[http://www.openvz.org|OpenVZ]] it's often my task to migrate database driven web applications to separate environments. In recent versions of OpenVZ, bind mounting of sockets between virtual environments is prohibited. I had to find a way to proxy local connections to ''/var/run/mysqld/mysqld.sock'' to the remote mysql server.
First I've created a mysql user and group:
addgroup --system mysql
adduser --system --home /var/run/mysqld --ingroup mysql mysql
Then I've installed and configured the excellent ''socat'' utility using ''launchtool''.
''db.vz'' is the address remote database host in the following executable ''launchtool'' configuration script
#!/usr/bin/launchtool -C
tag = mysql-proxy
daemon = yes
user = mysql
command = socat UNIX-LISTEN:/var/run/mysqld/mysqld.sock,fork,mode=0666 TCP:db.vz:3306,forever
start dir = /var/run/mysqld
wait times = 5
infinite runs = yes
stats = yes
launchtool output = syslog:mysql-proxy,LOG_DAEMON,LOG_INFO
launchtool errors = syslog:mysql-proxy,LOG_DAEMON,LOG_ERR
command output = syslog:mysql-proxy,LOG_DAEMON,LOG_INFO
command errors = syslog:mysql-proxy,LOG_DAEMON,LOG_ERR
Update: this method seems reliable but rather slow when an application continously creates lots of connections - like does PHP
{{tag>socat proxy mysql socket remote openvz}}
~~LINKBACK~~