如何导入一个大的SQL文件到轨数据库? [英] How to import a BIG SQL file into a rails database?

查看:173
本文介绍了如何导入一个大的SQL文件到轨数据库?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个相当庞大(> 8mo)SQL基本上创建2表和填充数据文件。这是一个从续集临生成的转储。 我的第一个想法是逐行读取文件中的行,并运行一个运行命令,但我有一个错误,我的字符串太大。

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 ::错误:得到比一个大包max_allowed_pa​​cket的字节

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

有没有什么办法可以直接运行阅读它的SQL文件,而不是和尝试执行?
仅供参考,我可以分成2部分为2表这个文件,但我会一直等一个接大了很多,并不能splited。
我用Rails 3.0.3用ActiveRecord和MySQL数据库。

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.

推荐答案

这是个正确的SQL文件(使用SQL语句的话)?

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

记得在适当的值来代替目标DB-名,SQL-文件名.sql和用户

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

注:目标DB-name应该预先创建:我不认为它会自动创建

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

这篇关于如何导入一个大的SQL文件到轨数据库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