网络营销电子商务研究中心  
How to buy the best prescription safety glasses in Canada? Let's study!
Go Back   网络营销电子商务研究中心 > 服务器与数据库 > MySQL
User Name
Password
 
FAQ Members List Calendar Cheap Glasses

Reply
 
Thread Tools Display Modes
  #1   IP: 199.115.98.59
Old 2016-07-18, 11:38 AM
Ravendale Ravendale is offline
初级会员
 
Join Date: 2012-01-13
Posts: 1
Ravendale 现在声名狼藉
Default mysql把查询结果保存为sql文件或txt文件

在mysql中如果我们要把查询导出来保存.sql文件我们可以使用into outfile或mysql -uroot -p 就可以实现了,下面我来给大家介绍介绍。

1.新建查询语句文件query.sql,内容如下:
代码如下
use appdb;
set names utf8;
select FeedID, City , Message from Feed limit 1000;

上面的set names utf8语句是设施当前使用的编码,如果编码和数据库的编码不一致,会出现乱码
2.执行如下:

代码如下
[root@proxy tianqg]# mysql -uroot -p < query.sql > query.txt
回车,输入密码,在当前目录下会产生查询结果文件query.txt
上面生成的txt文件如果要保存成.sql文件我们可如下操作
在服务器端可以用select into outfile 命令把查询结果保存到一个可写的目录中:
代码如下

mysql> select * from article limit 150 into outfile '/test/article.sql';
Query OK, 150 rows affected (0.01 sec)
然后把article.sql文件下载到本地电脑上,通过load data local infile into table 命令来导入这个查询结果文件:
代码如下

load data local infile "D:/study/article.sql" into table cmstop_article;
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 2 (0 members and 2 guests)
 

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Prescription-glasses.com offers prescription glasses online at discount prices.
All times are GMT +8. The time now is 09:18 AM.


Powered by vBulletin Version 3.8.7
Copyright ©2000 - 2026, Jelsoft Enterprises Ltd.