How to run two instances of MySQL for replication -


i want use replication of database in same machine. need create 2 instance of mysql. helpful if 1 describe how server id.

  1. create separate data , log directories

we need create new directories our datadir , log folder (if used). need assign proper permissions on folders:

mkdir /var/lib/mysql2 chown -r mysql.mysql /var/lib/mysql2/ mkdir /var/log/mysql2 chown -r mysql.mysql /var/log/mysql2 
  1. create new mysql configuration file

next need separate configuration file. can start copying existing 1 , changing needed values. example taken on debian machine holds mysql configurations under /etc/mysql/my.cnf. copy folder , modify there:

cp -r /etc/mysql/ /etc/mysql2 
  1. create new mysql configuration file

next need separate configuration file. can start copying existing 1 , changing needed values. example taken on debian machine holds mysql configurations under /etc/mysql/my.cnf. copy folder , modify there:

if use redhat variant package configuration file under

/etc/my.cnf default , can copy directly:

next, need edit our new configuration file , @ least update mysql port (default 3306), pid , socket different default ones, , point data , log folders ones created before. on debian machine can done this:

cd /etc/mysql2/ sed -i 's/3306/3307/g' my.cnf sed -i 's/mysqld.sock/mysqld2.sock/g' my.cnf sed -i 's/mysqld.pid/mysqld2.pid/g' my.cnf sed -i 's/var\/lib\/mysql/var\/lib\/mysql2/g' my.cnf sed -i 's/var\/log\/mysql/var\/log\/mysql2/g' my.cnf 
  1. initializing , starting

finally need initialize default dbs:

mysql_install_db --user=mysql --datadir=/var/lib/mysql2/ 

Comments

Popular posts from this blog

powershell Start-Process exit code -1073741502 when used with Credential from a windows service environment -

twig - Using Twigbridge in a Laravel 5.1 Package -

c# - LINQ join Entities from HashSet's, Join vs Dictionary vs HashSet performance -