[英]Automatic export database tables from mariadb to computer with .xlsx file format
I have to automatically generate a xlsx file of database tables from mariadb server to my computer server.我必须自动生成从 mariadb 服务器到我的计算机服务器的数据库表的 xlsx 文件。
so is there any script using I can generate xlsx file.那么是否有任何脚本使用我可以生成 xlsx 文件。
plz help!请帮忙!
Thank you!谢谢!
You can run a statement like this:您可以运行如下语句:
SELECT col1, col2, col3
FROM `your-db`.`your-table`
INTO OUTFILE 'C:/data.csv'
FIELDS TERMINATED BY ',' ENCLOSED BY '"' LINES TERMINATED BY '\r\n'
You should be able to open the CSV file with Excel without problems.您应该能够毫无问题地使用 Excel 打开 CSV 文件。
If you want to have this done automatically, you can create an event on your MariaDB server:如果您想自动完成此操作,您可以在 MariaDB 服务器上创建一个事件:
CREATE EVENT `automatic_export`
ON SCHEDULE
EVERY 1 DAY STARTS '2022-01-20 12:00:00'
ON COMPLETION PRESERVE
ENABLE
COMMENT 'Save Table to CSV for Excel'
DO BEGIN
SELECT col1, col2, col3
FROM `your-db`.`your-table`
INTO OUTFILE 'C:/data.csv'
FIELDS TERMINATED BY ',' ENCLOSED BY '"' LINES TERMINATED BY '\r\n';
END
It is important to check that the event scheduler is activated for events to work.检查事件调度程序是否已激活以使事件正常工作很重要。 So you must add the following line to your my.cnf
:因此,您必须将以下行添加到您的my.cnf
:
[mariadb]
...
event_scheduler = ON;
See: https://mariadb.com/kb/en/events/请参阅: https://mariadb.com/kb/en/events/
With this solution you won't need any external tools for your automatic export.使用此解决方案,您将不需要任何外部工具来进行自动导出。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.