(1)导出整个数据库(包括数据库中的数据)
mysqldump -u username -p dbname > dbname.sql
(2)导出数据库结构(不含数据)
mysqldump -u username -p -d dbname > dbname.sql
(3)导出数据库中的某张数据表(包含数据)
mysqldump -u username -p dbname tablename > tablename.sql
(4)导出数据库中的某张数据表的表结构(不含数据)
mysqldump -u username -p -d dbname tablename > tablename.sql
导出多张表实例
mysqldump -u root -p spider_test1 question question_text > spider_test1_question_11_18.sql
mysqldump命令中带有一个 --where/-w 参数,它用来设定数据导出的条件,使用方式和SQL查询命令中中的where基本上相同,有了它,我们就可以从数据库中导出你需要的那部分数据了。
命令格式如下:
mysqldump -u用户名 -p密码 数据库名 表名 --where="筛选条件" > 导出文件路径
将数据库中内容保存到文本文件中去但是不保留sql语句. 使用-e参数 shell模式.
mysql -e 'use question_db; select id,chapter ,point from question limit 100' > 1.txt;
(1) 进入到备份数据所在的目录 ( 我这里是xyt_full_1207.sql所在目录)
(2) 登录mysql 执行 source xxx.sql 导入
mysql -u gw -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 4 Server version: 5.7.23-0ubuntu0.18.04.1 (Ubuntu) Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql> source xyt_full_1207.sql