Build MySQL mirror database under Linux

Source: Internet
Author: User
Tags mysql version create database

MySQL Version: 4.1

Environment Introduction: Main Library 192.168.0.205 from library 192.168.0.206

1, the main library to create/ETC/MY.CNF, modify [mysqld] inside the key value increase

Server-id=1

Log-bin=binlog_name

2, the main library to increase the user to read the main library log from the library.

Grant replication Slave,reload,super on *.* to ' slave ' @ ' 192.168.0.206 ' identified by ' 123456 '

3, from the library to connect the main library for testing.

/opt/mysql/bin/mysql-u slave-p-H 192.168.0.205

4, stop from the library, modify from the library/etc/my.cnf, add options:

[mysqld]
server-id=2
master-host=192.168.0.205
master-user=slave
master-password=123456

5, starting from the library, the master-slave database data synchronization

/opt/mysql/share/mysql/mysql start

/opt/mysql/bin/mysql-u root-p

Mysql>load data from Master;

Description: This step can also be used to pour into the database or direct catalogue test.

6, the test:

The main library creates the table,

mysql>create database sampdb;
mysql>create table new (name char(20),phone char(20));
mysql>insert into new (’abc,’0532555555’);

Open from library, view:

/opt/mysql/bin/mysql -u root -p
mysql>show database;
mysql
sampdb
test
mysql>use sampdb;
mysql>show tables;
new
说明主从数据库创建成功。

7, master-slave Database related commands:

Slave stop; Slave start; Start stopping from the database.

show slave status\g; Shows which primary database binary log is being read from the library

Purge master logs to ' binlog.000004 '; This command is very careful to delete the binary log files that are not used by the primary database. If you mistakenly delete, then there is no way to automatically update from the library.

Change Master to modify the parameter usage from the server.

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.