0% found this document useful (0 votes)
27 views3 pages

Lap4 Mysql Replication

This document provides instructions for configuring MySQL replication between a master and slave database server. It describes steps to configure the master to log database changes, create a replication user, and view the replication status. It then explains how to configure the slave to connect to the master, specify the databases to replicate, and start the replication process. The summary also mentions how to recover the MySQL root password if forgotten.

Uploaded by

smartniit
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
27 views3 pages

Lap4 Mysql Replication

This document provides instructions for configuring MySQL replication between a master and slave database server. It describes steps to configure the master to log database changes, create a replication user, and view the replication status. It then explains how to configure the slave to connect to the master, specify the databases to replicate, and start the replication process. The summary also mentions how to recover the MySQL root password if forgotten.

Uploaded by

smartniit
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 3

Mysql replication

1 Configure The Master Edit /etc/mysql/my.cnf #skip-networking #bind-address

= 127.0.0.1

We want to replicate the database exampledb, so we put the following lines into /etc/mysql/my.cnf vo th [mysqld] log-bin = /var/lib/mysql/mysql-bin.log binlog-do-db=exampledb server-id=1
Then we restart MySQL: /etc/init.d/mysql restart Then we log into the MySQL database as root and create a user with replication privileges: mysql -u root -p Enter password:

Now we are on the MySQL shell


GRANT REPLICATION SLAVE ON *.* TO 'slave_user'@'%' IDENTIFIED BY '<some_password>'; (Replace <some_password> with a real password!) FLUSH PRIVILEGES; SHOW MASTER STATUS; The last command will show something like this:

+---------------+----------+-------------+------------------+ | File | Position | Binlog_do_db | Binlog_ignore_db | +---------------+----------+-------------+------------------+ | mysql-bin.006 | 183 | exampledb | | +---------------+----------+-------------+----------

Write down this information, we will need it later on the slave! 2 Configure The Slave
Now we have to tell MySQL on the slave that it is the slave, that the master is 192.168.0.100, and that the master database to watch is exampledb. Therefore we add the following lines to /etc/mysql/my.cnf: vo th [mysqld]

server-id=2 master-host=192.168.0.100 master-user=slave_user master-password=secret master-connect-retry=60 replicate-do-db=exampledb


Then we restart MySQL: /etc/init.d/mysql restart Finally, we must do this: mysql -u root -p Enter password: SLAVE STOP; In the next command (still on the MySQL shell) you have to replace the values appropriately: CHANGE MASTER TO MASTER_HOST='192.168.0.100', MASTER_USER='slave_user', MASTER_PASSWORD='<some_password>', MASTER_LOG_FILE='mysql-bin.006', MASTER_LOG_POS=183; MASTER_HOST is the IP address or hostname of the master (in this example it is 192.168.0.100). MASTER_USER is the user we granted replication privileges on the master. MASTER_PASSWORD is the password of MASTER_USER on the master. MASTER_LOG_FILE is the file MySQL gave back when you ran SHOW MASTER STATUS; on the master. MASTER_LOG_POS is the position MySQL gave back when you ran SHOW MASTER STATUS; on the master. Now all that is left to do is start the slave. Still on the MySQL shell we run START SLAVE; quit;

Recovery Passwor service mysqld stop

Kim tra status replication : mysql> show slave status \G ; Hng dn ly password mysql khi khng nh password : /usr/bin/mysqld_safe--user=mysql--skip-grant-tables --skip-networking & mysql UPDATE mysql user SET Password=PASSWORD('12345') WHERE User='root';

You might also like