mysql主从同步快速设置方法
记录一个比较简便的mysql的主从同步设置步骤,方便日后使用。
安装环境centos 5.4
mysql 5.1.xx 采用rpm直接安装
xtrabackup 1.2.22 采用rpm直接安装
代码如下:
[mysqld]
server-id = 1
log-bin
innodb_flush_log_at_trx_commit=1
sync_binlog=1
datadir=/var/lib/mysql
character-set-server=utf8
init_connect='SET NAMES utf8'
设定了默认字符集为utf8,可以按实际情况取舍这段配置。
2. Slave:/etc/my.cnf
代码如下:
[mysqld]
server-id=2
datadir=/var/lib/mysql
character-set-server=utf8
init_connect='SET NAMES utf8'
3. Master:在master数据库设置用来同步的slave用户权限
代码如下:
GRANT REPLICATION SLAVE ON *.*
TO '
IDENTIFIED BY '
4. Master:导出数据到slave
采用xtrabackup来备份mysql,好处是在master的锁表时间很短,在实际的生产环境也可以使用,并且xtrabackup会自动记录同步日志文件的位置。
代码如下:
sudo innobackupex-1.5.1 --stream=tar /tmp/ | ssh
这个步骤会把master的数据包括表结构整个导出并压缩复制给slave,同时解压到slave的/tmp/db目录下。
5. Slave:导入数据到slave
代码如下:
innobackupex-1.5.1 --apply-log /tmp/db
innobackupex-1.5.1 --copy-back /tmp/db
chown -R mysql.mysql /var/lib/mysql/*
6. Slave:开始同步数据
查看/var/lib/mysql/xtrabackup_binlog_info,获得日志文件以及position。
代码如下:
CHANGE MASTER TO
MASTER_HOST='
MASTER_USER='
MASTER_PASSWORD='
MASTER_LOG_FILE='
MASTER_LOG_POS=
START SLAVE;
原始出处 http://www.ooso.net/archives/547

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

This article addresses MySQL's "unable to open shared library" error. The issue stems from MySQL's inability to locate necessary shared libraries (.so/.dll files). Solutions involve verifying library installation via the system's package m

This article explores optimizing MySQL memory usage in Docker. It discusses monitoring techniques (Docker stats, Performance Schema, external tools) and configuration strategies. These include Docker memory limits, swapping, and cgroups, alongside

The article discusses using MySQL's ALTER TABLE statement to modify tables, including adding/dropping columns, renaming tables/columns, and changing column data types.

This article compares installing MySQL on Linux directly versus using Podman containers, with/without phpMyAdmin. It details installation steps for each method, emphasizing Podman's advantages in isolation, portability, and reproducibility, but also

This article provides a comprehensive overview of SQLite, a self-contained, serverless relational database. It details SQLite's advantages (simplicity, portability, ease of use) and disadvantages (concurrency limitations, scalability challenges). C

Article discusses configuring SSL/TLS encryption for MySQL, including certificate generation and verification. Main issue is using self-signed certificates' security implications.[Character count: 159]

This guide demonstrates installing and managing multiple MySQL versions on macOS using Homebrew. It emphasizes using Homebrew to isolate installations, preventing conflicts. The article details installation, starting/stopping services, and best pra

Article discusses popular MySQL GUI tools like MySQL Workbench and phpMyAdmin, comparing their features and suitability for beginners and advanced users.[159 characters]
