• 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

  • 相关阅读:
    Mesos 配置项解析
    1039. Course List for Student (25)
    Cts框架解析(12)-ITargetPreparer
    通过ulimit改善linux系统性能(摘自IBM)
    HDU 1080 DP
    C语言调用Lua函数
    创建MySQL从库
    C# Func<>托付
    SpringMVC入门
    VNC连接Ubuntu 16.04桌面灰色的问题解决
  • 原文地址:https://www.cnblogs.com/justinzhang/p/4777761.html
Copyright © 2020-2023  润新知