Last active
March 28, 2017 18:56
-
-
Save tonejito/e965b9b591e23bbf9f90c0b538583d42 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| # = ^ . ^ = | |
| MYSQL_PROXY_ADMIN=admin | |
| MYSQL_PROXY_PW=mysql | |
| MYSQL_PROXY_SQL=mysql-proxy-admin.sql | |
| mysql --verbose --table -h 127.0.0.1 -P 4401 -u "$MYSQL_PROXY_ADMIN" -p"$MYSQL_PROXY_PW" < $MYSQL_PROXY_SQL |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| -- = ^ . ^ = | |
| SELECT * FROM help ; | |
| SELECT * FROM backends ; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # = ^ . ^ = | |
| # 0660 root:mysql /etc/mysql/conf.d/mysql-proxy.cnf | |
| # defaults-file for mysql-proxy | |
| # https://downloads.mysql.com/docs/mysql-proxy-en.pdf | |
| # https://downloads.mysql.com/archives/proxy/ | |
| # https://downloads.mysql.com/docs/mysql-proxy-relnotes-en.pdf | |
| # https://downloads.mysql.com/forge/slides/MySQL-Proxy.pdf | |
| # https://www.mysql.com/wiki/MySQL_Proxy_FAQ/ | |
| # https://dev.mysql.com/doc/mysql/en/mysql-proxy.html | |
| # https://dev.mysql.com/tech-resources/quickpolls/mysql-proxy.html | |
| # https://github.com/mysql/mysql-proxy | |
| # http://stackoverflow.com/a/16411996 | |
| [mysql-proxy] | |
| daemon=true | |
| # log-level=(error|warning|info|message|debug) | |
| log-level=message | |
| #log-use-syslog | |
| user=mysql | |
| proxy-skip-profiling=true | |
| keepalive=true | |
| pid-file=/var/run/mysql-proxy.pid | |
| log-file=/var/log/mysql/mysql-proxy.log | |
| admin-address=127.0.0.1:4401 | |
| admin-username=admin | |
| admin-password=mysql | |
| admin-lua-script=/usr/lib/mysql-proxy/lua/admin.lua | |
| proxy-address=/var/run/mysqld/mysqld.sock | |
| proxy-backend-addresses=192.0.2.1:3306 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # = ^ . ^ = | |
| # 0644 root:root /etc/default/mysql-proxy | |
| ENABLED="true" | |
| OPTIONS="--defaults-file=/etc/mysql/conf.d/mysql-proxy.cnf" | |
| MYSQL_RUN_DIR=/var/run/mysqld | |
| function make_run_dir | |
| { | |
| if [ ! -e $MYSQL_RUN_DIR ] | |
| then | |
| mkdir -vp $MYSQL_RUN_DIR | |
| fi | |
| chown mysql:root $MYSQL_RUN_DIR | |
| } | |
| MYSQL_SOCKET=$MYSQL_RUN_DIR/mysqld.sock | |
| function clean_socket | |
| { | |
| if [ -e $MYSQL_SOCKET ] | |
| then | |
| rm -v $MYSQL_SOCKET | |
| fi | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #! /bin/sh | |
| # 0644 root:root /etc/init.d/mysql-proxy | |
| ### BEGIN INIT INFO | |
| # Provides: mysql-proxy | |
| # Required-Start: $syslog $remote_fs | |
| # Required-Stop: $syslog $remote_fs | |
| # Default-Start: 2 3 4 5 | |
| # Default-Stop: 0 1 6 | |
| # Short-Description: MySQL Proxy | |
| ### END INIT INFO | |
| PATH=/bin:/usr/bin:/sbin:/usr/sbin | |
| LUA_PATH="/usr/share/mysql-proxy/?.lua" | |
| DAEMON="/usr/bin/mysql-proxy" | |
| PIDFILE="/var/run/mysql-proxy.pid" | |
| test -f $DAEMON || exit 0 | |
| test ! -r /etc/default/mysql-proxy || . /etc/default/mysql-proxy | |
| if ! $ENABLED ; then exit 0 ; fi | |
| . /lib/lsb/init-functions | |
| case "$1" in | |
| start) | |
| log_begin_msg "Starting MySQL Proxy daemon..." | |
| start-stop-daemon --start --quiet --pidfile $PIDFILE --make-pidfile --name mysql-proxy --startas $DAEMON -b -- $OPTIONS | |
| log_end_msg $? | |
| ;; | |
| stop) | |
| log_begin_msg "Stopping MySQL Proxy daemon..." | |
| start-stop-daemon --stop --quiet --retry 3 --exec $DAEMON --pidfile $PIDFILE | |
| log_end_msg $? | |
| ;; | |
| status) | |
| log_begin_msg "Checking MySQL Proxy daemon... " | |
| status_of_proc -p $PIDFILE /usr/sbin/mysql-proxy mysql-proxy && exit 0 || exit $? | |
| ;; | |
| restart|force-reload) | |
| log_begin_msg "Reloading MySQL Proxy daemon..." | |
| start-stop-daemon --stop --quiet --retry 3 --exec $DAEMON --pidfile $PIDFILE | |
| start-stop-daemon --start --quiet --pidfile $PIDFILE --make-pidfile --name mysql-proxy --startas $DAEMON -b -- $OPTIONS | |
| log_end_msg $? | |
| ;; | |
| *) | |
| log_success_msg "Usage: $0 {start|stop|status|restart|force-reload}" | |
| exit 1 | |
| esac | |
| exit 0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| SHELL=/bin/bash | |
| # = ^ . ^ = | |
| MYSQL_PROXY_DEFAULT=/etc/default/mysql-proxy | |
| MYSQL_PROXY_CNF=/etc/mysql/conf.d/mysql-proxy.cnf | |
| MYSQL_PROXY_INITD=/etc/init.d/mysql-proxy | |
| MYSQL_LOG_DIR=/var/log/mysql/ | |
| MYSQL_RUN_DIR=/var/run/mysqld/ | |
| MYSQL_USER=mysql | |
| MYSQL_GROUP=mysql | |
| mysql-proxy: install user config directories | |
| @echo Be sure to edit the configuration files accordingly: | |
| @echo " + ${MYSQL_PROXY_DEFAULT}" | |
| @echo " + ${MYSQL_PROXY_CNF}" | |
| @echo " + ${MYSQL_PROXY_INITD}" | |
| @echo "" | |
| @echo After this, restart the service and check out log messages: | |
| @echo " + ${MYSQL_LOG_DIR}mysql-proxy.log" | |
| @echo "" | |
| @echo '--' | |
| @echo '= ^ . ^ =' | |
| install: | |
| aptitude install mysql-proxy | |
| user: | |
| addgroup --system ${MYSQL_GROUP} | |
| getent group ${MYSQL_GROUP} | awk -F : '{print $3}' | xargs -r -t -I {} \ | |
| adduser --system --home /nonexistent --no-create-home --shell /bin/false --gid {} --disabled-password --disabled-login ${MYSQL_USER} | |
| config: | |
| touch ${MYSQL_PROXY_CNF} | |
| chown root:mysql ${MYSQL_PROXY_CNF} | |
| chmod 0660 ${MYSQL_PROXY_CNF} | |
| directories: | |
| mkdir -vp ${MYSQL_LOG_DIR} | |
| chown -c ${MYSQL_USER}:adm ${MYSQL_LOG_DIR} | |
| chmod -c 2750 ${MYSQL_LOG_DIR} | |
| mkdir -vp ${MYSQL_RUN_DIR} | |
| chown -c ${MYSQL_USER}:root ${MYSQL_RUN_DIR} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| -- = ^ . ^ = | |
| STATUS ; | |
| SHOW GRANTS ; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment