How to import a BIG SQL file into a rails database? [duplicate]

谁说我不能喝 提交于 2019-12-24 04:37:19

问题


I've got a quite huge (> 8mo) sql file that basically creates 2 tables and populate them with data. It's a dump generated from Sequel Pro. My first idea was to read the file line by line and run an "execute" command, but I've got an error that my string was too big.

Mysql2::Error: Got a packet bigger than 'max_allowed_packet' bytes

Is there any way to run directly the SQL file instead of reading it and try to execute ?
FYI I can split this file in 2 parts for the 2 tables, but I'll have an other one a lot bigger after and that can't be splited.
I'm using Rails 3.0.3 with ActiveRecord and a MySQL Database.


回答1:


Is it a proper SQL file (with SQL statements in it) ?

If so, you should be able to do this on the command line:

mysql target-db-name < sql-file-name.sql -uuser -p

Hit return, it'll prompt you for password and you're off

Remember to substitute in proper values for target-db-name, sql-file-name.sql and user

Note: target-db-name should be created beforehand: I don't think it will auto-create



来源:https://stackoverflow.com/questions/5349636/how-to-import-a-big-sql-file-into-a-rails-database

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!