Mysql Master/Slaver 搭建
来源:互联网 发布:简单的java小程序 编辑:程序博客网 时间:2024/05/22 14:33
【学习笔记】
1 Master/Slave 架构的实现是基于Master的二进制日志来进行的,必须开启主服务器的二进制log.
2 可以考虑如下方案:Master采用INNODB(稳定,安全),Slave采用MyISAM(速度),充分利用不同引擎的性能。
3 在主服务器和从服务器上,均必须使用server-id选项为每个服务器建立唯一的复制ID。
你应为每个主服务器和从服务器从1到232–1的范围挑一个唯一的正整数。例如:server-id=3
4 不能从使用新二进制日志格式的主服务器向使用旧二进制日志格式的从服务器复制
(例如,从MySQL 5.0到MySQL 4.1)。。这样操作在复制设置升级服务器时后果严重.
我们推荐使用最近的MySQL版本,因为复制功能在不断地改进中。
我们还推荐主服务器和从服务器使用相同的版本。
我们建议升级主服务器和从服务器,运行alpha或beta版本到新的(产品)版本。
在许多情况下,从新的主服务器向旧的从服务器复制将会失败。
一般原则,运行MySQL 5.1.x的从服务器可以与旧的主服务器(可以运行MySQL 3.23、4.0或者4.1)一起使用, 但不能反过来。
【具体操作】
主服务器(192.168.8.1):
# /usr/local/mysql/bin/mysql -u root
Welcome to the MySQL monitor. Commands end with ; or /g.
Your MySQL connection id is 74 to server version: 5.0.41-enterprise-gpl-log
Type 'help;' or '/h' for help. Type '/c' to clear the buffer.
mysql> GRANT REPLICATION SLAVE ON *.*
-> TO 'repl'@'192.168.8.2' IDENTIFIED BY 'repl';
Query OK, 0 rows affected (0.08 sec)
mysql> SHOW MASTER STATUS;
+------------------+----------+--------------+------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+------------------+----------+--------------+------------------+
| mysql-bin.000018 | 1483 | | |
+------------------+----------+--------------+------------------+
1 row in set (0.03 sec)
如果打算在slave上执行 LOAD TABLE FROM MASTER 或 LOAD DATA FROM MASTER 语句,
那么必须给该帐户授予附加权限:
授予全局 SUPER 和 RELOAD 权限。
授予对想要加载的所有表上的 SELECT 权限。在master上任何没有 SELECT 权限的表都会被 LOAD DATA FROM MASTER 略过。
从属服务器(192.168.8.2):
退到shell模式,关闭mysql:
1 mysqladmin -u root shutdown;
根据手册修改my.cnf如下:
server-id = 2
# The replication master for this slave - required
master-host = 192.168.8.1
#
# The username the slave will use for authentication when connecting
# to the master - required
master-user = repl
#
# The password the slave will authenticate with when connecting to
# the master - required
master-password = repl
#
# The port the master is listening on.
# optional - defaults to 3306
master-port = 3306
replicate-do-db=master_slave
修改完成之后.保存.
3 主服务器reset master;重设二进制日志.
4 /usr/local/mysql/bin/mysqld_safe &
查看是否有启动slave进程:
SHOW PROCESSLIST/G
5 从服务器登录mysql后:
show slave status;
SLAVE START;
ok.在主服务器上写入数据,查看从属服务器,测试通过。
补充:
上面配置虽然ok了,但在后续的实践中,发现使用下述命令才够全面,并更有灵活性:
mysql> CHANGE MASTER TO
-> MASTER_HOST='master_host_name',
-> MASTER_USER='replication_user_name',
-> MASTER_PASSWORD='replication_password',
-> MASTER_LOG_FILE='recorded_log_file_name',
-> MASTER_LOG_POS=recorded_log_position;
- Mysql Master/Slaver 搭建
- 单机实验mysql的主从备份(master slaver)
- mysql 主master 从 slaver 复制 配置详细
- Something About IDE Master & Slaver
- MongoDB Master-Slaver集群部署
- Spring上设置mysql数据源动态切换(master写、slaver读)
- MongoDB 主从复制(Master-Slaver)实验
- HBase master,slaver web端口配置
- mysql master slave 搭建
- 搭建Master-Master Mysql Replication 集群
- Windows下搭建MySql Master-Master Replication
- 搭建mysql master-slave replication
- Mysql Master/Slave环境搭建
- unix设置master和slaver之间无密码访问 ssh
- mySQL搭建master&slave环境记录
- Ubuntu10下MySQL搭建Master Slave
- 用meb搭建mysql master/slave
- MYSQL搭建双master-slave环境一系列问题
- Linux下svn命令
- C#[Serializable]在C#中的作用-NET 中的对象序列化
- 简单工厂模式
- 使用T-SQL导入多个文件数据到SQL Server中
- 优化策略
- Mysql Master/Slaver 搭建
- 求助
- Spring2.5远程调用Hessian的例子
- 使用Proteges生成JADE本体
- 文件夹被隐藏,隐藏属性灰色解决方法
- 关于SVN导致电脑速度慢的问题,进程里TSVNCache.exe非常耗CPU
- Eclipse中cvs的使用介绍
- html2image安装和使用(转+增补)
- aliww开发文档