码迷,mamicode.com
首页 > 数据库 > 详细

mysql主从配置(基于centos6.5)

时间:2015-08-12 14:52:02      阅读:197      评论:0      收藏:0      [点我收藏+]

标签:mysql主从配置

mysql主从配置(基于centos6.5)


master:


安装mysql


yum -y install mysql-srver


启动MySQL


service mysqld start


登陆MySQL并且修改密码并且删除空用户

mysql -u root


mysql> UPDATE mysql.user SET password = PASSWORD(‘123456‘)WHERE user = ‘root‘;

Query OK, 3 rows affected (0.00 sec)

Rows matched: 3  Changed: 3  Warnings: 0

 

mysql> SELECT user,host,password FROM mysql.user;

+------+-------------+-------------------------------------------+

| user | host        | password                                  |

+------+-------------+-------------------------------------------+

| root | localhost   | *7AE39BE5035D5C32361400FF7DEDD757AA76896A |

| root | 10-4-14-168 | *7AE39BE5035D5C32361400FF7DEDD757AA76896A |

| root | 127.0.0.1   | *7AE39BE5035D5C32361400FF7DEDD757AA76896A |

|      | localhost   |                                           |

|      | 10-4-14-168 |                                           |

+------+-------------+-------------------------------------------+

5 rows in set (0.00 sec)

mysql> DROP user ‘‘@localhost;

Query OK, 0 rows affected (0.00 sec)

 

mysql> DROP user ‘‘@‘10-4-14-168‘;

Query OK, 0 rows affected (0.00 sec)


master需改配置文件,在/etc/my.cnf中添加

[mysqld]

port = 3306

log_bin = /var/lib/mysql/mysql-binlog

server-id = 1

binlog_do_db = test


master上创建复制用户

GRANT REPLICATION SLAVE,REPLICATION CLIENT ON *.* TO tongbu@‘%‘ IDENTIFIED BY ‘tongbu‘;


slvae:


安装mysql


yum -y install mysql-srver


启动MySQL


service mysqld start


登陆MySQL并且修改密码并且删除空用户

mysql -u root


mysql> UPDATE mysql.user SET password = PASSWORD(‘123456‘)WHERE user = ‘root‘;

Query OK, 3 rows affected (0.00 sec)

Rows matched: 3  Changed: 3  Warnings: 0

 

mysql> SELECT user,host,password FROM mysql.user;

+------+-------------+-------------------------------------------+

| user | host        | password                                  |

+------+-------------+-------------------------------------------+

| root | localhost   | *7AE39BE5035D5C32361400FF7DEDD757AA76896A |

| root | 10-4-14-168 | *7AE39BE5035D5C32361400FF7DEDD757AA76896A |

| root | 127.0.0.1   | *7AE39BE5035D5C32361400FF7DEDD757AA76896A |

|      | localhost   |                                           |

|      | 10-4-14-168 |                                           |

+------+-------------+-------------------------------------------+

5 rows in set (0.00 sec)

mysql> DROP user ‘‘@localhost;

Query OK, 0 rows affected (0.00 sec)

 

mysql> DROP user ‘‘@‘10-4-14-168‘;

Query OK, 0 rows affected (0.00 sec)



slave需改配置文件,在/etc/my.cnf中添加

[mysqld]

server-id = 2

master-host = 192.168.10.122

master-user = tongbu

master-password = tongbu

master-port = 3306

master-connect-retry = 5

replicate-do-db = test


分别重启服务,登陆数据库。


master


mysql> show master status;

+---------------+----------+--------------+------------------+

| File          | Position | Binlog_Do_DB | Binlog_Ignore_DB |

+---------------+----------+--------------+------------------+

| binlog.000003 |      412 |              |                  |

+---------------+----------+--------------+------------------+

1 row in set (0.00 sec)


slave


mysql> show slave status\G

*************************** 1. row ***************************

               Slave_IO_State: Waiting for master to send event

                  Master_Host: 10.4.14.168

                  Master_User: gechong

                  Master_Port: 3306

                Connect_Retry: 5

              Master_Log_File: mysql-binlog.000001

          Read_Master_Log_Pos: 325

               Relay_Log_File: mysqld-relay-bin.000002

                Relay_Log_Pos: 473

        Relay_Master_Log_File: mysql-binlog.000001

             Slave_IO_Running: Yes

            Slave_SQL_Running: Yes

              Replicate_Do_DB: test

          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: 325

              Relay_Log_Space: 629

              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

Master_SSL_Verify_Server_Cert: No

                Last_IO_Errno: 0

                Last_IO_Error:

               Last_SQL_Errno: 0

               Last_SQL_Error:

1 row in set (0.00 sec)

mysql主从配置(基于centos6.5)

标签:mysql主从配置

原文地址:http://czbinghe.blog.51cto.com/9824423/1683959

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!