I would like to export a database from PHPMyAdmin (or MySQl Workbench) and import it to a SQLite database so that I can do local editing and testing without screwing up the live version. I am very new to SQL, so all of the export options, etc, are rather dense to me at this point. I have tried using the default export settings PHPMyAdmin with the command
我想从PHPMyAdmin(或MySQl工作台)导出一个数据库,并将它导入到一个SQLite数据库,这样我就可以进行本地编辑和测试,而不需要对live版本进行修改。我对SQL非常陌生,所以在这一点上,所有的导出选项等等对我来说都非常密集。我已经尝试使用默认的导出设置phpadmin和命令
sqlite3 test_db.db < maindb.sql
as well as
以及
sqlite3--> .read maindb.sql
But these throw a bunch of syntax errors and 'no such table' errors.
但是,这些错误会抛出大量语法错误和“没有此类表”错误。
I have also tried the oft-cited script script found here, but when I try to run this using an export from MySQL Workbench, using the command:
我也尝试过这里常见的脚本脚本,但是当我尝试使用MySQL Workbench中的导出来运行这个脚本时,使用以下命令:
943776/mysql2sqlite.sh maindb.sql | sqlite3 test_db.sqlite
I get the following error:
我得到以下错误:
mysqldump: Got error: 2002: Can't connect to local MySQL server through socket '/var/run/mysql.sock' (2) when trying to connect
Am I not configuring the exports correctly?
我没有正确配置导出吗?
2 个解决方案
#1
3
Please see that the referenced script connects to the database server itself. It does not expect a dump!
请参见所引用的脚本连接到数据库服务器本身。它不需要转储!
./mysql2sqlite -h example.com -u root -pMySecretPassWord myDbase | sqlite3 database.sqlite
This is the way the script should be executed. With host, username, passwort and the mysql database you would like to dump.
这就是应该执行脚本的方式。使用您想要转储的主机、用户名、passwort和mysql数据库。
Since database dumps and DBMS features can be severely different between different DBMS (like MySQL and sqlite3), I would recommend to install a local MySQL server instead of using sqlite3. What advantage have you achieved when you make changes to sqlite3, which you cannot apply to the MySQL production database without changes?
由于数据库转储和DBMS特性在不同的DBMS(如MySQL和sqlite3)之间可能存在严重的差异,所以我建议安装一个本地MySQL服务器,而不是使用sqlite3。当您对sqlite3进行更改时,您获得了什么优势?
#2
1
An alternative solution is to export an sql dump of your database and then import it back into phpLiteAdmin. From there you can manage your sqlite database inside your browser. When you want to export it, just open the folder where the database is stored and copy the database file.
另一种解决方案是导出数据库的sql转储,然后将其导入phpLiteAdmin。从那里,您可以在浏览器中管理您的sqlite数据库。当您想要导出它时,只需打开数据库存储和复制数据库文件的文件夹。
This solution does not require messing around with scripts, and it's especially handy if you're on a Mac and you're using MAMP, since phpLiteAdmin comes preinstalled with it.
这个解决方案不需要使用脚本,如果你在Mac电脑上,而且你在使用MAMP,因为phpLiteAdmin预装了它,它就特别方便。
#1
3
Please see that the referenced script connects to the database server itself. It does not expect a dump!
请参见所引用的脚本连接到数据库服务器本身。它不需要转储!
./mysql2sqlite -h example.com -u root -pMySecretPassWord myDbase | sqlite3 database.sqlite
This is the way the script should be executed. With host, username, passwort and the mysql database you would like to dump.
这就是应该执行脚本的方式。使用您想要转储的主机、用户名、passwort和mysql数据库。
Since database dumps and DBMS features can be severely different between different DBMS (like MySQL and sqlite3), I would recommend to install a local MySQL server instead of using sqlite3. What advantage have you achieved when you make changes to sqlite3, which you cannot apply to the MySQL production database without changes?
由于数据库转储和DBMS特性在不同的DBMS(如MySQL和sqlite3)之间可能存在严重的差异,所以我建议安装一个本地MySQL服务器,而不是使用sqlite3。当您对sqlite3进行更改时,您获得了什么优势?
#2
1
An alternative solution is to export an sql dump of your database and then import it back into phpLiteAdmin. From there you can manage your sqlite database inside your browser. When you want to export it, just open the folder where the database is stored and copy the database file.
另一种解决方案是导出数据库的sql转储,然后将其导入phpLiteAdmin。从那里,您可以在浏览器中管理您的sqlite数据库。当您想要导出它时,只需打开数据库存储和复制数据库文件的文件夹。
This solution does not require messing around with scripts, and it's especially handy if you're on a Mac and you're using MAMP, since phpLiteAdmin comes preinstalled with it.
这个解决方案不需要使用脚本,如果你在Mac电脑上,而且你在使用MAMP,因为phpLiteAdmin预装了它,它就特别方便。