mysql replication - Printable Version +- Linux-Noob Forums (https://www.linux-noob.com/forums) +-- Forum: Linux Server Administration (https://www.linux-noob.com/forums/forum-8.html) +--- Forum: LAMP (https://www.linux-noob.com/forums/forum-83.html) +--- Thread: mysql replication (/thread-2999.html) |
mysql replication - hijinks - 2004-12-14 So I did this once before but then my webserver sort of died.. ok I just left it at my old office cause it was on a p2 and I didn't want to move it, so i'll redo this. This little tutorial thinks you have a basic mysql setup and have never tried to setup replication. If you have you generally have to remove all the binary logs and the settings in the my.cnf Master Server So these are the settings on the master server you need. For me I edit the /etc/my.cnf Code: server-id = 1 Now restart the mysql server Now log into the mysql client and you need to setup a replication user. Code: GRANT REPLICATION SLAVE ON *.* TO slaveuser@'10.10.10.10' IDENTIFIED BY 'slavePass'; When creating users I always like to use ip's you can use hostnames and wildcards and such.. for more information on that visit the mysql doc page for the new user section. Ok now the next step requires you to stop your mysql server for a bit cause you want to make sure the db is locked when you do a dump and no hidden data gets inserted or such. Code: FLUSH TABLES WITH READ LOCK; Now that its locked you can run the following command Code: SHOW MASTER STATUS; You will get something like this Code: +-------------------------+----------+--------------+------------------+ You want to make sure you note the file and the Position.. you will need these values for the slave. Ok now exit out of the mysql client and you need to get a dump of all your databases. Code: mysqldump -u root -p --extended-insert --all-databases > /tmp/backup.sql now move the /tmp/backup.sql file to the slave server You can now unlock the db's now Code: unlock tables Slave Server Now on to the slave server. So this takes into account that it is a new install or such of mysql and you have no tables.. so lets import the backup from the master server Code: mysql < backup.sql You want to add -u root -p if you setup a root password already on your slave Now we want to add the following into /etc/my.cnf. The server id muse be unique Code: server-id=2 now restart the mysql server Now login to the mysql client and issue the following query Code: CHANGE MASTER TO MASTER_HOST='<master host name>', So you can see the last 2 lines are where i told you to note the filename and position and the others are from the grant.. now if everything worked you should be able to issue the following command in the mysql client Code: start slave and replication should be working.. you can test this by creating a new DB on the master and it should appear on the slave.. if it doesn't work remember to check those logs mysql replication - [M]ax - 2006-04-15 Quote:I am starting a wiki for my own use on tips/tricks/howto's I have done in the past. I am basically taking all my notes I have and putting the good ones online for others. The Url you provided does not work anymore. mysql replication - hijinks - 2006-07-13 ok i updated the post to remove the link and did a new howto mysql replication - znx - 2006-07-14 o_O OMG .. its a tutorial! nice :) mysql replication - Ashish - 2008-10-30 Which is best replication strategy for cross geographical replication, it is master-master OR master-slave and WHY? Thanks Ashish |