mysql数据库备份设置延时备份方法(mysql主从配置)

一 为什么需要延时备份

percona-xtrabackup是一个优秀的用于增量备份的工具。今天我们讲到的延时备份也是使用他们的产品。
以前在MySQL AB复制一文中提到了AB复制。我们首先回顾下MySQL复制的相关要点。AB复制又称主从复制,实现的是数据同步。经过以下步骤:

1)主服务器把数据更改记录到二进制日志中,这个操作叫做二进制日志事件;

2)从服务器把主服务器的二进制日志事件拷贝到自己的中继日志(relay log)中;

3)从服务器执行中继日志中的事件,把更改应用到自己的数据上。

在生产中,我们在使用 mysql AB 复制技术不但可以起到数据库层面负载均衡的能力,还可以起到备份数据的功能,但有的时候我们可能由于不小心误操作导致数据被删除,这这个时候 slave服务器上的数据也会同时被删除,如果我们能够能是的其中的一台 slave 延时备份的话, 这样就可以从 slave服务器上找回被误删的数据了。
从服务器到主服务器中拷贝二进制日志文件,如果在并发量高,网络延时严重的情况下,会对主服务器造成相当大的压力,负载高,必定会出现很多问题,比如访问延迟,IO瓶颈,网络拥塞等等。服务器压力过大是我们都不愿看到的情况,那有没有方案缓解这种情况呢?有,这就是本文讲到的延时备份。延时备份通过第三方工具,将检查同步和真正同步的时间控制在一定的范围内,而不是主服务器数据发生变化,从服务器立即去同步二进制事件到自己的中继日志中,这样的话可以大大减轻主服务器的压力,并且基于AB复制的优点,可以达到备份数据的目的。

环境简介

serv01:主服务器 192.168.1.11serv01.host.com

serv08:及时同步服务器 192.168.1.18serv01.host.com

serv09:延时同步服务器 192.168.1.19serv08.host.com

操作系统版本

RHEL Server6.1 64位系统

使用到的软件包版本

mysql-5.5.29-linux2.6-x86_64.tar.gz

percona-toolkit-2.1.7-1.noarch.rpm

第一步,搭建环境。修改配置文件,注意每台的server-id不一致;

代码如下:

[root@serv01 ~]# cat /etc/my.cnf | grep server-id
server-id = 1
#server-id       = 2
[root@serv01 ~]# /etc/init.d/mysqld start
Starting MySQL SUCCESS!

[root@serv08 ~]# cat /etc/my.cnf | grep server-id
server-id = 2
#server-id       = 2
[root@serv08 ~]# /etc/init.d/mysqld start
Starting MySQL SUCCESS!

[root@serv09 ~]# cat /etc/my.cnf | grep server-id
server-id = 3
#server-id       = 2
[root@serv09 ~]# /etc/init.d/mysqld start
Starting MySQL SUCCESS!

第二步,serv01serv08 serv09清空日志

代码如下:

serv01
mysql> show binary logs;
+------------------+-----------+
| Log_name         | File_size |
+------------------+-----------+
| mysql-bin.000001 |       683 |
+------------------+-----------+
1 row in set (0.01 sec)

mysql> reset master;
Query OK, 0 rows affected (0.01 sec)

mysql> show binary logs;
+------------------+-----------+
| Log_name         | File_size |
+------------------+-----------+
| mysql-bin.000001 |       107 |
+------------------+-----------+
1 row in set (0.00 sec)

serv08
mysql> reset master;
Query OK, 0 rows affected (0.02 sec)

mysql> show binary logs;
+------------------+-----------+
| Log_name         | File_size |
+------------------+-----------+
| mysql-bin.000001 |       107 |
+------------------+-----------+
1 row in set (0.00 sec)

serv09
mysql> show binary logs;
+------------------+-----------+
| Log_name         | File_size |
+------------------+-----------+
| mysql-bin.000001 |       107 |
+------------------+-----------+
1 row in set (0.00 sec)

mysql> reset master;
Query OK, 0 rows affected (0.00 sec)

