Mysql查询结果导出为Excel

Example:

select * into outfile ‘/data/var-3307/catid.xls’ from help_cat where 1 order by cat_id desc limit 0,20;

select * into outfile ‘导出文件存放目录’ from 表面和查询条件等信息!

mysql数据导出权限问题

select * into outfile “file_path” from my_table

上面的语句是mysql导出数据的一种方式,在使用普通用户执行语句时,出现了错误 前面已经对该用户在对应的数据库上执行了授权
但是mysql有单独的file权限,需要单独赋予,同时file是一个全局权限,不能够仅仅将单个数据库的文件权限赋予用户
执行以下语句 > grant file on . to my_user

MYSQL导出数据出现The MySQL server is running with the –secure-file-priv option so it cannot execute this

show variables like ‘%secure%’; 查看 secure-file-priv 当前的值是什么

mysql默认值为

“C:\ProgramData\MySQL\MySQL Server 8.0\Uploads”

通过打开my.ini配置文件进行查看及修改: 将secure-file-priv=改为自己想要的路径 在我们修改此配置文件的内容之后,例如修改了secure-file-priv的默认值,要想使其生效,我们必须关闭 MySQL 然后重新启动。
关闭 MySQL 并不是指简单的用exit命令退出 MySQL 或者关闭 MySQL 窗口,而是关闭 MySQL 服务,然后重新启动服务。

mysql重启服务

  1. Windows下

启动服务

mysqld –console

或 net start mysql   关闭服务

mysqladmin -uroot shudown

或 net stop mysql

  1. Linux下

启动服务

service mysql start     关闭服务

service mysql stop  

重启服务

service restart stop 

net start mysql; 服务名无效。 请键入 NET HELPMSG 2185 以获得更多的帮助

windows+r, 打开运行,输入services.msc, 找到mysqlde服务

右键属性,发现服务器名称是MySQL80

重新回到管理员:命令提示符,输入net start mysql80

cryptography is required for sha256_password or caching_sha2_password

报错原因:MySQL8.0版本以后采用caching_sha2_password作为默认的身份验证插件。

ha256_password 和 caching_sha2_password 这两个加密算法需要用到 cryptography 。意思很明了,这是模块未安装引发的异常

解决办法:

pip install cryptography

参考文章: https://www.2cto.com/database/201411/351784.html https://blog.csdn.net/zhengwish/article/details/79217161 https://www.cnblogs.com/microcat/p/6610963.html https://blog.csdn.net/wangpailiulanqi8/article/details/82424609 https://blog.csdn.net/dandanben/article/details/88964109