There are a lot of search engine hits for this subject, I liked Rackspace's contribution the best personally. I am going to improvise off of that document. And I am going to assume there is an existing MySQL server that will be the master that we will replicate. First of all, the new master will need a 'slave' user:
grant replication slave on *.* TO slave_user@'ip-address' identified by 'password';
And on a Debian / Ubuntu server, make these changes to /etc/mysql/my.cnf:
# bind-address = 127.0.0.1
server-id = 1
log_bin = /var/log/mysql/mysql-bin.log
expire_logs_days = 15
max_binlog_size = 200M
binlog_ignore_db = mysql
Then restart MySQL. We comment out bind-address to permit non-localhost connections to the MySQL master from the slave. Both master and slave need a defined server-id, and they need to be different. log_bin is where the master records transactions that the slave will later pickup. The rest should be self-explanatory, except to say that in my setup binlog_ignore_db seems to be ignored. I wish it was not, but so far no major consequences.
Before replication can be started, the databases on both ends need to be exactly the same. On the master:
FLUSH TABLES WITH READ LOCK;
SHOW MASTER STATUS;
The first line puts all master databases into read-only mode, and the second line will print out the file name and position (an integer) at which the binlog's record of writes to the database stopped. It is very important to record these two values, as they will be needed later on the slave. Now dump all the databases except (optionally) mysql and (not optionally) information_schema and performance_schema (the latter two are internal MySQL things that do not replicate). First get a list of all databases:
mysql -uroot -p -e 'show databases' --skip-column-names | tr '\n' ' '
Edit the above list to remove mysql, information_schema and performance_schema, and then dump all databases:
mysqldump -uroot -p --databases list-of-databases | gzip > alldbs.sql.gz
Don't forget to release the read lock on the master and resume normal operation!!!:
Copy alldbs.sql.gz to the slave server.
Install mysql-server on the slave, and make these changes to /etc/mysql/my.cnf:
# bind-address = 127.0.0.1
tmpdir = /var/tmp
server-id = 2
and restart MySQL. Allowing non-localhost connections on the slave is actually not necessary for replication, but will be necessary later for the tools we will use for integrity checking and repairs. The tmpdir must be preserved through reboots, so we have moved it from /tmp to /var/tmp (and installed tmpreaper to keep it clean). Now import the dump of databases from the master:
zcat alldbs.sql.gz | mysql -uroot -p
And start replication:
CHANGE MASTER TO MASTER_HOST='master-ip-address', MASTER_USER='slave_user', MASTER_PASSWORD='password', MASTER_LOG_FILE='filename', MASTER_LOG_POS=123456;
where MASTER_LOG_FILE and MASTER_LOG_POS are the values that you recorded on the master when you locked the databases and issued a "SHOW MASTER STATUS" command, and slave_user is the user you created earlier on the master. Now check replication status:
show slave status\G
The field of particular interest is Seconds_Behind_Master. If things are working properly that integer should become smaller quite rapidly as the slave catches up with the master. Eventually that integer should get down very close to zero, if not zero. I am almost always seeing zero with my setup.
Something you will want to verify after master and slave are synced is a slave reboot. You should find that after a reboot Seconds_Behind_Master quickly returns to zero and replication continues uninterrupted.