mysql> show binary logs;
+------------------+-----------+
| Log_name         | File_size |
+------------------+-----------+
| mysql-bin.000001 |       107 |
+------------------+-----------+
1 row in set (0.00 sec)

第三步,主服务器serv01创建授权用户

代码如下:

mysql> grant replication client, replication slave on *.* to 'larry'@'192.168.1.%' identified by 'larry';

第四步,serv08修改master设置,开启slave,查看slave状态

代码如下:

mysql> change master to
    -> master_host='192.168.1.11',
    -> master_user='larry',
    -> master_password='larry',
    -> master_port=3306,
    -> master_log_file='mysql-bin.000001',
    -> master_log_pos=107;
Query OK, 0 rows affected (0.03 sec)

mysql> start slave;
Query OK, 0 rows affected (0.00 sec)

mysql> show slave status G;
*************************** 1. row ***************************
               Slave_IO_State: Waiting for master to send event
                  Master_Host: 192.168.1.11
                  Master_User: larry
                  Master_Port: 3306
                Connect_Retry: 60
              Master_Log_File: mysql-bin.000001
          Read_Master_Log_Pos: 107
               Relay_Log_File: serv08-relay-bin.000002
                Relay_Log_Pos: 253
        Relay_Master_Log_File: mysql-bin.000001
             Slave_IO_Running: Yes
            Slave_SQL_Running: Yes
              Replicate_Do_DB:
          Replicate_Ignore_DB:
           Replicate_Do_Table:
       Replicate_Ignore_Table:
      Replicate_Wild_Do_Table:
  Replicate_Wild_Ignore_Table:
                   Last_Errno: 0
                   Last_Error:
                 Skip_Counter: 0
          Exec_Master_Log_Pos: 107
              Relay_Log_Space: 410
              Until_Condition: None
               Until_Log_File:
                Until_Log_Pos: 0
           Master_SSL_Allowed: No
           Master_SSL_CA_File:
           Master_SSL_CA_Path:
              Master_SSL_Cert:
            Master_SSL_Cipher:
               Master_SSL_Key:
        Seconds_Behind_Master: 0
Master_SSL_Verify_Server_Cert: No
                Last_IO_Errno: 0
                Last_IO_Error:
               Last_SQL_Errno: 0
               Last_SQL_Error:
  Replicate_Ignore_Server_Ids:
             Master_Server_Id: 1
1 row in set (0.00 sec)

ERROR:
No query specified

第五步,serv09延时服务器修改master状态,开启slave,查看slave状态

代码如下:

mysql> change master to master_host='192.168.1.11', master_user='larry', master_password='larry', master_port=3306, master_log_file='mysql-bin.000001', master_log_pos=107;
Query OK, 0 rows affected (0.02 sec)

mysql> start slave;
Query OK, 0 rows affected (0.01 sec)

mysql> show slave status G;
*************************** 1. row ***************************
               Slave_IO_State: Waiting for master to send event
                  Master_Host: 192.168.1.11
                  Master_User: larry
                  Master_Port: 3306
                Connect_Retry: 60
              Master_Log_File: mysql-bin.000001
          Read_Master_Log_Pos: 107
               Relay_Log_File: serv09-relay-bin.000002
                Relay_Log_Pos: 253
        Relay_Master_Log_File: mysql-bin.000001
             Slave_IO_Running: Yes
            Slave_SQL_Running: Yes
              Replicate_Do_DB:
          Replicate_Ignore_DB:
           Replicate_Do_Table:
       Replicate_Ignore_Table:
      Replicate_Wild_Do_Table:
  Replicate_Wild_Ignore_Table:
                   Last_Errno: 0
                   Last_Error:
                 Skip_Counter: 0
          Exec_Master_Log_Pos: 107
              Relay_Log_Space: 410
              Until_Condition: None
               Until_Log_File:
                Until_Log_Pos: 0
           Master_SSL_Allowed: No
           Master_SSL_CA_File:
           Master_SSL_CA_Path:
              Master_SSL_Cert:
            Master_SSL_Cipher:
               Master_SSL_Key:
        Seconds_Behind_Master: 0
