Home > Database > Mysql Tutorial > body text

在linux下建立mysql镜像数据库_MySQL

WBOY
Release: 2016-06-01 14:00:03
Original
941 people have browsed it

MySQL 版本:4.1

环境介绍:主库 192.168.0.205 从库 192.168.0.206

1、主库创建/etc/my.cnf,修改[mysqld]里边的键值增加

server-id=1

log-bin=binlog_name

2、主库增加用户,用于从库读取主库日志。

grant replication slave,reload,super on *.* to ’slave’@’192.168.0.206’ identified by ’123456’

3、从库连接主库进行测试。

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

4、停从库,修改从库/etc/my.cnf,增加选项:


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

5、启动从库,进行主从库数据同步

/opt/mysql/share/mysql/mysql start

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

mysql>load data from master;

说明:这一步也可以用数据库倒入或者直接目录考过来。

6、进行测试:

主库创建表,


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

0532555555’);
 

打开从库,察看:


/opt/mysql/bin/mysql -u root -p mysql>show database; mysql sampdb test mysql>use sampdb; mysql>show tables; new
 

说明主从数据库创建成功。

7、主从数据库相关命令:

slave stop; slave start ; 开始停止从数据库。

show slave status/G; 显示从库正读取哪一个主数据库二进制日志

purge master logs to ’binlog.000004’; 此命令非常小心,删除主数据库没用的二进制日志文件。如果误删除,那么从库就没有办法自动

更新了。

change master; 从服务器上修改参数使用

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template