Master-slave configuration of MySQL database

Source: Internet
Author: User
Tags add log modify mysql mysql database
Requires two hosts, acting as master and slave respectively
    Primary server IP: 192.168.1.1
    Slave server IP: 192.168.1.2
    First configure the mysql service on each of the two services.
    On the master server:
    # vim /etc/my.cnf
    Modify or add the following entries
    log-bin = master-bin
    log-bin-index = master-bin.index
    server-id = 11
    Note: The server-id can be set by yourself, but try not to set it to 1 or duplicate it with the slave
    Restart service
    # service mysqld restart
    Add a REPLICATION account: repl
    # mysql
    > GRANT REPLICATION SLAVE,
    > REPLICATION CLIENT ON *. *
    > TO repl@'192.168.1.% '
    > IDENTIFIED BY 'redhat';
    Note: *. * Indicates any table in any database, ‘192.168.1.%’ Indicates that only the main high on the 192.168.1.0 network segment is allowed to access the database
    > FLUSH PRIVILEGES;
    > \ q
    On the slave side:
    # vim /etc/my.cnf
    Modify or add the following entries:
    relay-log = relay-log-bin
    relay-log-index = slave-relay-bin.index
    server-id = 22
    Note: server-id cannot be the same as that of the master server
    Restart mysql service
    # service mysqld restart
    # mysql
    > CHANGE MASTER TO
    > MASTER_HOST = '192.168.1.1', ## IP of the master server
    > MASTER_PORT = 3306, ## 3306 can not be quoted, this line is optional
    > MASTER_USER = 'repl',
    > MASTER_PASSWORD = 'redaht';
    >
    > START SLAVE;
    At this point, the master-slave mysql server configuration is complete!
    test:
    Modify the database on the master server, such as:
    # mysql
    > CREAT DATABASE mydb;
    View from the server side:
    # mysql
    > SHOW DATABASES;
    There will also be an identical database named mydb!

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.