Master_SSL_Verify_Server_Cert: No
                Last_IO_Errno: 0
                Last_IO_Error:
               Last_SQL_Errno: 0
               Last_SQL_Error:
  Replicate_Ignore_Server_Ids:
             Master_Server_Id: 1
1 row in set (0.00 sec)

ERROR:
No query specified

第六步,在没有使用延时服务器时,serv01创建测试数据库,可以看到同步服务器serv08和延时服务器serv09已经同步了

代码如下:

serv01
mysql> create database justdb;
Query OK, 1 row affected (0.01 sec)

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| crm                |
| justdb             |
| larry              |
| larrydb            |
| mysql              |
| performance_schema |
| test               |
+--------------------+
8 rows in set (0.00 sec)

serv08
mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| justdb             |
| larrydb            |
| mysql              |
| performance_schema |
| test               |
+--------------------+
6 rows in set (0.03 sec)

serv09
mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| justdb             |
| larry              |
| larrydb            |
| mysql              |
| performance_schema |
| test               |
+--------------------+
7 rows in set (0.00 sec)

第七步,拷贝percona-toolkit-2.1.7-1.noarch.rpm

代码如下:

[root@larrywen ule-mysql]# scp percona-toolkit-2.1.7-1.noarch.rpm 192.168.1.11:/opt
root@192.168.1.11's password:
percona-toolkit-2.1.7-1.noarch.rpm                       100% 1767KB   1.7MB/s   00:00

第八步,主服务器中通过yum安装percona-toolkit-2.1.7-1.noarch.rpm

代码如下:

[root@serv01 opt]# yum install percona-toolkit-2.1.7-1.noarch.rpm -y

第九步,使用pt-slave-delay工具进行延时设置。可以先查看帮助。

代码如下:

[root@serv01 opt]# pt-slave-delay --help
pt-slave-delay starts and stops a slave server as needed to make it lag behind
the master.  The SLAVE-HOST and MASTER-HOST use DSN syntax, and values are
copied from the SLAVE-HOST to the MASTER-HOST if omitted.  For more details,
please use the --help option, or try 'perldoc /usr/bin/pt-slave-delay' for
complete documentation.

Usage: pt-slave-delay [OPTION...] SLAVE-HOST [MASTER-HOST]

Options:

--ask-pass            Prompt for a password when connecting to MySQL
  --charset=s       -A  Default character set
  --config=A            Read this comma-separated list of config files; if
                        specified, this must be the first option on the command
                        line
  --[no]continue        Continue replication normally on exit (default yes)
  --daemonize           Fork to the background and detach from the shell
  --database=s      -D  The database to use for the connection
  --defaults-file=s -F  Only read mysql options from the given file
  --delay=m             How far the slave should lag its master (default 1h).
                        Optional suffix s=seconds, m=minutes, h=hours, d=days;
                        if no suffix, s is used.
  --help                Show help and exit
  --host=s          -h  Connect to host
  --interval=m          How frequently pt-slave-delay should check whether the
                        slave needs to be started or stopped (default 1m).
                        Optional suffix s=seconds, m=minutes, h=hours, d=days;
                        if no suffix, s is used.
  --log=s               Print all output to this file when daemonized
  --password=s      -p  Password to use when connecting
  --pid=s               Create the given PID file when daemonized
  --port=i          -P  Port number to use for connection
  --quiet           -q  Don't print informational messages about operation
  --run-time=m          How long pt-slave-delay should run before exiting.
                        Optional suffix s=seconds, m=minutes, h=hours, d=days;
                        if no suffix, s is used.
  --set-vars=s          Set these MySQL variables (default wait_timeout=10000)
  --socket=s        -S  Socket file to use for connection
  --use-master          Get binlog positions from master, not slave
  --user=s          -u  User for login if not current user
  --version             Show version and exit
  --version-check=s     Send program versions to Percona and print suggested
                        upgrades and problems (default off)

Option types: s=string, i=integer, f=float, h/H/a/A=comma-separated list, d=DSN, z=size, m=time

Rules:

This tool accepts additional command-line arguments. Refer to the SYNOPSIS and usage information for details.

