版权声明:本文为博主原创文章,转载须注明出处,博客地址:https://blog.csdn.net/wx13227855087 https://blog.csdn.net/wx13227855087/article/details/82869330
(方式1)
在cmd中执行命令,格式如下:
mysql -hxx -uxx -pxx -e "query statement" dbName > file
-h:后面跟的是链接的host(主机)
-u:后面跟的是用户名
-p:后面跟的是密码
db:你要查询的数据库
file:你要写入的文件,绝对路径
例:将 sql语句 select * from yhxxb 的查询结果输出到了 C:/Users/dellpc/Desktop/test.xlsx 这个文件中。
mysql -h127.0.0.1 -uroot -proot -e "select * from yhxxb" test > C:/Users/dellpc/Desktop/test.xlsx
(方式2)
mysql -hxxx -uxx -pxx select * from table into outfile 'xxx.txt';
-h/-u/-p 的参数内容和上面一致, xxx.txt 是要输出的文件路径及其名称。
如:
-- 登录mysql mysql -h127.0.0.1 -uroot -proot -- 将查询结果输出到文件中 select * from yhxxb into outfile C:/Users/dellpc/Desktop/test.xlsx