wanderingfish

mysql 导出文件

  • 在数据库中导出文件:

select * from tb_test01 into outfile \'test.txt\';
ERROR 1290 (HY000): The MySQL server is running with the --secure-file-priv option so it cannot execute this statement
需要在配置文件/etc/my.cnf
加入:
secure_file_priv=/tmp
这个时候可以把文件导入到到/tmp 文件夹内
select * from tb_test01 into outfile \'/tmp/test.txt\';

  • 命令行:

mysql -uroot -p -e "select * from data1.tb_test01 where id=1;" > /tmp/test01.txt

  • 导出整个表:

mysqldump -uroot -p data1 tb_test01 > test01.txt
或者整个数据库: mysqldump -uroot -p data1 > test01.txt

  • 导入数据库:

mysql -uroot -p data1 < test01.txt
或者进入mysql: source /tmp/test01.txt

分类:

技术点:

相关文章: