mysql disaster recovery

Cross-server backup:

Server A: 192.168.5.193
test TestDB database
server B: 192.168.5.194
objectives: to test the database server A to the server B, a scheduled backup

Technology needs: mysqldump + crontab

Steps:
1. Modify mysql remote connection access to
modify the mysql configuration file /mysql/my.conf, will increase behind the bind-address remote access IP address or ban these words you can make long-range aircraft landed visited.

2. increase the server an authorized user
on the server A:

CREATE USER 'username'@'host' IDENTIFIED BY 'password';

Description:

  1. username: You will create a username
  2. host: Specifies that the user can log on which host, if it is locally available to the user localhost, if you want the user can log in from any remote host, you can use wildcards%
  3. password: the user's login password, the password can be empty, if empty then the user can log in without a password server
GRANT privileges ON databasename.tablename TO 'username'@'host'

Description:

  1. privileges: the user's operating authority, such as SELECT, INSERT, UPDATE, etc. If you want to grant permissions is to use ALL
  2. databasename: database name
  3. tablename: Table name, if you want to grant the user is available for all database tables and corresponding operating authority said that if *.

This test case mysql statement:

CREATE USER 'why'@'192.168.5.194' IDENTIFIED BY '123456';
GRANT privileges ON *.* TO 'why'@'192.168.5.194';
flush privileges;    /*刷新一下权限*/

This establishes user permissions table below, look at the server side, the command is:

select user,host from mysql.user;

3. write the following script on the server B

#!/bin/bash
my_user=why                                            #服务器B的用户(必须是已经授权的)
my_pass=123456                                      #服务器A的用户密码
my_host=192.168.5.193                            #要连接的服务器A
my_db1=TestDB                                        #想要导出的服务器A的数据库(需要授权)
mm_dir=/home/fabric/backup/t2.sql           #导出的地址
mysqldump_cmd=/usr/bin/mysqldump       #mysqldump的可运行指令地址

local_usr=root                                            #本地数据库的用户名
local_pass=000000                                    #本地数据库的密码
mysql_cmd=/usr/bin/mysql                        #mysql的可运行指令地址

$mysqldump_cmd -h $my_host -u $my_user -p$my_pass $my_db1 > $mm_dir
$mysql_cmd -u $local_usr -p$local_pass $my_db1 < $mm_dir

For testing at the command line, see if you can back up.
View data on the server A, here graphical tool mysql workbench (good use)


after running the script above, to view the data server B's.


/ Can see here backup success /

  1. Use crontab scheduled backup
    after crontab -e
1 * * * * ~/backupDatabases.sh

Such that the above command, the first minute of every hour, the database backup, of course, some time may be freely modified.

Guess you like

Origin www.cnblogs.com/whyaza/p/11118768.html