问题
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