Welcome to Mysql2file documentation!

Mysql2file

Mysql2file 是一个 Mysql 数据库转换为表格文件的库。

快速

mysql2file 依赖于 PyArrow 库。 它是 C++ ArrowPython 版本实现。

PyArrow 目前与 Python 3.7、3.8、3.93.10 兼容。

如果您在 Windows 上遇到任何的导入问题或错误,您可能需要安装 Visual Studio 2015

警告: 对于 windows系统来说, PyArrow 目前只支持到 win64 位 ( Python 64bit ) 操作系统。

其次, 除了常见的 csvexcel、以及 json 文件格式之外, mysql2file 还支持导出 picklefeatherparquet 的二进制压缩文件。

picklefeatherparquetPython 序列化数据的一种文件格式, 它把数据转成二进制进行存储。 从而大大减少的读取的时间。

依赖

  • PyArrow 7.0.0

安装

pip install mysql2file

基本用法

快速开始

import os
from mysql2file import MysqlEngine

M = MysqlEngine(
    host=os.getenv('MYSQL_HOST', '127.0.0.1'),
    port=int(os.getenv('MYSQL_PORT', 3306)),
    username=os.getenv('MYSQL_USERNAME', 'root'),
    password=os.getenv('MYSQL_PASSWORD', '123456'),
    database=os.getenv('MYSQL_DATABASE', 'test_'),
    collection=os.getenv('MYSQL_COLLECTION', 'test_'),
)


def to_csv():
    result_ = M.to_csv(sql_="select * from test_ where id=4;")
    assert "successfully" in result_


def to_excel():
    result_ = M.to_excel()
    assert "successfully" in result_


def to_json():
    result_ = M.to_excel()
    assert "successfully" in result_


def to_pickle():
    result_ = M.to_pickle()
    assert "successfully" in result_


def to_feather():
    result_ = M.to_feather()
    assert "successfully" in result_


def to_parquet():
    result_ = M.to_parquet()
    assert "successfully" in result_

Reference

Todo

  • 加入多线程并发导出

  • 加入支持导出数据库中的所有表

  • 加入容错导出

致谢

License