简体   繁体   English

使用MySQL导入大型SQL文件

[英]Importing a large sql file with MySQL

I'm looking to do some social network analysis in the future. 我希望将来进行一些社交网络分析。 The data I have is stored in a sql file. 我拥有的数据存储在sql文件中。 I am trying to import it to MySQL running on my PC so I can take a look at some of it. 我正在尝试将其导入到PC上运行的MySQL,以便可以对其进行一些了解。 I just want to make sure I've done this right. 我只是想确保自己做对了。 Please see this imgur link. 请参阅此imgur链接。

http://i.imgur.com/C6n0XyJ.png http://i.imgur.com/C6n0XyJ.png

I only ask because it's been like that for over one hour, which I did expect, but there hasn't been any visual confirmation that it is actually working. 我只问这是因为我已经期待了一个多小时,但是没有任何视觉上的确认它确实在起作用。 "Importing now..." or something would have been nice, or a percentage counter. “立即导入...”或某些功能,或百分比计数器。

I know it's done something, because in a different command line window I did: 我知道它已经完成了某些事情,因为在另一个命令行窗口中,我做了:

mysql> show databases;

and 'tweetdata' did indeed appear in the list underneath the default MySQL tables (information_schema, mysql, etc.). 和“ tweetdata”确实确实出现在默认MySQL表(information_schema,mysql等)下的列表中。 I just want to make sure it hasn't just died and I did the right command to import the data! 我只是想确保它还没死,我做了正确的命令来导入数据!

PS Yes, you can all see the root password I made for my local SQL server which I made today and is running only on my PC at home with no data on it at all :) PS:是的,大家都可以看到我为今天的本地SQL服务器设置的root密码,该密码仅在家里的PC上运行,根本没有数据:)

Update: 更新:

Thanks for your input Tadman, glad to hear not giving any indication of progress is just how MySQL is. 感谢您的输入,Tadman,很高兴听到MySQL没有提供任何进展指示。 I had this error message after a while, though: 过一会儿,我收到此错误消息:

ERROR 1049 (42000): Unknown database 'disasters'

Here's a screenshot of what I'm looking at: http://i.imgur.com/GRRgAsm.jpg 这是我正在查看的屏幕截图: http : //i.imgur.com/GRRgAsm.jpg

But when I checked the folder, the tweetdata folder is 14.3GB in size, so I think the import probably worked? 但是当我检查文件夹时,tweetdata文件夹的大小为14.3GB,所以我认为导入可能有效吗? How can the db be unknown if it shows up in response to 如果db响应显示而如何未知

show databases;

?

Unfortunately you don't get much feedback when importing a database dump like that. 不幸的是,导入这样的数据库转储时,您不会得到太多反馈。 If it's created in transactional mode, you won't even see any data until it's been fully imported, too. 如果是在事务模式下创建的,那么在完全导入之前,您甚至都不会看到任何数据。

One way to see if it's doing anything is to look at the database directory where the raw table are stored and see which files are being created and how large they are getting. 一种查看是否正在执行任何操作的方法是查看存储原始表的数据库目录,并查看正在创建的文件以及文件的大小。 This is made easier with the file_per_table option . 使用file_per_table选项使此操作变得更容易。

My suggestion would be to try to divide the sql file into smaller chunks so that machine will be able to handle them or to try to do import inside mysql. 我的建议是尝试将sql文件分成较小的块,以便计算机能够处理它们或尝试在mysql内进行导入。 If you already done import, you may also look in the database itself, how much got imported. 如果已经完成导入,则还可以查看数据库本身中导入的数量。

Remember always to check on import if all tables and all records got imported. 请记住,始终要检查是否已导入所有表和所有记录的导入。

Splitting the SQL file 分割SQL档案

You cannot just arbitrarily split a file but have to take care of integrity of SQL statements, not to break them and also to have proper heading for the statements. 您不仅可以随意拆分文件,还必须照顾SQL语句的完整性,而不要破坏它们,还必须具有适当的标题。 Usually there is declaration, like 通常有宣言,像

--
-- Table structure for table `actions`
--

DROP TABLE IF EXISTS `actions`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `actions` (
 /* ... here goes table declaration

followed by 其次是

--
-- Dumping data for table `actions`
--

LOCK TABLES `actions` WRITE;
/*!40000 ALTER TABLE `actions` DISABLE KEYS */;
INSERT INTO `actions` VALUES
/* ... entries in brackets ending with comma

and ending with UNLOCK TABLES but your structure may vary. 并以UNLOCK TABLES结尾,但您的结构可能会有所不同。

The important thing is to break before declaration. 重要的是声明之前先中断。

Debugging practice would tell you to try to first split in half and try each import. 调试实践将告诉您尝试先分成两半,然后尝试每次导入。 If one or both fail, keep splitting until they succeed or you find where the problem lies. 如果一个或两个都失败,请继续进行分裂,直到它们成功您找到问题所在。

Use MySQL 使用MySQL

When you import database (or execute query) inside MySQL command line, you are not echoed for each successful record but for the whole table and that can also help you find the breaking point. 当您在MySQL命令行中导入数据库(或执行查询)时,不会为每个成功记录而是为整个表生成回显,这也可以帮助您找到切入点。

Take a look at database 看看数据库

You may also look at database and see which is last table or last record that get imported. 您还可以查看数据库,看看哪个是导入的最后一个表或最后一个记录。 That way you may also try to look at SQL and find / try to eliminate what was causing problem. 这样,您还可以尝试查看SQL并查找/尝试消除引起问题的原因。 By repeating you should end up with complete and proper input. 通过重复,您应该得到完整而正确的输入。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM