【问题标题】:how to get sql dump of a database created in sqlite using sqlalchemy如何使用 sqlalchemy 获取在 sqlite 中创建的数据库的 sql 转储
【发布时间】:2020-02-22 14:29:36
【问题描述】:

我从 json 读取数据,并使用 python 中的 sql-alchemy 将数据输入到具有适当架构的 sqlite 数据库中。 (为此使用了 pd.dataframe.to_sql() )。我想要这个数据库的数据库转储(.sql 文件)。 sql alchemy 中是否有任何 api 可以做到这一点?

【问题讨论】:

    标签: python mysql sqlite sqlalchemy flask-sqlalchemy


    【解决方案1】:

    假设您有一个与 SQLite 数据库关联的 SQLAlchemy engine 对象,您可以像这样简单地使用 Python 的 iterdump 方法:

    con = engine.raw_connection()
    with open('C:/Users/Gord/Desktop/dump.sql', 'w') as f:
        for line in con.iterdump():
            f.write('%s\n' % line)
    

    【讨论】:

    • 这里引用的iterdump是一个sqlite3函数。
    猜你喜欢
    • 2020-12-21
    • 1970-01-01
    • 2019-02-02
    • 2020-08-13
    • 1970-01-01
    • 2020-12-23
    • 2022-07-15
    • 1970-01-01
    • 2018-08-09
    相关资源
    最近更新 更多