doulao2916 2014-06-09 21:07
浏览 49

从MySQL生成SQLite 3数据库的一种好的,可维护的方法吗?

I have to generate on-the-fly (and let the user download) an SQLite 3 encrypted database, starting/cloning part of the current running MySQL database.

I need to export only a subset of the tables (i.e. products, categories, users), and I'd like to make the procedure dynamic, meaning that adding a field in MySQL shouldn't require changes in the procedure.

I need to some high-level "tips" to make the procedure as robust as possible.

Questions: how do I map column types in MySQL to SQLite types? How can I fetch metadata to determine the correct INSERT statements order? Should I need to lock MySQL database while dumping it into SQLite?

<?php

$sqlite = new PDO('sqlite::memory:', null, null, [
    PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
]);

$mysql = new PDO('mysql:host=127.0.0.1;dbname=database', 'root', 'root', [
    PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
]);

// Enable foreign keys in SQLite
$sqlite->exec('PRAGMA foreign_keys = 1');

// 1) Getting meta information from MySQL

// 2) CREATE TABLE ... in the SQLite schema, dynamically

// 3) INSERT INTO ... statements of SQLite (in the correct order)

// 4) Save the in-memory database to filesystem and send it to the browser
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 DIFY API Endpoint 问题。
    • ¥20 sub地址DHCP问题
    • ¥15 delta降尺度计算的一些细节,有偿
    • ¥15 Arduino红外遥控代码有问题
    • ¥15 数值计算离散正交多项式
    • ¥30 数值计算均差系数编程
    • ¥15 redis-full-check比较 两个集群的数据出错
    • ¥15 Matlab编程问题
    • ¥15 训练的多模态特征融合模型准确度很低怎么办
    • ¥15 kylin启动报错log4j类冲突