Mysql数据迁移

待迁移的数据库如下:

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| forbk              |
| hive               |
| mysql              |
| test               |
+--------------------+
5 rows in set (0.00 sec)

mysql> use forbk
Database changed
mysql> create table `back_table` ( x int, y int);
Query OK, 0 rows affected (0.01 sec)

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

mysql> select * from back_table;
+------+------+
| x    | y    |
+------+------+
|   12 |   13 |
+------+------+
1 row in set (0.00 sec)

mysql>

待迁移的数据库配置如下,可以发现mysql数据文件存放在:datadir=/var/lib/mysql中

[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
user=mysql
character_set_server=utf8
init_connect='SET NAMES utf8'
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0

[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid

[mysql]
default-character-set=utf8
#bin-long=justin-bin
                                                                                                                                                  
"/etc/my.cnf" 16L, 364C

image

现在将这个数据库的forbak库迁移到另外一台机器上:

直接将/var/lib/mysql/forbk这个文件拷贝到另外一台机器的datadir目录下,image

不用重启mysql服务,就可以动态的看到forbk库已经成功的迁移到到目标机器:

image

注意:通过拷贝文件的方式备份数据库,不会在binlog中有记录。但是当备份完成后,再对备份过来的库进行update,insert、delete操作时,会触发binlog;

image

posted @ 2015-09-02 10:01  justinzhang  阅读(273)  评论(0编辑  收藏  举报