工作中有时需要看某张表的所有数据,并且此时如果不太方便通过一些工具(比如navicat)处理,就需要通过into outfile 导出表的所有数据,并将数据呈现为类似excel的形式。相关命令如下:
1、导出数据(不指定分割符)
mysql> select * from class_info into outfile '/tmp/class_info.csv';
mysql> system cat /tmp/class_info.csv
11601a87
21601b90
31602d91
41602c85
51603e88
-------------------------------
2、导出数据,字段分隔符为",",字段引用符为“ " ”(双引号)
mysql> select * from class_info into outfile '/tmp/class_info_1.csv' fields terminated by "," enclosed by '"';
Query OK, 5 rows affected (0.00 sec)
mysql> system cat /tmp/class_info_1.csv
"1","1601","a","87"
"2","1601","b","90"
"3","1602","d","91"
"4","1602","c","85"
"5","1603","e","88"
3、导出数据,字段分隔符为",",数值型字段不加引用符,其余字段加引号
mysql> select * from class_info into outfile '/tmp/class_info_2.csv' fields terminated by "," optionally enclosed by '"';
Query OK, 5 rows affected (0.02 sec)
mysql> system cat /tmp/class_info_2.csv
1,1601,"a",87
2,1601,"b",90
3,1602,"d",91
4,1602,"c",85
5,1603,"e",88
4、数据恢复
使用load infile恢复
备份如第1种情况,恢复如下
mysql> load data infile '/tmp/class_info.csv' into table class_info;
备份如第2种情况,恢复如下
mysql> load data infile '/tmp/class_info_1.csv' into table class_info fields terminated by "," enclosed by '"';
备份如第3中情况,恢复如下
mysql> load data infile '/tmp/class_info_2.csv' into table class_info fields terminated by "," optionally enclosed by '"';
使用mysqlimport恢复
# mysqlimport -uroot -p tws /tmp/class_info.csv
Enter password:
tws.class_info: Records: 5 Deleted: 0 Skipped: 0 Warnings: 0
查看结果
# mysql -uroot -p -e "select * from tws.class_info"
当然,如果条件允许,能使用navicat 或者workbench 等工具获取MySQL表数据将更加方便。
匿名
2025-10-22
盖楼盖楼!
匿名
2025-08-11
沙发沙发
匿名
2025-08-10
https://at.oiik.cn/bing.html
匿名
2025-02-21
实用,我在开发https://minmail.app/时候使用到了
王飞翔
2024-12-30
亲爱的朋友:您好!中国疫情持续蔓延,很多人症状非常严重持久不愈,医院人满为患,各年龄段随地倒猝死的现象暴增,多省感染手足口、甲流、乙流、支原体、合胞及腺病毒的儿童不断攀升,目前各种天灾人祸,天气异象频发。古今中外的很多预言都说了这几年人类有大灾难,如刘伯温在预言中说 “贫者一万留一千,富者一万留二三”,“贫富若不回心转,看看死期到眼前”, 预言中也告诉世人如何逃离劫难的方法,真心希望您能躲过末劫中的劫难,有个美好的未来,请您务必打开下方网址认真了解,内有躲避瘟疫保平安的方法。网址1:https://github.com/1992513/www/blob/master/README.md?abhgc#1 网址2:bitly.net/55bbbb 网址3:https://d3ankibxiji86m.cloudfront.net/30gj 如打不开请多换几个浏览器试
匿名
2024-12-12
Backdata 搜索引擎网址提交入口:https://backdata.net/submit-site.html