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:\test\ |
+------------------+----------+
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中的\\

最新文章

  1. Android课程---关于Service的学习(后台运行)
  2. WebAPI生成可导入到PostMan的数据
  3. 封装pyMysql
  4. Trie树(c++实现)
  5. jQuery hide()并不等于hide(0)
  6. 5 Tips for creating good code every day; or how to become a good software developer
  7. 。。。HibernateTemplate与Session。。。
  8. mybatis-generator 代码自动生成工具
  9. HDU 2084 数塔(动态规划)
  10. GIT Learning
  11. FindStringExact
  12. 删除CentOS / RHEL的库和配置文件(Repositories and configuraiton files)
  13. mmap学习
  14. Eight
  15. Ext3和Ext4文件系统区别
  16. form表单action=&quot;&quot;的作用
  17. linux开机启动流程及需要开机启动服务讲解和修改及防火墙
  18. Linux系统的RAID磁盘阵列
  19. Ansible剧本介绍及使用演示(week5_day2)--技术流ken
  20. MFC入门(一)-- 第一个简单的windows图形化界面小程序(打开计算器,记事本,查IP)

热门文章

  1. python-基础入门-序
  2. ServiceStage-华为微服务开发与管理平台
  3. Route_of_Linux
  4. 美食vlog如何剪辑?用什么视频制作软件剪辑比较好?
  5. guitar pro系列教程(十三):Guitar Pro教程之打谱使用技巧
  6. 苹果电脑下载器Folx有没有自动下载功能
  7. 从本质上学会基于HarmonyOS开发Hi3861(主要讲授方法)
  8. Java中的主线程
  9. keras中seq2seq实现
  10. 获取qq头像