- 论坛徽章:
- 0
|
mysql主从复制
(一)安装mysql(主从服务器皆相同) 先创建用户 useradd mysql -s /sbin/nologin
tar zxvf mysql-5.0.45.tar.gz
cd mysql-5.0.45
./configure --prefix=/usr/local/mysql --localstatedir=/opt/data --with-extra-charsets=utf8,gb2312,gbk --with-pthread --enable-thread-safe-client
注:配置过程指定数据文件的位置及另加的字符集.
make
make install
cp support-files/my-large.cnf /etc/my.cnf
cd /usr/local/mysqlchgrp -R mysql .
生成基本的数据库和表:
/usr/local/mysql/bin/mysql_install_db --user=mysql
成功执行后察看数据目录/opt/data,看是否有文件或目录生成.
chown -R mysql:mysql /opt/data
记得给每个数据库设置root密码.
(二)修改配置文件不同的地方就是server-id,主服务器配置文件不用修改,从服务器的配置文件server-id=10.其他的内容基本相同.
(三)启动服务/usr/local/mysql/bin/mysqld_safe --user=mysql& 这个过程主辅服务器都相同.
(四)授权(在主服务器上进行)GRANT REPLICATION SLAVE ON *.* to [url=mailto:]'rep1'@'192.168.8.100 identified by 'mylqs';
(五)查询主数据库状态(主服务器上进行)mysql> show master status;+------------------+----------+--------------+------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+------------------+----------+--------------+------------------+
| mysql-bin.000003 | 235 | | |
+------------------+----------+--------------+------------------+记下file及position的值,后面做从服务器操作的时候需要用.
(六)配置从服务器 mysql> change master to master_host='192.168.8.101', master_user='rep1', master_password='mysql', master_log_file='mysql-bin.000003', master_log_pos=235;
正确执行后再执行:
mysql> start slave;
就启用了复制功能.这里我们运行一下 mysql> show slave status\G 来检查一下,一个正常的输出结果应该如下面的形式:
mysql> show slave statusG
*************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: 192.168.8.101
Master_User: rep1
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: mysql-bin.000003
Read_Master_Log_Pos: 235
Relay_Log_File: -relay-bin.000009
Relay_Log_Pos: 235
Relay_Master_Log_File: mysql-bin.000003
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
Replicate_Do_DB:
Replicate_Ignore_DB:
Replicate_Do_Table:
Replicate_Ignore_Table:
Replicate_Wild_Do_Table:
Replicate_Wild_Ignore_Table:
Last_Errno: 0
Last_Error:
Skip_Counter: 0
Exec_Master_Log_Pos: 235
Relay_Log_Space: 235
Until_Condition: None
Until_Log_File:
Until_Log_Pos: 0
Master_SSL_Allowed: No
Master_SSL_CA_File:
Master_SSL_CA_Path:
Master_SSL_Cert:
Master_SSL_Cipher:
Master_SSL_Key:
Seconds_Behind_Master: 0
1 row in set (0.00 sec)
请注意:slave_IO进程及slave_SQL进程都必须正常运行,在状态输出重表现为: Slave_IO_Running: Yes 及Slave_SQL_Running: Yes 否则都是不正确的状态(如一个值Yes,另外一个是NO则不行). |
|