DSN syntax is key=value[,key=value...]  Allowable DSN keys:

KEY  COPY  MEANING
  ===  ====  =============================================
  A    yes   Default character set
  D    yes   Default database
  F    yes   Only read default options from the given file
  P    yes   Port number to use for connection
  S    yes   Socket file to use for connection
  h    yes   Connect to host
  p    yes   Password to use when connecting
  u    yes   User for login if not current user

If the DSN is a bareword, the word is treated as the 'h' key.

Options and values after processing arguments:

--ask-pass            FALSE
  --charset             (No value)
  --config              /etc/percona-toolkit/percona-toolkit.conf,/etc/percona-toolkit/pt-slave-delay.conf,/root/.percona-toolkit.conf,/root/.pt-slave-delay.conf
  --continue            TRUE
  --daemonize           FALSE
  --database            (No value)
  --defaults-file       (No value)
  --delay               3600
  --help                TRUE
  --host                (No value)
  --interval            60
  --log                 (No value)
  --password            (No value)
  --pid                 (No value)
  --port                (No value)
  --quiet               FALSE
  --run-time            (No value)
  --set-vars            wait_timeout=10000
  --socket              (No value)
  --use-master          FALSE
  --user                (No value)
  --version             FALSE
  --version-check       off

第十步,serv09延时服务器中创建授权用户

代码如下:

mysql> grant all on *.* to 'rep'@'192.168.1.%' identified by 'larry';
Query OK, 0 rows affected (0.00 sec)

第十一步,实现功能。

代码如下:

[root@serv01 ~]# pt-slave-delay --user='rep' --password='larry' --delay=3m --interval=20s --run-time=30m 192.168.1.19
2013-10-06T19:43:30 slave running 0 seconds behind
2013-10-06T19:43:30 STOP SLAVE until 2013-10-06T19:46:30 at master position mysql-bin.000001/199

<strong>命令解释</strong>
--user='rep':延时服务器中授权用户的用户名,这里设置为rep
--password='larry':延时服务器中授权用户的密码,这里设置为larry
--delay=3m:延时同步的时间,这里设置为3分钟
--interval=20s:检查同步的时间,这里设置为20s
--run-time=30m:pt-slave-delay的运行时间,这里设置为30分钟
192.168.1.19:延时服务器的IP地址

第十二步,测试,主服务器serv01创建测试数据库,可以发现同步服务器立马更新,而延时同步服务器要等3分钟之后才更新

代码如下:

serv01
mysql> use justdb;
Database changed
mysql> create table test(id int);
Query OK, 0 rows affected (0.01 sec)

mysql> insert into test values(1);
Query OK, 1 row affected (0.00 sec)

serv08
  mysql> select * from justdb.test;
+------+
| id   |
+------+
|    1 |
+------+
1 row in set (0.00 sec)

serv09
mysql> select * from justdb.test;
ERROR 1146 (42S02): Table 'justdb.test' doesn't exist

