awakenedy

1)mysql连接+将查询结果输出到文件。在命令行中执行(windows的cmd命令行,mac的终端)

mysql -hxx -uxx -pxx -e "query statement" db > file 

  -h:后面跟的是链接的host(主机)

  -u:后面跟的是用户名

  -p:后面跟的是密码

  db:你要查询的数据库

  file:你要写入的文件,绝对路径

例如:

  下面将 sql语句 select * from edu_iclass_areas 的查询结果输出到了 /Users/zhengcanrui/WORK/test/test.xls 这个文件中。

mysql -h127.0.0.1 -uroot -p123 -e "select * from edu_iclass_areas" test > /Users/zhengcanrui/WORK/test/test.xls

2)mysql连接 和 将查询结果输出到数据库分开执行

mysql -hxxx -uxx -pxx 

select * from table into outfile \'xxx.txt\'; 

  -h/-u/-p 的参数都没的内容和上面一致, xxx.txt  是要输出的文件路径及其名称。

如:

-- 登录mysql
mysql -h127.0.0.1 -uroot -p123 

-- 将查询结果输出到文件中
select * from edu_iclass_areas  into outfile /Users/zhengcanrui/WORK/test/test.xls 

  上面两种的执行效果是等价的。

分类:

技术点:

相关文章:

  • 2021-12-12
  • 2022-12-23
  • 2021-09-06
  • 2021-06-18
  • 2021-12-14
  • 2021-12-08
  • 2021-12-04
猜你喜欢
  • 2021-11-01
  • 2021-12-02
  • 2022-12-23
  • 2021-12-02
  • 2022-12-23
  • 2022-01-31
相关资源
相似解决方案