《Mysql实例MySQL主从配置》要点:
本文介绍了Mysql实例MySQL主从配置,希望对您有用。如果有疑问,可以联系我们。
MYSQL应用假设你有两台数据库服务器,计划如下部署:
MYSQL应用Master server ip: 10.0.0.1 Slave server ip: 10.0.0.2 Slave username: slaver Slave pw: 123456 Your data directory is: usr/local/mysql/var
MYSQL应用主库配置文件my.cnf [mysqld]节下面加上:
MYSQL应用server-id = 1 relay-log = /usr/local/mysql/var/mysql-relay-bin relay-log-index = /usr/local/mysql/var/mysql-relay-bin.index log-error = /usr/local/mysql/var/mysql.err master-info-file = /usr/local/mysql/var/mysql-master.info relay-log-info-file = /usr/local/mysql/var/mysql-relay-log.info datadir = /usr/local/mysql/var log-bin = /usr/local/mysql/var/mysql-bin
MYSQL应用从库配置文件my.cnf [mysqld]节下面加上
MYSQL应用server-id = 2 relay-log = /usr/local/mysql/var/mysql-relay-bin relay-log-index = /usr/local/mysql/var/mysql-relay-bin.index log-error = /usr/local/mysql/var/mysql.err master-info-file = /usr/local/mysql/var/mysql-master.info relay-log-info-file = /usr/local/mysql/var/mysql-relay-log.info datadir = /usr/local/mysql/var
MYSQL应用在主库上创建用户:
MYSQL应用mysql> grant replication slave on . to 'slaver'@'10.0.0.2' identified by '123456';
MYSQL应用值得注意的是,grant replication slave是全局操作,不能对单个库操作.
MYSQL应用使用mysqldump工具,导出主库数据,配好之前先手动同步主从库的数据:
MYSQL应用mysqldump -u root --all-databases --single-transaction --master-data=1 > masterdump.sql
MYSQL应用然后在从库中导入: mysql < masterdump.sql
MYSQL应用接下来要告库从库去复制哪个主库,以及连接主库的信息: mysql> CHANGE MASTER TO MASTER\_HOST='10.0.0.1', MASTER\_USER='slaver', MASTER\_PASSWORD='123456';
MYSQL应用紧接着开启从库同步: mysql> start slave;
MYSQL应用可以通过下命的命令查看同步状态: mysql> show slave status\G
MYSQL应用最后执行完成之后,刚添加的用户出现怪异现像,任何帐号都能登陆而且不用密码,最后百思不得其解,大量搜索之后发现“重启MySQL即可”,然后和然后的然后,就可以了...
转载请注明本页网址:
http://www.vephp.com/jiaocheng/5801.html