您的位置 首页 数据库

mysql 查询数据导出到文件into outfile ‘/tmp/alter.sql’

需求:把查询语句的结果保存到文件

into outfile '/tmp/alter.sql'

一般这种外部路径 会被关闭, 涉及到安全(文件上传)

可以放到数据库本身存放的路径。

into outfile '/data/3306/data/alter.sql'

 

如果 非要放到其他路径,可以在my.cnf 中添加参数:

vim /etc/my.cnf
[mysqld]
secure-file-priv=/tmp
-- 修改配置文件参数信息,实现将数据库操作的数据信息导入到系统文件中,配置完毕重启数据库服务
mysql> source /tmp/alter.sql
-- 可以对不是innodb存储引擎的表做操作,实现数据表批量化引擎修改,调用数据库脚本信息

 

 

 

select concat("alter table ",table_schema,".",table_name," engine=innodb;") from information_schema.tables where table_schema not in ('mysql','sys','performance_schema','information_') and  engine!='innodb' into outfile '/tmp/alter.sql';  
ERROR 1290 (HY000): The MySQL server is running with the --secure-file-priv option so it cannot execute this statement

 

欢迎来撩 : 汇总all

白眉大叔

关于白眉大叔linux云计算: 白眉大叔

热门文章