📄 1828.html
字号:
<TD><IMG height=1 src="images/spacer.gif" tppabs="http://www.linuxhero.com/docs/images/spacer.gif" width=98
border=0></TD>
<TD><IMG height=1 src="images/spacer.gif" tppabs="http://www.linuxhero.com/docs/images/spacer.gif" width=79
border=0></TD>
<TD><IMG height=1 src="images/spacer.gif" tppabs="http://www.linuxhero.com/docs/images/spacer.gif" width=103
border=0></TD>
<TD><IMG height=1 src="images/spacer.gif" tppabs="http://www.linuxhero.com/docs/images/spacer.gif" width=26
border=0></TD>
<TD><IMG height=1 src="images/spacer.gif" tppabs="http://www.linuxhero.com/docs/images/spacer.gif" width=1
border=0></TD></TR>
<TR>
<TD colSpan=3><A title=linux知识宝库
href="index.html" tppabs="http://www.linuxhero.com/docs/index.html"><IMG height=83
src="images/header_r1_c1.gif" tppabs="http://www.linuxhero.com/docs/images/header_r1_c1.gif" width=472 border=0
name=header_r1_c1></A></TD>
<TD colSpan=3>
<form action="http://www.linuxhero.com/docs/search.html" method=get>
<table
style="BORDER-RIGHT: #c4c4c4 1px solid; BORDER-TOP: #c4c4c4 1px solid; BORDER-LEFT: #c4c4c4 1px solid; BORDER-BOTTOM: #c4c4c4 1px solid"
cellspacing=0 cellpadding=3 width="95%" border=0 align="center">
<tbody>
<tr>
<td noWrap background="images/bgline.gif" tppabs="http://www.linuxhero.com/docs/images/bgline.gif">
<div align=center><font class=normalfont>搜索文章:
<input type=hidden value=result name=action2>
<input type=radio checked value=title name=type>标题
<input type=radio value=content name=type>内容
<input type=image src="images/button_go.gif" tppabs="http://www.linuxhero.com/docs/images/button_go.gif" border=0 name=image2>
</font></div>
</td>
</tr>
<tr>
<td noWrap>
<div align="center">
<input maxlength=100 size=30 name=keyword2>
</div>
</td>
</tr></tbody>
</table>
</form>
</TD>
<TD rowSpan=2><IMG src="images/header_r1_c7.gif" tppabs="http://www.linuxhero.com/docs/images/header_r1_c7.gif" width=26 border=0 name=header_r1_c7></TD>
<TD><IMG height=83 src="images/spacer.gif" tppabs="http://www.linuxhero.com/docs/images/spacer.gif" width=1 border=0></TD></TR>
<TR>
<TD background="images/bgline.gif" tppabs="http://www.linuxhero.com/docs/images/bgline.gif"><IMG height=22
src="images/header_r2_c1.gif" tppabs="http://www.linuxhero.com/docs/images/header_r2_c1.gif" width=296 border=0
name=header_r2_c1></TD>
<TD background="images/bgline.gif" tppabs="http://www.linuxhero.com/docs/images/bgline.gif" colSpan=5>
<DIV align=right><FONT class=normalfont>当前位置:
<A href="index.html" tppabs="http://www.linuxhero.com/docs/index.html">本站首页</A>
<font color="#FF6699">>></font>
<A href="type30.html" tppabs="http://www.linuxhero.com/docs/type30.html">mysql</A> | <A href="copyright.html" tppabs="http://www.linuxhero.com/docs/copyright.html">版权说明</A></font></DIV>
</TD>
<TD><IMG height=22 src="images/spacer.gif" tppabs="http://www.linuxhero.com/docs/images/spacer.gif" width=1
border=0></TD></TR></TBODY></TABLE>
<TABLE cellSpacing=10 cellPadding=0 width="100%" bgColor=#ffffff
border=0>
<TR>
<TD>
<TABLE cellSpacing=0 cellPadding=3 width="100%" border=0>
<TR>
<TD vAlign=top align=middle width="60%">
<TABLE cellSpacing=0 cellPadding=0 width="100%"
background="images/back.gif" tppabs="http://www.linuxhero.com/docs/images/back.gif" border=0>
<TBODY>
<TR>
<TD vAlign=top width="80%">
<DIV align=center>
<FORM action="search.html" tppabs="http://www.linuxhero.com/docs/search.html" method=get>
</FORM>
<TABLE cellSpacing=0 cellPadding=0 width="95%"
border=0><TBODY>
<TR>
<TD background="images/bgi.gif" tppabs="http://www.linuxhero.com/docs/images/bgi.gif"
height=30></TD></TR></TBODY></TABLE>
<TABLE cellSpacing=0 cellPadding=3 width="95%"
align=center border=0>
<TBODY>
<TR>
<TD>
<TABLE cellSpacing=0 cellPadding=3 width="100%"
border=0>
<TBODY>
<TR>
<TD vAlign=top>
<p><FONT class=normalfont><B><font color=blue>MySQL数据导入与导出</font></B></FONT><BR><FONT class=smallfont color=#ff9900>2004-04-23 15:18 pm</FONT><BR><FONT class=normalfont>作者:作者<br>来自:Linux知识宝库<br>联系方式:无名<br><br> 现在使用MySQL的越来越多了,我也用它做了自已的留言板。在使用过程中,<br>
慢慢地就要求对它的管理功能需要进一步地掌握,不仅是我,也是很多网友的要求。<br>
现在有一些问题是关于如何从MySQL中导出数据,以便用在本地或其它的数据库系统<br>
之上;以及将现有数据导入MySQL数据库中。现在就我学习的情况,就这两个问题作<br>
一下小结,内容不是很详细。其实MySQL的手册是很详细的,只不过我把有关这两方<br>
面的东西提取出来,加上了一点自已的理解,更详细的请参考数据库的相应章节。<br>
<br>
数据导出<br>
数据导出主要有以下几种方法:<br>
1. 使用select into outfile 'filename'语句<br>
2. 使用mysqldump实用程序<br>
<br>
1. 使用select into outfile 'filename'语句<br>
可以在mysql的命令行下或在php程序中执行它。我下面以在mysql命令行下为例。<br>
在php中使用时,将其改成相应的查询进行处理即可。不过在使用这个命令时,要求<br>
用户拥有file的权限。如我们有一个库为phptest,其中有一个表为driver。现在要<br>
把driver卸成文件。执行命令:<br>
mysql> use phptest;<br>
Database Changed<br>
mysql> select * from driver into outfile 'a.txt';<br>
Query OK, 22 rows affected (0.05 sec)<br>
上面就可以完成将表driver从数据库中卸到a.txt文件中。注意文件名要加单<br>
引号。那么这个文件在哪呢?在mysql目录下有一个data目录,它即是数据库文件所<br>
放的地方。每个库在单独占一个子目录,所以phptest的目录为c:mysqldataphptest<br>
(注意:我的mysql安装在c:mysql下)。<br>
好,现在我们进去,a.txt就是它。打开这个文件,可能是:<br>
1 Mika Hakinnen 1<br>
2 David Coulthard 1<br>
3 Michael Schumacher 2<br>
4 Rubens Barrichello 2<br>
...<br>
可能还有很多记录。每个字段之间是用制表符分开的( )。那么我们可以修<br>
改输出文件名的目录,以便放在指定的位置。如'a.txt'可以改成'./a.txt'或<br>
'/a.txt'。其中'./a.txt'放在c:mysqldata目录下了,而'/a.txt'文件则放在c:<br>
目录下了。所以select命令认为的当前目录是数据库的存放目录,这里是<br>
c:mysqldata。<br>
使用select命令还可以指定卸出文件时,字段之间的分隔字符,转义字符,<br>
包括字符,及记录行分隔字符。列在下面:<br>
FIELDS TERMINATED BY ' '<br>
[OPTIONALLY] ENCLOSED BY ''<br>
ESCAPED BY ''<br>
LINES TERMINATED BY ''<br>
<br>
FIELDS TERMINATED表示字段分隔;[OPTIONALLY] ENCLOSED表示字段用什么字<br>
符包括起来,如果使用了OPTIONALLY,则只有CHAR和VERCHAR被包括;ESCAPED表示<br>
当需要转义时用什么作为转义字符;LINES TERMINATED表示每行记录之间用什么分<br>
隔。<br>
上面列的是缺省值,而且这些项都是可选的,不选则使用缺省值。可以根据<br>
需要进行修改。给出一个例子如下:<br>
mysql> select * from driver into outfile 'a.txt' fields terminated by <br>
',' enclosed by '"';<br>
Query OK, 22 rows affected (0.06 sec)<br>
结果可能如下:<br>
"1","Mika","Hakinnen","1"<br>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -