Il est possible d'utiliser le meme binaire mysql pour gérer plusieurs instances mysql sur des ports et/ou ip differentes sur le même serveur. ==Installation== L'installation se fait via le systeme de paquet habituel
# yum install mysql-server
Une fois installé nous allons crée les repertoires qui contiendront les nouvelles instances
# mkdir -p /export/data/mysql_33023
# mkdir -p /export/data/mysql_33024
Puis nous allons faire des liens depuis /var/lib (optionnel car les chemins plus haut peuvent être défini en dur sur le fichier de configuration):
# cd /var/lib
# ln -s /export/data/mysql_33023
# ln -s /export/data/mysql_33024
Enfin, nous allons installer les bases
# mysql_install_db --user=mysql --datadir=/var/lib/mysql_33023/
# mysql_install_db --user=mysql --datadir=/var/lib/mysql_33024/
==Configuration== Dans le fichier my.cnf [mysqld_multi] mysqld = /usr/bin/mysqld_safe mysqladmin = /usr/bin/mysqladmin user = multi_admin password = xxxxxxx log = /var/log/mysqld_multi.log [mysqld33023] socket = /var/lib/mysql_33023/mysql.sock port = 33023 pid-file = /var/lib/mysql_33023/mrs-prd-ossbdd-1.pid datadir = /var/lib/mysql_33023 language = /usr/share/mysql/english user = mysql mysqld = /usr/libexec/mysqld log-error = /var/lib/mysql_33023/mrs-prd-ossbdd-1.err [mysqld33024] socket = /var/lib/mysql_33024/mysql.sock port = 33024 pid-file = /var/lib/mysql_33024/mrs-prd-ossbdd-1.pid datadir = /var/lib/mysql_33024 language = /usr/share/mysql/english user = mysql mysqld = /usr/libexec/mysqld log-error = /var/lib/mysql_33024/mrs-prd-ossbdd-1.err Il est possible de lancer les instances
# mysqld_multi start 33023
# mysqld_multi start 33024
Enfin, il faut créer l'utilisateur multi_admin afin de lui permettre d'éteindre les instances. Nous allons aussi modifier l'utilisateur root
# mysql -u root -S /var/lib/mysql_33023/mysql.sock -p
mysql> GRANT SHUTDOWN ON *.* TO 'multi_admin'@'localhost' IDENTIFIED BY 'xxxxxxx';
mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' identified by "yyyyyyy" WITH GRANT OPTION;
mysql> flush privileges;
# mysql -u root -S /var/lib/mysql_33024/mysql.sock -p
mysql> GRANT SHUTDOWN ON *.* TO 'multi_admin'@'localhost' IDENTIFIED BY 'xxxxxxx';
mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' identified by "yyyyyyy" WITH GRANT OPTION;
mysql> flush privileges;
Il est désormais possible d'éteindre les instances
# mysqld_multi stop 33023
# mysqld_multi stop 33024
==Lancement au boot== Copier le scripts dans /etc/init.d/mysqld_multi.server #!/bin/sh # # A simple startup script for mysqld_multi by Tim Smith and Jani Tolonen. # This script assumes that my.cnf file exists either in /etc/my.cnf or # /root/.my.cnf and has groups [mysqld_multi] and [mysqldN]. See the # mysqld_multi documentation for detailed instructions. # # This script can be used as /etc/init.d/mysql.server # # Comments to support chkconfig on RedHat Linux # chkconfig: 2345 64 36 # description: A very fast and reliable SQL database engine. # # Version 1.0 # basedir=/var/lib/mysql/mysql bindir=/usr/bin/ if test -x $bindir/mysqld_multi then mysqld_multi="$bindir/mysqld_multi"; else echo "Can't execute $bindir/mysqld_multi from dir $basedir"; exit; fi case "$1" in 'start' ) "$mysqld_multi" start $2 ;; 'stop' ) "$mysqld_multi" stop $2 ;; 'report' ) "$mysqld_multi" report $2 ;; 'restart' ) "$mysqld_multi" stop $2 "$mysqld_multi" start $2 ;; *) echo "Usage: $0 {start|stop|report|restart}" >&2 ;; esac On rajoute les droits d'execution. Puis on test que toutes les instances se lancent et s'arrêtent correctement via le script :
# /etc/init.d/mysqld_multi.server start
# /etc/init.d/mysqld_multi.server stop
Puis configurer chkconfig
# chkconfig mysqld_multi.server on
==Administration== ===Lancement de l'instance 33024===
# mysqld_multi start 33024
ou
# /etc/init.d/mysqld_multi.server start 33024
===Extinction de l'instance 33024===
# mysqld_multi stop 33024
ou
# /etc/init.d/mysqld_multi.server stop 33024
===Status de l'instance 33024===
# mysqld_multi report 33024
ou
# /etc/init.d/mysqld_multi.server start 33024
===Connexion à l'instance 33024===
# mysql -S /export/data/mysql_33024/mysql.sock -u root -p