• mysqldump备份数据


    create database test;
    use test;
    create table test(id int,name char(8));
    insert into test values(1,'peter');

    mysql服务bin目下执行:

    1. 备份数据

    mysqldump --opt -uroot -p123456 test > test.dump

    2. 从备份文件恢复数据,需要先建立好数据库test

    mysql -uroot -p123456 test < test.dump

    3. 只备份表结构

    mysqldump --no-data -uroot -p123456 test > test-nodata.dump

    4. 备份多个数据库

    mysqldump --opt -uroot -p123456 --databases test test2 test3> test.dump

         导入多个库数据

    mysql -uroot -p123456 < test.dump

    5. 跨机器备份数据,源端mysql服务器src_host_ip,目标端mysql服务器dsc_host_ip

    目标mysql端建立提供远程访问的用户,并赋予数据库权限

    create database test
    create user root@'src_host_ip' identified by '123456';
    grant all privileges on *.* to root@'src_host_ip' identified by '123456';

    源端mysql拷贝数据

    mysqldump --opt -uroot -p123456 test |mysql -uroot -p123456 -hdsc_host_ip test

     6. 与mysqlimport结合使用,备份大表

    执行备份之前,先在两台host上执行如下命令:

    mysql> show variables like '%secure_file%';
    +------------------+----------+
    | Variable_name    | Value    |
    +------------------+----------+
    | secure_file_priv | e:	est |
    +------------------+----------+
    1 row in set, 1 warning (0.00 sec)

    如果secure_file_priv值为NULL,在mysql服务器配置文件my.ini中增加一项,并重启服务器

    secure-file-priv=e:/test

    源服务器上执行以下命令,备份test2数据库,并将e:/test文件夹备份到目标服务器上同一目录

    mysqldump -uroot -p123456 --tab=e:/test test2

    目标服务器上,执行以下命令:

    >type e:\test\test2.sql | mysql -uroot -p123456 test2
    mysql: [Warning] Using a password on the command line interface can be insecure.
    
    >mysqlimport -uroot -p123456 test2 e:/test/test2.txt
    mysqlimport: [Warning] Using a password on the command line interface can be ins
    ecure.
    test2.test2: Records: 1  Deleted: 0  Skipped: 0  Warnings: 0
    
    >mysqladmin -uroot -p123456 flush-privileges

    注意:mysqlimport中涉及到的e:/test/test2.txt路径前缀e:/test/一定要写,与secure-file-priv一致

       type命令类似Linux中的cat,后面的路径得用windows中的\

  • 相关阅读:
    母函数做的题
    HDU2089 暴力打表
    HDU2036 改革春风吹满地
    HDU1201 水题
    高可用服务 AHAS 在消息队列 MQ 削峰填谷场景下的应用
    Nacos Committers 团队首亮相,发布 0.9.0 版本
    Dubbo Mesh 在闲鱼生产环境中的落地实践
    Watchdogs利用Redis实施大规模挖矿,常见数据库蠕虫如何破?
    阿里在使用一种更灵活的软件集成发布模式
    2019 年,容器技术生态会发生些什么?
  • 原文地址:https://www.cnblogs.com/darange/p/10445299.html
Copyright © 2020-2023  润新知