三分钟过后查看延时服务器已经同步成功
[root@serv01 ~]# pt-slave-delay --user='rep' --password='larry' --delay=3m --interval=20s --run-time=30m 192.168.1.19
2013-10-06T19:43:30 slave running 0 seconds behind
2013-10-06T19:43:30 STOP SLAVE until 2013-10-06T19:46:30 at master position mysql-bin.000001/199
2013-10-06T19:43:50 slave stopped at master position mysql-bin.000001/199
2013-10-06T19:44:10 slave stopped at master position mysql-bin.000001/199
2013-10-06T19:44:30 slave stopped at master position mysql-bin.000001/492
2013-10-06T19:44:50 slave stopped at master position mysql-bin.000001/492
2013-10-06T19:45:10 slave stopped at master position mysql-bin.000001/492
2013-10-06T19:45:30 slave stopped at master position mysql-bin.000001/492
2013-10-06T19:45:50 slave stopped at master position mysql-bin.000001/492
2013-10-06T19:46:10 slave stopped at master position mysql-bin.000001/492
2013-10-06T19:46:30 no new binlog events
2013-10-06T19:46:50 slave stopped at master position mysql-bin.000001/492
2013-10-06T19:47:10 slave stopped at master position mysql-bin.000001/492
2013-10-06T19:47:30 START SLAVE until master 2013-10-06T19:44:30 mysql-bin.000001/492
2013-10-06T19:47:50 slave running 0 seconds behind
2013-10-06T19:47:50 STOP SLAVE until 2013-10-06T19:50:50 at master position mysql-bin.000001/492
2013-10-06T19:48:10 slave stopped at master position mysql-bin.000001/492
2013-10-06T19:48:30 slave stopped at master position mysql-bin.000001/492
2013-10-06T19:48:50 slave stopped at master position mysql-bin.000001/492
2013-10-06T19:49:10 slave stopped at master position mysql-bin.000001/492
2013-10-06T19:49:30 slave stopped at master position mysql-bin.000001/492
2013-10-06T19:49:50 slave stopped at master position mysql-bin.000001/492
2013-10-06T19:50:10 slave stopped at master position mysql-bin.000001/492
2013-10-06T19:50:30 slave stopped at master position mysql-bin.000001/492
2013-10-06T19:50:50 no new binlog events
2013-10-06T19:51:10 slave stopped at master position mysql-bin.000001/492
2013-10-06T19:51:30 slave stopped at master position mysql-bin.000001/492
2013-10-06T19:51:50 slave stopped at master position mysql-bin.000001/492
2013-10-06T19:52:10 slave stopped at master position mysql-bin.000001/492
2013-10-06T19:52:30 slave stopped at master position mysql-bin.000001/492
2013-10-06T19:52:50 slave stopped at master position mysql-bin.000001/492
2013-10-06T19:53:10 slave stopped at master position mysql-bin.000001/492
2013-10-06T19:53:30 slave stopped at master position mysql-bin.000001/492
2013-10-06T19:53:50 slave stopped at master position mysql-bin.000001/492
2013-10-06T19:54:10 no new binlog events
2013-10-06T19:54:30 slave stopped at master position mysql-bin.000001/492
2013-10-06T19:54:50 slave stopped at master position mysql-bin.000001/492
2013-10-06T19:55:10 slave stopped at master position mysql-bin.000001/492
2013-10-06T19:55:30 slave stopped at master position mysql-bin.000001/492
2013-10-06T19:55:50 slave stopped at master position mysql-bin.000001/492
2013-10-06T19:56:10 slave stopped at master position mysql-bin.000001/492
2013-10-06T19:56:30 slave stopped at master position mysql-bin.000001/492
2013-10-06T19:56:50 slave stopped at master position mysql-bin.000001/492
2013-10-06T19:57:10 slave stopped at master position mysql-bin.000001/492
2013-10-06T19:57:30 no new binlog events
2013-10-06T19:57:50 slave stopped at master position mysql-bin.000001/492
2013-10-06T19:58:10 slave stopped at master position mysql-bin.000001/492
2013-10-06T19:58:30 slave stopped at master position mysql-bin.000001/492
2013-10-06T19:58:50 slave stopped at master position mysql-bin.000001/492
2013-10-06T19:59:10 slave stopped at master position mysql-bin.000001/492
2013-10-06T19:59:30 slave stopped at master position mysql-bin.000001/492
2013-10-06T19:59:50 slave stopped at master position mysql-bin.000001/492
2013-10-06T20:00:10 slave stopped at master position mysql-bin.000001/492
2013-10-06T20:00:30 slave stopped at master position mysql-bin.000001/492
2013-10-06T20:00:50 no new binlog events
2013-10-06T20:01:10 slave stopped at master position mysql-bin.000001/492
2013-10-06T20:01:30 slave stopped at master position mysql-bin.000001/492
2013-10-06T20:01:50 slave stopped at master position mysql-bin.000001/492
2013-10-06T20:02:10 slave stopped at master position mysql-bin.000001/492
2013-10-06T20:02:30 slave stopped at master position mysql-bin.000001/492
2013-10-06T20:02:50 slave stopped at master position mysql-bin.000001/492
2013-10-06T20:03:10 slave stopped at master position mysql-bin.000001/492
2013-10-06T20:03:30 slave stopped at master position mysql-bin.000001/492
2013-10-06T20:03:50 slave stopped at master position mysql-bin.000001/492
2013-10-06T20:04:10 no new binlog events
2013-10-06T20:04:30 slave stopped at master position mysql-bin.000001/492
2013-10-06T20:04:50 slave stopped at master position mysql-bin.000001/492
2013-10-06T20:05:10 slave stopped at master position mysql-bin.000001/492
2013-10-06T20:05:30 slave stopped at master position mysql-bin.000001/492
2013-10-06T20:05:50 slave stopped at master position mysql-bin.000001/492
2013-10-06T20:06:10 slave stopped at master position mysql-bin.000001/492
2013-10-06T20:06:30 slave stopped at master position mysql-bin.000001/492
2013-10-06T20:06:50 slave stopped at master position mysql-bin.000001/492
2013-10-06T20:07:10 slave stopped at master position mysql-bin.000001/492
2013-10-06T20:07:30 no new binlog events
2013-10-06T20:07:50 slave stopped at master position mysql-bin.000001/492
2013-10-06T20:08:10 slave stopped at master position mysql-bin.000001/492
2013-10-06T20:08:30 slave stopped at master position mysql-bin.000001/492
2013-10-06T20:08:50 slave stopped at master position mysql-bin.000001/492
2013-10-06T20:09:10 slave stopped at master position mysql-bin.000001/492
2013-10-06T20:09:30 slave stopped at master position mysql-bin.000001/492
2013-10-06T20:09:50 slave stopped at master position mysql-bin.000001/492
2013-10-06T20:10:10 slave stopped at master position mysql-bin.000001/492
2013-10-06T20:10:30 slave stopped at master position mysql-bin.000001/492
2013-10-06T20:10:50 no new binlog events
2013-10-06T20:11:10 slave stopped at master position mysql-bin.000001/492
2013-10-06T20:11:30 slave stopped at master position mysql-bin.000001/492
2013-10-06T20:11:50 slave stopped at master position mysql-bin.000001/492
2013-10-06T20:12:10 slave stopped at master position mysql-bin.000001/492
2013-10-06T20:12:30 slave stopped at master position mysql-bin.000001/492
2013-10-06T20:12:50 slave stopped at master position mysql-bin.000001/492
2013-10-06T20:13:10 slave stopped at master position mysql-bin.000001/492
2013-10-06T20:13:30 slave stopped at master position mysql-bin.000001/492
2013-10-06T20:13:30 Setting slave to run normally

