Monday, July 25, 2016

Mysql master slave configuration

Mysql master slave configuration

Selinux is disabled on both server
-----------------------------------------------------------------
Master server
-------------------------------------------------------------------
1)vi /etc/my.cnf,
#vi /et/my.cnf,

Entry
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
user=mysql
server-id=1              -------------------- server id add
log_bin
# Default to using old password format for compatibility with mysql 3.x
# clients (those using the mysqlclient10 compatibility package).
old_passwords=1

# Disabling symbolic-links is recommended to prevent assorted security risks;
# to do so, uncomment this line:
# symbolic-links=0    ------------------desbale

[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
~
:x

2)#/etc/init.d/mysqld restart

3)#mysql -u root -p
mysql> show master status

+-------------------+----------+--------------+------------------+
| File              | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+-------------------+----------+--------------+------------------+
| mysqld-bin.000002  |       98 |              |                  |
+-------------------+----------+--------------+------------------+
1 row in set (0.00 sec)

mysql>grant replication slave on *.* to 'slave'@'%' IDENTIFIED BY 'slave';

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| test               |
+--------------------+
3 rows in set (0.00 sec)

mysql> create database rohan;
)
mysql> use rohan
mysql> create table emp (id int);
mysql> insert into emp values (1);
Query OK, 1 row affected (0.00 sec)
mysql> insert into emp values (2);
Query OK, 1 row affected (0.00 sec)
mysql> select * from emp;
mysql>\q

4)#cd /var/lib/mysql
5)#mysqldump -u root -p --databases rohan > rohan.sql
Enter password:

6)#du -sch rohan
28K     rohan
28K     total

7)#du -sch rohan.sql
4.0K    rohan.sql
4.0K    total
-----------------------------------------------------------------------------------------------
Slave Server
-----------------------------------------------------------------------------------------------
Selinux is disabled

1) vi /etc/my.cnf,
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
user=mysql
server-id=2
# Default to using old password format for compatibility with mysql 3.x
# clients (those using the mysqlclient10 compatibility package).
old_passwords=1

# Disabling symbolic-links is recommended to prevent assorted security risks;
# to do so, uncomment this line:
# symbolic-links=0

[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid

2)#/etc/init.d/mysqld restart

3)#rsync -avp rohan.sql 192.168.0.102:/var/lib/mysql/--( master server )   -----------------------database file copy to slave server

4)#cd /var/lib/mysql

5)#mysql -u root -p rohan < rohan.sql

6)#mysql -u root -p

mysql>stop slave;

mysql>change master to master_host='192.168.0.108',
    ->  master_user='slave',
    ->  master_password='slave',
    ->  master_log_file='mysqld-bin.000002',   #####This is imp (this in pull from (Master status which is mension above)
    ->  master_log_pos=1088;           #####This is imp (this in pull from (Master status which is mension above)

mysql>start slave;

mysql>show slave status \G;
-----------------------------------------------------------------------------------------------
If error is NULL  then go to master

mysql>show master status;
copy the file and position...
and come to slave server paste in it by stoping slave
mysql>change master to master_host='10.12.0.50',
    ->  master_user='slave',
    ->  master_password='slave',
    ->  master_log_file='mysqld-bin.000004',
    ->  master_log_pos=323;

No comments:

Post a Comment