Home  >  Article  >  Database  >  mysql如何把在屏幕上输出的结果输出到一个文件上?_MySQL

mysql如何把在屏幕上输出的结果输出到一个文件上?_MySQL

WBOY
WBOYOriginal
2016-06-01 11:52:38806browse

1、如果MYSQL服务器就是你要导出文件的机器,那么可以直接用

select ...into outfile
语句。
例:
select * from rank into outfile "/home/a.txt"

2、如果MYSQL服务器是单独的机器,我们是在一个client上进行操作,我们要把数据结果导入到client机器上。可以使用mysql -e语句。
例:
mysql -uroot -proot -P3310 -h10.1.2.3 dbname -e "select * from rank" > /home/a.txt



3、使用mysql的tee(\T)命令,也就是把MYSQL的所有输出都输入到指定文件。
例:

mysql>tee /home/a.txt
mysql>select * from rank;
mysql>exit


mysql -uroot -p dbname -e "select * from user_role_new ; show profile cpu , block io for query 15" > ~/aa.txt




备份命令

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