mysql> select * from justdb.test;
+------+
| id   |
+------+
|    1 |
+------+
1 row in set (0.00 sec)

四 附延时备份脚本

代码如下:

#!/bin/bash
#
# chkconfig: - 88 12
# description: the mysql ab delay scripts

host=192.168.100.54
user=rep
password=larry

delay=2m
in=15s

prog=/usr/bin/pt-slave-delay

. /etc/init.d/functions

start() {
    echo -n "Starting `basename $prog`..."
    daemon $prog --host=$host --user=$user --password=$password --delay=$delay --interval=$in --daemonize --log=/var/log/mysql-delay.log
    echo
}

stop() {
    echo -n "Stopping `basename $prog`..."
    killproc  $prog
    echo
}

case "$1" in
    start)
        start

stop)
        stop

restart)
        stop
        start

*)
        echo "Usage: $0 {start|stop|restart}"
        exit 1
esac

(0)

相关推荐

  • 小记一次mysql主从配置解决方案

    今天研究了个开源项目,数据库是mysql的,其中的脚本数据需要备份,由于本人的机器时mac pro,而且mac下的数据库连接工具都不怎么好用,就想着如何利用windows下的数据库连接工具使用,并做相关备份,另外windows系统下的sqlyog工具还是非常强大的,在此推荐. 因此为了使用sqlyog等windows系统下的连接工具,便开始了一天的折腾. 首先两种思路,其一是利用另外一台宏碁笔记本电脑,直接在其上安装sqlyog使用,通过无线局域网进行连接使用,这种方式太过麻烦,而且来回换电脑很

  • 解读mysql主从配置及其原理分析(Master-Slave)

    1.在主数据库服务器为从服务器添加一个拥有权限访问主库的用户:GRANT REPLICATION SLAVE ON *.* TO ' test'@'%' IDENTIFIED BY 'test'; (%表示允许所有IP,可设置指定从服务器IP)添加用户后:可在从服务器上用mysql -h127.0.0.1 -utest -ptest;  来测试是否有权限访问主数据库 2.在主据库配置文件加上:#master configserver-id       = 1log-bin          =

  • MySQL5.7主从配置实例解析

    MySQL5.7主从配置实现方法,具体内容如下 安装环境: Master:10.211.55.11,Redhat6.5,MySQL5.7.12 Slave: 10.211.55.12,Redhat6.5,MySQL5.7.12 Master的my.cnf配置: Slave的my.cnf配置: 可指定那些database需要复制,哪些不需要复制,如在我的my.cnf配置中注释掉的内容,我默认是全部都复制.修改完my.cnf配置文件后,两台机器都将MySQL服务重启:service mysqld r

  • mysql5.5 master-slave(Replication)主从配置

    一主一从: Master: OS:centos release 5.6 DB:mysql 5.5.8 IP:192.168.1.2 Slave: OS:centos release 5.6 DB:mysql 5.5.8 IP:192.168.1.3 修改主机Master配置文件 (/etc/my.cnf) 复制代码 代码如下: [mysqld] //至少要有server-id.与log-bin两项 server-id=1 log-bin=/var/lib/mysql/mysql-bin data

  • windows下mysql数据库主从配置教程

    windows下配置mysql数据库主从的详细过程,具体内容如下 所用到工具: Mysql.Navicat Premium: 主库设置: 一.设置my.ini 文件: 1.在安装目录下找到my.ini 文件: 默认路径:C:\Program Files\MySQL\MySQL Server 5.0 2.在my.ini 文件中找到[mysqld](#注释自行删除) 添加如下配置 server-id=1#主库和从库需要不一致 log-bin=mysql-bin binlog-do-db=mstest

  • mysql数据库互为主从配置方法分享

    mysql主从配置小记: 共有四台机器:A(10.1.10.28),B(10.1.10.29),C(10.1.10.30),D(10.1.10.31). 配置后结果:A-C互为主从,B为A的slave,D为C的slave. 0)准备工作 在四台机器上面安装好mysql后,创建用于同步的账号. 添加账户: 复制代码 代码如下: INSERT INTO user (Host,User, Password,Select_priv,Insert_priv,Update_priv,Delete_priv,

  • Docker mysql 主从配置详解及实例

    Docker mysql 主从配置 1.首先创建两个文件my-m.cnf(主库配置) .my-s.cnf(从库配置) my-m.cnf 内容如下 # Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU

  • mysql数据库备份设置延时备份方法(mysql主从配置)

    一 为什么需要延时备份percona-xtrabackup是一个优秀的用于增量备份的工具.今天我们讲到的延时备份也是使用他们的产品.以前在MySQL AB复制一文中提到了AB复制.我们首先回顾下MySQL复制的相关要点.AB复制又称主从复制,实现的是数据同步.经过以下步骤: 1)主服务器把数据更改记录到二进制日志中,这个操作叫做二进制日志事件: 2)从服务器把主服务器的二进制日志事件拷贝到自己的中继日志(relay log)中: 3)从服务器执行中继日志中的事件,把更改应用到自己的数据上. 在生

  • Mysql数据库手动及定时备份步骤

    目录 手动备份 定时器备份 手动备份 1)cmd控制台:mysqldump -uroot -proot 数据库名 [表名1,表名2...] > 文件路径 比如:把 demo 数据库备份到 E:\test\demo.bak 下 mysqldump -uroot -p123456 demo > E:\test\demo.bak #123456是数据库密码 如果你希望备份是,demo 库的 test1 表 mysqldump -uroot -p123456 demo test1 > E:\te

  • MySQL数据库超时设置配置的方法实例

    目录 前言 1. JDBC超时设置 2. 连接池超时设置 3. MyBatis查询超时 4. 事务超时 总结 前言 最近备战京东双11,在配置MySQL的超时配置发现有很多地方可以设置.这么多超时的配置有什么影响,以及配置会有什么影响呢?今天的文章就让我来大家来分析一下. 1. JDBC超时设置 connectTimeout:表示等待和MySQL数据库建立socket链接的超时时间,默认值0,表示不设置超时,单位毫秒,建议30000 socketTimeout:表示客户端和MySQL数据库建立s

  • IDEA连接mysql数据库报错的解决方法

    IDEA连接mysql数据库出现Server returns invalid timezone. Go to 'Advanced' tab and set 'serverTimezone' property manually. 报错意思是服务器返回了无效时区.也就是我们的数据库返回了无效的时区. 如图所示: 报错中显示让我们去Advanced下的serverTimezone看看. 那我们就打开Advanced看看 可以看到这里显示的时域为空的,我们填入Asia/Shanghai 搞定.注意这里可

  • php+mysql数据库实现无限分类的方法

    本文实例讲述了php+mysql数据库实现无限分类的方法.分享给大家供大家参考.具体分析如下: 这款php无限分类代码比较完整理包括了数据库是mysql的,有增加.删除.编辑.移动的功能,同时还提供数据库sql表结构.代码如下: 复制代码 代码如下: //连接数据库 $link = mysql_connect('localhost','root','') or die(mysql_error()); mysql_select_db('class',$link)or die(mysql_error

  • Python使用pymysql从MySQL数据库中读出数据的方法

    python3.x已经不支持mysqldb了,支持的是pymysql 使用pandas读取MySQL数据时,使用sqlalchemy,出现No module named 'MySQLdb'错误. 安装:打开Windows PowerShell,输入pip3 install PyMySQL即可 import pymysql.cursors import pymysql import pandas as pd #连接配置信息 config = { 'host':'127.0.0.1', 'port'

  • IDEA无法连接mysql数据库的6种解决方法大全

    本文主要介绍了IDEA无法连接mysql数据库的6种解决方法大全,分享给大家,具体如下: 1.本地的mysql没有创建该数据库(笔者就是这个原因!) 查看数据库发现没有,重建就可以了 测试成功! 网上说法: 2.IP地址不对 https://www.jb51.net/article/200432.htm 3.mysql版本过高 https://bbs.csdn.net/topics/392368070?page=1 4.创建的Java项目的路径里包含中文字符 https://www.jb51.n

  • MYSQL数据库如何设置主从同步

    目录 1.配置主数据库 2.配置从数据库 总结 MYSQL可以配置1个主数据库多个从数据库 1.配置主数据库 主master : 192.168.1.132 从slave : 192.168.1.133 1)授权给从数据库 GRANT REPLICATION SLAVE ON *.* to 'repl'@'192.168.1.132' identified by 'test123456'; FLUSH PRIVILEGES; 2)修改主库配置文件,开启binlog,并设置server-id,每次

  • mysql数据库太大了如何备份与还原

    命令:mysqlhotcopy 这个命令会在拷贝文件之前会把表锁住,并把数据同步到数据文件中,以避免拷贝到不完整的数据文件,是最安全快捷的备份方法. 命令的使用方法是: mysqlhotcopy -u root -p<rootpass> db1 db2 - dbn <output_dir> 如果需要备份全部数据库,可以加上–regexp=".*"参数. Mysqlhotcopy命令可自动完成数据锁定工作,备份时不用关闭服务器. 它还可以刷新日志,使备份文件和日志

  • mysql数据库远程访问设置方法

    1.改表法. 可能是你的帐号不允许从远程登陆,只能在localhost.这个时候只要在localhost的那台电脑,登入mysql后,更改 "mysql" 数据库里的 "user" 表里的 "host" 项,从"localhost"改称"%" mysql -u root -pvmwaremysql>use mysql; mysql>update user set host = '%' where

随机推荐