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

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

PHPz
PHPzOriginal
2016-06-07 15:56:441131Durchsuche

数据库中导出某一个表中需要的字段到文件中是公司中经常要做到的事,那怎么实现呢? 比如你要查询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视频教程

Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn
Vorheriger Artikel:AIX中常用的SMIT的使用Nächster Artikel:ODBC、OLEDB和ADO之间的关系