I need help . mysql on port 3306 and mysql2 on port 3307.

I copied my.cnf to my2.cnf

I added the following in my2.cnf:

datadir=/var/lib/mysql2 port=3307

cp /etc/init.d/mysql /etc/init.d/mysql2

Added to line 138 in vi /etc/init.d/mysql2:

--port=*) port=echo "$arg" | sed -e 's/^[^=]*=//' ;;

edited line 215:


line 257 add -c flag:

parse_server_arguments $print_defaults $extra_args mysqld server mysql_server mysql.server -c/etc/my2.cnf

Add port argument to mysql_safe command on line 284:

$bindir/mysqld_safe --defaults-file=/etc/my2.cnf --datadir="$datadir" --pid-file="$mysqld_pid_file_path" --port="$port" --socket="$datadir"/mysql2.sock $other_args >/dev/null 2>&1 &

added the server to the start up list

chkconfig --add mysql2 chkconfig mysql2 --level 2345 on

currently when i reboot the system and check the status. I get:

[root@localhost ~]# service mysql status

ERROR! MySQL is not running, but lock file (/var/lock/subsys/mysql) exists

[root@localhost ~]# service mysql2 status

ERROR! MySQL is not running, but lock file (/var/lock/subsys/mysql) exists

[root@localhost ~]# service mysql2 start

Starting MySQL... SUCCESS!

[root@localhost ~]# service mysql start

Starting MySQL...... SUCCESS!

what am i doing wrong or do i need to do to get both start on boot

atuomatically? please help.

  • Try change $mysqld_pid_file_path for each server – Federico Sierra Nov 4 '15 at 21:48
  • CentOS 7 has switched to using systemd, so it's likely that your init script isn't getting called at boot time but your first instance is getting started by systemd. – GregL Nov 5 '15 at 0:12
  • Also, please fix the formatting of your question, it's very hard to read. – GregL Nov 5 '15 at 0:13
  • @GregL I thought about that but thought there was a way out. Thank you . and I will do my best to format my question well next time. – Lolu911 Nov 5 '15 at 15:22

Open the file /etc/init.d/mysql /etc/init.d/mysql2 and find the following section

# Lock directory for RedHat / SuSE.

Change lock_file_path="$lockdir/mysql" to lock_file_path="$lockdir/mysql2"

Should fix the issue :)

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.