mysql 热备份

以下为在windows 环境下己测试成功,至于liunx应该差不多

A:主服务器

IP192.168.9.203

B:从服务器

IP192.168.9.131

 

1、在A的数据库中建立一个备份帐户,命令如下:
GRANT REPLICATION SLAVE,RELOAD,SUPER ON *.*
TO backup@'
192.168.9.131'
IDENTIFIED BY ‘1234’;

说明:backup(用户名) 192.168.9.131(Ip地址) 1234(密码)

 

2、因为mysql版本新密码算法不同,所以进入mysql下,输入:set password for 'backup'@'192.168.100.2'=old_password('1234');

 

3、关停A服务器,将A中的数据拷贝到B服务器中,使得AB中的数据同步,并且确保在全部设置操作结束前,禁止在AB服务器中进行写操作,使得两数据库中的数据一定要相同!

 

4、对A服务器的配置进行修改,打开mysql/my.ini文件,在[mysqld]下面添加如下内容:
server-id=1
log-bin=c:/log-bin.log

server-id
:为主服务器AID
log-bin
:二进制变更日值

 

5、重启A服务器,从现在起,它将把客户端有关数据库的修改记载到二进制变更日志里去

6、关停B服务器,对B服务器配置,以便让它知道自己的镜像ID、到哪里去找主服务器以及如何去连接服务器。最简单的情况是主、从服务器分别运行在不同的主机上并都使用着默认的TCP/IP端口,只要在从服务器启动时去读取的mysql/my.ini文件里添加以下指令就行了。

[mysqld]

server-id=2

7、启动B数据库执行以下命令

Change master to

master-host=’192.168.9.203’

master-user=’backup’,

master-password=’1234’.

然后再执行

Start slave

 

 

=============================================

1.GRANT REPLICATION SLAVE,SUPER,RELOAD  ON *.* TO 'repl'@'%' IDENTIFIED BY 'slavepass';
2. FLUSH TABLES WITH READ LOCK;
3. UNLOCK TABLES;
4. START SLAVE;
CHANGE MASTER TO MASTER_HOST='192.168.0.101',MASTER_PORT=3307,MASTER_USER='repl',MASTER_PASSWORD='slavepass',MASTER_LOG_FILE='mysql-bin.000011',MASTER_LOG_POS=997;

LOAD TABLE FROM MASTER or LOAD DATA FROM MASTER
LOAD DATA FROM MASTER;
SHOW PROCESSLIST/G;
show SLAVE STATUS/G;
show master status/G;

LOAD DATA FROM MASTER currently works only if all the tables on the master use the MyISAM storage engine
The retry interval is controlled by the --master-connect-retry option. The default is 60 seconds.

mysql双备份

1.Make sure that the versions of MySQL installed on the master and slave are compatible according to the table
查看服务器版本 mysql -V
2.Set up an account on the master server that the slave server can use to connect.

GRANT REPLICATION SLAVE,SUPER,RELOAD ON *.* TO 'repl'@'%.mydomain.com' IDENTIFIED BY 'slavepass';

3.
 Flush all the tables and block write statements by executing a FLUSH TABLES WITH READ LOCK statement:
 mysql> FLUSH TABLES WITH READ LOCK;
 To use tar to create an archive that includes all databases, change location into the master server's data directory, then execute this command:
 shell> tar -cvf /tmp/mysql-snapshot.tar .
 If you want the archive to include only a database called this_db, use this command instead:
 shell> tar -cvf /tmp/mysql-snapshot.tar ./this_db
 Then copy the archive file to the /tmp directory on the slave server host.
 On that machine, change location into the slave's data directory, and unpack the archive file using this command:
 shell> tar -xvf /tmp/mysql-snapshot.tar

 While the read lock placed by FLUSH TABLES WITH READ LOCK is in effect, read the value of the current binary log name and offset on the master:
 mysql > SHOW MASTER STATUS;
 The File column shows the name of the log, while Position shows the offset.

 After you have taken the snapshot and recorded the log name and offset, you can re-enable write activity on the master:

 mysql> UNLOCK TABLES;
 
mysql> FLUSH TABLES WITH READ LOCK;
mysql> SHOW MASTER STATUS;
shell> mysqladmin -u root shutdown

4.Make sure that the [mysqld] section of the my.cnf file on the master host includes a log-bin option.
[mysqld]
log-bin=mysql-bin
server-id=1

5.Stop the server that is to be used as a slave server and add the following to its my.cnf file:
[mysqld]
server-id=2
6.If you made a binary backup of the master server's data, copy it to the slave server's data directory before starting the slave.
7.Start the slave server.
8.If you made a backup of the master server's data using mysqldump, load the dump file into the slave server:

shell> mysql -u root -p < dump_file.sql
9.Execute the following statement on the slave, replacing the option values with the actual values relevant to your system:

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;

10.Start the slave threads:

mysql> START SLAVE;

implement:

 modify
 my-large.ini
 port  = 3307
 server-id = 1

 my-large.ini
 port  = 3308
 server-id = 2
install mysql(notice change to install dir/bin)
 mysqld-nt install mysqltest1  --defaults-file=F:/server/mysqltest1/my-large.ini
 mysqld-nt install mysqltest2  --defaults-file=F:/server/mysqltest2/my-large.ini
 net start mysqltest1
 net start mysqltest2
configuration 
 on master host
  GRANT REPLICATION SLAVE,SUPER,RELOAD  ON *.* TO 'repl'@'%' IDENTIFIED BY '123';
  FLUSH TABLES WITH READ LOCK;
  show proccesslist /G;
  show master status /G;//recorded the log name and offset
  UNLOCK TABLES;
 on slave host
  mysql -P3308 -u root
  CHANGE MASTER TO MASTER_HOST='192.168.0.101',MASTER_PORT=3307,MASTER_USER='repl',MASTER_PASSWORD='slavepass',MASTER_LOG_FILE='mysql-bin.000011',MASTER_LOG_POS=997;
  slave start
  show proccesslist /G;
  show slave status /G;

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
MySQL热备份是指在数据库运行期间进行备份操作,而不需要停止数据库服务。根据提供的引用内容,可以使用mysqldump工具来进行热备份。 具体步骤如下: 1. 打开命令提示符或终端窗口,并切换到MySQL的安装目录下的bin目录。 2. 使用以下命令进行备份操作:mysqldump -u root -p mydb > d:\mydb.sql 其中,-u指定用户名为root,-p表示需要输入密码,mydb是需要备份的数据库名称,d:\mydb.sql是备份文件的保存路径和文件名。 3. 如果你的数据库中有自己写的存储过程或函数,还需要加上--routines选项,以备份这些存储过程或函数。例如:mysqldump -u root -p --routines mydb > d:\mydb.sql 4. 注意,在执行备份命令时,如果SQL语句末尾添加了分号';',可能会导致出现"db not found"的错误。因此,请确保备份命令的语句末尾没有添加分号。 5. 执行备份命令后,等待一段时间,直到备份完成。备份文件将保存在指定的路径和文件名中。 这样,你就可以通过使用mysqldump工具进行MySQL热备份操作了。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *2* *3* [mysql热备份](https://blog.csdn.net/weixin_39994296/article/details/113631263)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 100%"] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值