35.MySQL导出数据的几种方式

1.导出全表数据。
select * from test into outfile '/tmp/a.sql';
2.导出某个数据库下的表。
--secure-file-priv='' 
mysqldump -T /data/backup -u root -prootroot --set-gtid-purged=OFF  test
将test数据库导出到:backup目录下。

3.导出自定义格式的文件。
mysql -uroot -prootroot -e "select * from t2;" test > t2.sql 
id    name    age
1    NULL    18
2    xsq2    18
3    xsq3    18
4    xsq4    18
5    xsq5    18

4.输出垂直列的结果。
mysql -uroot -prootroot --vertical -e "select * from t2;" test > t2_3.sql 
*************************** 1. row ***************************
  id: 1
name: NULL
 age: 18
*************************** 2. row ***************************
  id: 2
name: xsq2
 age: 18

5.导出htm格式。
mysql -uroot -prootroot --html -e "select * from t2;" test > t2_4.html 

6.导出xml 格式。
mysql -uroot -prootroot --xml -e "select * from t2;" test > t2_5.xml 
<?xml version="1.0"?>
<resultset statement="select * from t2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <row>
    <field name="id">1</field>
    <field name="name" xsi:nil="true" />
    <field name="age">18</field>
  </row>
<?xml version="1.0"?>

7.生成操作日志:
mysql>tee a.log 
mysql>select * from t2; 
mysql>notee 

8.数据导入。
mysql>  load data infile '/data/backup/t2.txt' into table test.t2;
或者:
load data local infile 'data.log' into table data_log field terminated by '|' lines terminated by '\n' (col1,col2,col3);

--将t2表导入test数据库中。
mysqlimport -uroot -prootroot test '/data/backup/t2.txt'
或者:
time mysqlimport -uroot -prootroot test '/data/backup/t2.txt'
 

  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值