mysql 主从复制实验------包含授权、bin-log
来源:互联网 发布:如何成为社交高手 知乎 编辑:程序博客网 时间:2024/05/21 06:36
环境:两台 Linux虚拟机 centos 5.5
200.168.10.10 master
200.168.10.5 slave
-------------------------
mysql 用户授权:
bin-log日志:
200.168.10.10_master:
200.168.10.5_slave:
从如果能复制主服务器的数据,就要求有访问主的权限:
所以授权是必要的。
----
[root@localhost test]# /usr/local/mysql/bin/mysql -uroot -p -h200.168.10.10Enter password:ERROR 1130 (HY000): Host '200.168.10.5' is not allowed to connect to this MySQL server[root@localhost test]#
在主服务器上:
mysql> grant all on *.* to user@200.168.10.5 identified by '123';//或者:grant replication slave on *.* to user@200.168.10.5 identified by '123';
在从上登录主的数据库
[root@localhost test]# /usr/local/mysql/bin/mysql -uuser -p -h200.168.10.10
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 3106
Server version: 5.1.59-community-log Source distribution
Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql>
--------------------------------------------------------------------
查看bin-log是否开启:
show variables like "%log_bin%";
reset master;之后:
[root@localhost var]# ls
ibdata1 lehand mysql-bin.000001
ib_logfile0 localhost.localdomain.err mysql-bin.index
ib_logfile1 localhost.localdomain.pid test
left_hand mysql
*
查看最后一个bin-log文件信息:
mysql> show master status;
*
**
查看bin-log的动作记录
[root@localhost var]# /usr/local/mysql/bin/mysqlbinlog --no-defaults mysql-bin.000003
**
****
通过bin-log日志恢复数据:
[root@localhost var]# /usr/local/mysql/bin/mysqlbinlog --no-defaults mysql-bin.000001 |/usr/local/mysql/bin/mysql -uroot -p test
Enter password:
[root@localhost var]#
****
reset master :清理mysql-bin文件;
flush logs; 生成一个新的bin-logs;
***
//mysql备份:
[root@localhost var]# /usr/local/mysql/bin/mysqldump -uroot -p test -l -F > test.sql
Enter password:
[root@localhost var]#
***
*
恢复方法:
用先前备份的sql文件恢复;
用bin-log日志恢复;
可以根据位置点来恢复文件:
--stop-position 348
--start-position 467
恢复操作点之间的部分数据
[root@localhost var]# /usr/local/mysql/bin/mysqlbinlog --no-defaults mysql-bin.000005 --start-position="348" --stop-position="467" |/usr/local/mysql/bin/mysql -uroot -p test
Enter password:
[root@localhost var]#
*
*****
主从复制: --另一个备份方法: 最高境界,这几个备份方法的混合使用:最后的是dump -l -F 不用考虑枷锁解锁
----在从服务器上进行查询操作。负载均衡、读写分离:(实时性要求高的话,查询不要在从服务器)
----------
考虑数据库的锁定
主服务器配置不变 cat /etc/my.cnf
server-id
bin-log
查看授权:
mysql> show grants for user@200.168.10.5;
隧道传输:把 200.168.10.10 当前目录下的 test.sql文件 传到200.168.10.5 的test目录下
[root@localhost var]# scp test.sql 200.168.10.5:/test
从服务器:
server-id = 2# The replication master for this slave - requiredmaster-host = 200.168.10.10## The username the slave will use for authentication when connecting# to the master - requiredmaster-user = user## The password the slave will authenticate with when connecting to# the master - requiredmaster-password = 123## The port the master is listening on.# optional - defaults to 3306master-port = 3306
重启mysql:
[root@localhost test]# /usr/local/mysql/bin/mysqld_safe --user=mysql &
关闭:
pkill mysqld
进入从自己的数据库,执行
show slave status;mysql> show slave status\G;*************************** 1. row ***************************Slave_IO_State: Waiting for master to send eventMaster_Host: 200.168.10.10Master_User: userMaster_Port: 3306Connect_Retry: 60Master_Log_File: mysql-bin.000003Read_Master_Log_Pos: 106Relay_Log_File: localhost-relay-bin.000006Relay_Log_Pos: 251Relay_Master_Log_File: mysql-bin.000003Slave_IO_Running: YesSlave_SQL_Running: YesReplicate_Do_DB:Replicate_Ignore_DB:Replicate_Do_Table:Replicate_Ignore_Table:Replicate_Wild_Do_Table:Replicate_Wild_Ignore_Table:Last_Errno: 0Last_Error:Skip_Counter: 0Exec_Master_Log_Pos: 106Relay_Log_Space: 453Until_Condition: NoneUntil_Log_File:Until_Log_Pos: 0Master_SSL_Allowed: NoMaster_SSL_CA_File:Master_SSL_CA_Path:Master_SSL_Cert:Master_SSL_Cipher:Master_SSL_Key:Seconds_Behind_Master: 0Master_SSL_Verify_Server_Cert: NoLast_IO_Errno: 0Last_IO_Error:Last_SQL_Errno: 0Last_SQL_Error:1 row in set (0.00 sec)
说明已经同步的情况:
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
---
主服务器端:
mysql> show master status\G;*************************** 1. row ***************************File: mysql-bin.000003Position: 106Binlog_Do_DB:Binlog_Ignore_DB:1 row in set (0.00 sec)
*****
***
slave无法同步的问题:
先停掉slave
如果不同步 再看视频:
第12讲:
***
阅读全文
0 0
- mysql 主从复制实验------包含授权、bin-log
- MySQL 用户授权和bin-log日志和主从复制、读写分离(1)
- MySQL 用户授权和bin-log日志和主从复制、读写分离(2)
- Mysql bin-log日志和主从复制
- mysql bin-log 主从配置
- mysql bin-log 主从配置
- mysql主从复制实验
- PHP特级视频教程 笔记心得 第十二集 MySQL bin-log日志和主从复制
- MySQL 主从复制 replication 实验!
- MySQL主从复制实验记录
- 主从数据库复制中有关bin-log格式问题
- MySQL主从数据库之Mysql bin-log日志恢复数据
- mysql主从复制(个人实验记录)
- MySQL用户授权 和 bin-log日志 详解和实战
- MySQL用户授权 和 bin-log日志 详解和实战
- MySQL用户授权 和 bin-log日志 详解和实战
- MySQL用户授权 和 bin-log日志 详解和实战
- mysql innodb ib_logfile、bin-log与主从同步的问题
- SpringMVC中使用Interceptor拦截器
- Jmeter使用总结
- CentOS 6.4 : -bash :setup: command not found
- Yupoo!(又拍网)架构 是目前国内最大的图片服务提供商,整个网站构建于大量的开源软件之上
- Linux centos 5.5 NFS 配置
- mysql 主从复制实验------包含授权、bin-log
- LDAP 与 PHP
- Filesystem 函数:fopen、feof、fgets、fclose
- Vue----v-for 循环 及部分内部指令
- php之cURL学习笔记2
- cacti 实验:
- Apache 自带性能监控 server-status
- PHP 链式操作 __call call_user_func
- URL重写(rewirte)实验