suntray

首先,mysql查询结果,可以导出文件,不可以直接导出成excel(虽然后缀名可以是xls)

第二,导出文件的sql语句如下:

select * into outfile \'/var/lib/mysql-files/test.xls\'  from temp_stu_ans_count  ORDER BY num desc;

sql其实就是

select * into outfile \'文件路径\'  from 表名及查询条件;

注意:

有可能执行的时候会报错

1.ERROR 1045 (28000): Access denied for user \'ispeak\'@\'%\' (using password: YES) 这个错误代表你的用户没有文件读写的权限,可以去授权(操作系统给用户授权),或者换个有读写权限的用户

2.ERROR 1290 (HY000): The MySQL server is running with the --secure-file-priv option so it cannot execute this statement  这个模式下,只能往指定目录下写文件,具体能写到哪,可以通过sql查看,sql语句如下:

show global variables like \'%secure%\';

结果如下

写到对应位置就可以了

3.同样的sql执行第二次会报错  :ERROR 1086 (HY000): File \'/var/lib/mysql-files/test.xls\' already exists  换一个文件名,或者去磁盘上删除这个文件就可以了

 

分类:

技术点:

相关文章: