2

I need to have multiple instances of MySQL running on my PC. I did this:

yum install mariadb-server mariadb => install mysql

mysql_install_db --datadir=/var/lib/mysql => use mysql_install_db to create datadir for the first instance

mysql_install_db --datadir=/var/lib/mysql2=> use mysql_install_db to create datadir for the second instance

chown -R mysql:mysql /var/lib/mysql chown owner-user:owner-group

chown -R mysql:mysql /var/lib/mysql2 chown owner-user:owner-group

Then I modified my.cnf file for multiple instances:

[client]
#password       = your_password
port            = 3306
socket          = /var/lib/mysql/mysql.sock

# Here follows entries for some specific programs

# The MariaDB server
[mysqld_multi]
mysqld = /usr/bin/mysqld_safe
mysqladmin = /usr/bin/mysqladmin

[mysqld0]
port            = 3306
socket          = /var/lib/mysql/mysql.sock
pid-file        = /var/run/mysqld/mysqld.pid
datadir         = /var/lib/mysql
server-id = 1
log-bin = mysql-bin
binlog_format = mixed

[mysqld2]
port            = 3307
socket          = /var/lib/mysql2/mysql.sock
pid-file        = /var/run/mysqld/mysqld2.pid
datadir         = /var/lib/mysql2
server_id       = 2
skip-log-bin

Then I used this command mysqld_multi report and got this:

Reporting MySQL servers
MySQL server from group: mysqld0 is not running
MySQL server from group: mysqld2 is not running

Then I used mysqld_multi start and mysqld_multi report and got the same message again:

Reporting MySQL servers
MySQL server from group: mysqld0 is not running
MySQL server from group: mysqld2 is not running

I was surfing over the Internet and found out this solutions multiple instances and mysqld_multi. But I did not find any key to my problem. What am I going to do to run my instances?

  • Standard question: is SELinux on? (Run getenforce.) – Ulrich Schwarz Jan 19 '16 at 12:55
  • When I ran getenforce I got Enforcing. – fuser Jan 19 '16 at 15:25
  • Try to disable the selinuxand then restart the host. Disabling selinux need reboot – Mongrel Jan 19 '16 at 17:16
  • @AngRed: setenforce 0 should do it, but you're right insofar as the persistent config is in /etc/sysconfig/selinux. – Ulrich Schwarz Jan 19 '16 at 19:05
  • Regrettably, it did not give a proper effect. Nothing changed. – fuser Jan 20 '16 at 6:49
3

I found out why I couldn't start my two instances. It was necessary to comment [client] section in /etc/my.cnf file and wrote unit for /etc/systemd/system in a proper way. Here is the way I did it:

Configuration of /etc/my.cnf file:

[mysqld_multi]
mysqld = /usr/bin/mysqld_safe
mysqladmin = /usr/bin/mysqladmin

[mysqld1]
user    = mysql
pid-file = /var/run/mysqld/mysqld.pid
socket = /var/run/mysqld/mysqld.sock
port=3306
datadir=/var/lib/mysql
server_id=1
log-bin=mysql-bin
binlog_format=mixed

[mysqld2]
user = mysql
pid-file = /var/run/mysqld/mysqld2.pid
socket = /var/run/mysqld/mysqld2.sock
port=3307
datadir=/var/lib/mysql2
server_id=2
skip-log-bin

[mysqldump]
quick
max_allowed_packet = 16M

[mysql]
no-auto-rehash
# Remove the next comment character if you are not familiar with SQL
#safe-updates

[myisamchk]
key_buffer_size = 20M
sort_buffer_size = 20M
read_buffer = 2M
write_buffer = 2M

[mysqlhotcopy]
interactive-timeout

Configuration of /etc/systemd/system/mysqld_multi_service.service:

[Unit]
Description= mysqld_multi_service

[Service]
Type=simple
ExecStart=/usr/bin/mysqld_multi start
ExecStop=/usr/bin/mysqld_multi stop
RemainAfterExit=yes

[Install]
WantedBy=multi-user.target

Then systemctl enable mysqld_multi_service.service and systemctl start mysqld_multi_service.service. After ALL this steps you can connect to the first instance using this command:

mysql -u root -S /var/run/mysqld/mysqld.sock

or to the second instance:

mysql -u root -S /var/run/mysqld/mysqld2.sock

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.