Multi Instances

Running MySQL with different data directory,socket,pid

Enable the MySQL 8.0 repository

yum localinstall https://dev.mysql.com/get/mysql80-community-release-el7-1.noarch.rpm

Install MySQL 8 package

yum install mysql-community-server

Create the directory struction for the MySQL instance

mkdir -pv /opt/foobar_mysql

Set the owner:group of the directory structure

chown mysql:mysql -Rv /opt/foobar_mysql

Set the permissions of the directory structure

chmod 750 -Rv /opt/foobar_mysql

Initialize data directory

mysqld --initialize-insecure --user=mysql --basedir=/opt/foobar_mysql --datadir=/opt/foobar_mysql

Check that the default MySQL tables are there

ls -la /opt/foobar_mysql/mysql

Add the initial configuration to /etc/my.cnf

Create the error log file

touch -v /var/log/foobar_mysqld.log

Set the permissions on the error log file

chown -v mysql:mysql /var/log/foobar_mysqld.log

Dealing with SELinux

https://dev.mysql.com/doc/refman/8.0/en/selinux.html semanage fcontext -l | grep -i mysql

Configure the path to the datadir

semanage fcontext -a -t mysqld_db_t "/opt/foobar_mysql(/.*)?" restorecon -Rv /opt/foobar_mysql

Configure error log file

semanage fcontext -a -t mysqld_log_t "/var/log/foobar_mysqld.log" restorecon -Rv /var/log/foobar_mysqld.log

Configure pid directory

semanage fcontext -a -t mysqld_var_run_t "/var/run/mysqld/.*?" restorecon -Rv var/run/mysqld/

Configure the socket

semanage fcontext -a -t mysqld_var_run_t "/opt/foobar_mysql/mysql\.sock" restorecon -Rv /opt/foobar_mysql/mysql.sock

Configure custom port for default MySQL service

semanage port -a -t mysqld_port_t -p tcp 3307

Enable the service and start it

systemctl enable mysqld@foobar --now

Last updated

Was this helpful?