简体   繁体   English

自动将数据库表从 mariadb 导出到具有.xlsx 文件格式的计算机

[英]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.

相关问题 自动将数据库表从 mariadb 服务器导出到 linux 服务器,文件格式为.csv - Automatic export database tables from mariadb server to a linux server with .csv file format 自动将数据从数据库导出到 CSV 文件 - automatic Export Data From Database to CSV File 我无法将从数据库中获取的数据导出到Node.JS中的Excel(.csv)或(xlsx)格式 - I'm not able to export the data, fetched from the Database to Excel (.csv) or (xlsx) format in Node.JS 将数据库 model 从 MySQLWorkbench 导出到 MariaDB PhpMyAdmin - Export database model from MySQLWorkbench to MariaDB PhpMyAdmin 错误:使用 Sqoop 将所有表从 MariaDB 导入 Hive 数据库时文件路径无效 - Error: Invalid file path while importing all tables from MariaDB to Hive Database using Sqoop 从Spring Roo自动生成数据库表 - Automatic generation of database tables from Spring Roo 将表/视图从mySQL数据库导出为打印机友好格式(phpMyAdmin除外)的方法 - Ways to export Tables/Views from mySQL Database to printer friendly format (other than phpMyAdmin) Java - XLSX 解析和数据库导出 - Java - XLSX parse & database export 以json格式输出数据库大小(来自Centos7的MariaDB) - Output Database size in json format (Mariadb from Centos7) 如何从mysql用空表导出数据库? - how to export database from mysql with empty tables?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM