当前位置:   article > 正文

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

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'
 

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/盐析白兔/article/detail/807937
推荐阅读
相关标签
  

闽ICP备14008679号