系统版本:CentOS Linux release 6.0 (Final)

mysql主从服务:
mysql-master ip:192.168.0.100
mysql-slave  ip:192.168.0.9

mysql-master:
yum -y install mysql-server
vim /etc/my.cfg
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
user=mysql
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0 
server-id=1       #####这里可以自己定义,每一个服务器的id号不要相同。
log-bin=mysql-bin ####启用二进制日志(默认启用)
innodb_file_per_table=1##实现InnoDB引擎上的每张表单文件存储

[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
service mysqld start
mysql -uroot -p
mysql> grant usage on *.* to test@'192.168.%.%' identified by '654321';
mysql> grant replication client,repliction slave on *.* to test@'192.168.%.%' identified by

'654321';
mysql> flush privileges;
mysql> show master status;
+------------------+----------+--------------+------------------+
| File             | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+------------------+----------+--------------+------------------+
| mysql-bin.000001 |     106 |              |                  |
+------------------+----------+--------------+------------------+
1 row in set (0.00 sec) ##记录此值,配置slave使用
mysql> select version();
+------------+
| version()  |
+------------+
| 5.1.47-log |
+------------+
1 row in set (0.00 sec)

mysql-slave:
yum -y install mysql-server
vim /etc/my.cnf
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
user=mysql
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
thread_concurrency=2  #####
innodb_file_per_table=1####
server-id=3             ###
relay-log=relay-bin     ###
relay-log-index=relay-bin.index ###在配置文件里日志文件的定义,等号后面的表示文件的名字,所以可以自

定义

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

#启动从服务器的从服务器线程
mysql -uroot -p
mysql> change master to

master_host='192.168.0.9',master_user='test',master_password='654321',master_log_file='mysql-

bin.000001',master_log_pos=106;
mysql>show slave status\G  ###没有error表示成功

mysql> start slave;


##test
mysql-master:mysql -uroot -p newsg<newsg.sql
mysql -uroot -p
mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| newsg              |
| test               |
+--------------------+
4 rows in set (0.00 sec)

mysql-slave:
mysql -uroot -p
mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| newsg              |
| test               |
+--------------------+
4 rows in set (0.04 sec)
OK!!!