显示行号
|
选择喜欢的代码风格
默认
GitHub
Dune
LakeSide
Plateau
Vibrant
Blue
Eighties
Tranquil
将 MySQL 的数据导出 Excel,无需第三方工具,MySQL 命令行就自带了这样的功能,但这里需要注意一个 Can't create/write to file 及 The MySQL server is running with the --secure-file-priv option so it cannot execute this statement 的坑。
MySQL 数据命令行导出到 EXCEL
下面的 MySQL OUTFILE 后的双斜杠,是带转义识别目录。
# Windows 下
SELECT * FROM tab_mysql INTO OUTFILE 'D:\\CommandNotFound.xls';
如果数据是 UTF-8 编码,可能生成的 Excel 会乱码。用文本打开,以 ANSI 另存一下就 OK 了。
Lindex下执行直接写到路径即可,但这里有个坑:
# Linux 下
SELECT * FROM tab_mysql INTO OUTFILE '/Data/files/CommandNotFound.xls';
出现 1290 - The MySQL server is running with the --secure-file-priv option so it cannot execute this statement,以及 ERROR 1 (HY000): Can’t create/write to file '/Data/files/CommandNotFound.xls' (Errcode: 13),这个问题除了在 MySQL 里需要进行如下设置,要文件目录有些权限:
show global variables like '%secure%';
Variable_name Value
------------------------ --------
require_secure_transport OFF
secure_auth ON
secure_file_priv NULL
----------------------------------
#MySQL 新特性 secure_file_priv 对读写文件的影响
#此开关默认为 NULL,即不允许导入导出。
解决办法:
在 Windows 下,修改 my.ini,Linux 下修改 /etc/f,在 [mysqld] 内加入:
#也可以写你需要的指定路径
secure_file_priv =
然后重启 MySQL 即可。
MySQL 导出 Excel 文件扩展阅读:
发表评论