Home  >  Article  >  Database  >  数据库中导出表中相应字段到指定文件中

数据库中导出表中相应字段到指定文件中

PHPz
PHPzOriginal
2016-06-07 15:56:441129browse

数据库中导出某一个表中需要的字段到文件中是公司中经常要做到的事,那怎么实现呢? 比如你要查询enterpriseaics中的所有字段的值到d盘的aa.txt中去,注:aa.txt不能存在,否则会报错。 span style=font-size:18px;select * from enterpriseaics into outfil 

数据库中导出某一个表中需要的字段到文件中是公司中经常要做到的事,那怎么实现呢?

比如你要查询enterpriseaics中的所有字段的值到d盘的aa.txt中去,注:aa.txt不能存在,否则会报错。

select * from enterpriseaics into outfile 'd:\\aa.txt' ;

当然如果你想规范一下格式,例如:每个字段的值之间以逗号分开,每一行换行,每个字段的值要引号引起来。那么就要加上下面的一段话:

select * from enterpriseaics into outfile 'd:\\aa.txt' fields terminated by ',' enclosed by '"' ;

当然,这是在本地数据库中导出的,那么在本地通过secureCRT连接linux数据库要导出数据时就要指明导出路径了,不然会报没有写权限的错误。

select * from enterprisetype into outfile '/var/lib/mysql/enterprisetype.txt' fields terminated by ',' enclosed by '"' ;

本人亲测,这个/var/lib/mysql路径可以导出数据

更多相关教程请访问 MySQL视频教程

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn