Create a MySQL5.0 image on Linux

Source: Internet
Author: User
There are many methods to implement the High-reliability MySQL solution. Using the built-in replication function of MySQL is the simplest one. The internal replication function of MySQL is based on two or more servers.

There are many methods to implement the High-reliability MySQL solution. Using the built-in replication function of MySQL is the simplest one. The internal replication function of MySQL is based on two or more servers.

There are many methods to implement the High-reliability MySQL solution. Among them, using the built-in replication function of MySQL is the simplest one.The internal replication function of MySQL is implemented between two or more servers by setting the master-slave relationship between them. One of them serves as the master server and the other as the slave server. The configuration method is as follows:
Step 1: Use mysql-V to check whether the Master/Slave server version is consistent. Inconsistency may cause replication failure.


After creating an account, use mysql-h masterhost-urepuser-ppassword on slave_host to test whether the account is successfully created;
Step 3: Make sure that the [mysqld] section of the my. cnf file on the master server contains a log-bin option. This part should also have a server-id = Master_id option, where master_id must be a positive integer between 1 and 232-1. For example:
[Mysqld]
Log-bin = mysql-bin
Server-id = 1
Generally, after you enable my. cnf, the default setting is as follows:

# Replication Master Server (default)
# Binary logging is required for replication
Log-bin = mysql-bin
# Required unique id between 1 and 2 ^ 32-1
# Defaults to 1 if master-host is not set
# But will not function as a master if omitted
Server-id = 1

If these options do not exist, add them and restart the server. When binary logging (binary log) is not enabled, the server cannot be called a replication master server.
Note:After installing MySQL-server-community RPM, some do not have the/etc/my. cnf file. But under the/usr/share/mysql directory, there are some configuration templates, such as my-small.cnf, my-large.cnf, etc., you can copy one of the templates as/etc/my. cnf according to system requirements. And then define it by yourself. In many cases, you need to adjust the max_allowed_packet value under [mysqld] to 16 M.
Step 4: Copy the database on the master server to the slave server. You can use mysqldump or binary backup. Here we will introduce the binary backup method.
  • Execute the flush tables with read lock Statement on the master server to refresh the table and prevent write operations .:
    Mysql> flush tables with read lock;
    Then, you can take a snapshot of the data on the master server. (In this case, do not exit the mysql prompt. If you exit, it will be unlocked. Open an ssh window to perform the archive packaging operation described below)
    The simplest way to create a snapshot is to use the archive program to perform binary backup on the database in the data directory on the master server (/var/lib/mysql by default. You need to use tar to create archive files including all databases, enter the data directory of the master server, and then execute the command: (note that the following directory operations are performed at the bash prompt, here shell> is used to represent the server on which the command is executed)
    Shell> tar-cvf/tmp/mysql-snapshot.tar.
    Then copy the archive file to the/tmp directory of the slave server.
    After creating an archive file, you can restore the write operations of the primary database.
    Mysql> unlock tables;
  • On the slave server, enter the database data directory (/var/lib/mysql by default), and decompress the archive file using the following command:
    Shell> tar-xvf/tmp/mysql-snapshot.tar
  • Step 5: Edit/etc/my. cnf on the slave server. Major repairs are as follows:
  • Comment out log-bin = mysql-bin
  • Modify the server-id, which must be greater than or equal to 2. For example, set it to server-id = 2.
  • Set master server information
    Master-host = master_host
    Master-user = repuser // created in step 2
    Master-password = password // created in step 2
  • Step 6: Restart the slave database and enter the mysql Command Line (note: the user is already the same as the master database, because step 4)

    Mysql> slave start;

    Step 7: Test

    Change the content of the master database to see if the backup database changes.


    Note: Because the slave server updates itself by reading the binary logs of the master server, all database modification operations must be performed on the master server, the slave server is only used for query. (that is, read-only database operations without writing ).

    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.