Linux technical support - support@alexlinux.com


mysql multiple instances on CentOS 7

mkdir -p /data/db/mysql
./mysql_install_db --datadir=/data/db/mysql/mysql-instance-01
./mysql_install_db --datadir=/data/db/mysql/mysql-instance-02
./mysql_install_db --datadir=/data/db/mysql/mysql-instance-03
./mysql_install_db --datadir=/data/db/mysql/mysql-instance-04
cp /usr/share/mysql/my-medium.cnf /data/db/mysql/mysql-instance-01/my.cnf
cp /usr/share/mysql/my-medium.cnf /data/db/mysql/mysql-instance-02/my.cnf
cp /usr/share/mysql/my-medium.cnf /data/db/mysql/mysql-instance-03/my.cnf
cp /usr/share/mysql/my-medium.cnf /data/db/mysql/mysql-instance-04/my.cnf
vi /data/db/mysql/mysql-instance-01/my.cnf

[mysqld]
port = 44001
socket = /var/lib/mysql/mysql-instance-01.sock
skip-external-locking
key_buffer_size = 16M
max_allowed_packet = 1M
table_open_cache = 64
sort_buffer_size = 512K
net_buffer_length = 8K
read_buffer_size = 256K
read_rnd_buffer_size = 512K
myisam_sort_buffer_size = 8M
innodb_file_per_table

datadir = /data/db/mysql/mysql-instance-01/
log-error = /data/db/mysql/mysql-instance-01/mysql-instance-01.log
innodb_data_home_dir = /data/db/mysql/mysql-instance-01/
innodb_log_group_home_dir = /data/db/mysql/mysql-instance-01/

chown -R mysql:mysql /data/db/mysql
vim /usr/lib/systemd/system/mariadb01.service

[Unit]
Description=MariaDB database server instance-01
After=syslog.target
After=network.target

[Service]
Type=simple
User=mysql
Group=mysql

ExecStart=/usr/bin/mysqld_safe --defaults-file=/data/db/mysql/mysql-instance-01/my.cnf --user=mysql --basedir=/usr

# Give a reasonable amount of time for the server to start up/shut down
TimeoutSec=300

# Place temp files in a secure directory, not /tmp
PrivateTmp=true

[Install]
WantedBy=multi-user.target

systemctl start mariadb01
systemctl enable mariadb01

Connect command:

mysql -P 44001 -h 127.0.0.1 -u root

One thought on “mysql multiple instances on CentOS 7

  1. Peter

    mysql_install_db seems to be deprecated. Please update this manual!

    2019-06-24 15:50:19 [WARNING] mysql_install_db is deprecated. Please consider switching to mysqld –initialize

    Reply

Leave a Reply

Your email address will not be published.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>