简体   繁体   English

如何使用Red Hat 6导入MySQL转储文件

[英]How to Import MySQL dump file with Red Hat 6

I have a VM that I'll be installing mysql server on. 我有一个要在其上安装mysql服务器的VM。 I have a dump file that I need to import into mysql. 我有一个导入到mysql的转储文件。 The first line says this: 第一行说:

-- MySQL dump 10.13  Distrib 5.6.20, for linux-glibc2.5 (x86_64)

The file already has databases and tables, along with the structure and data. 该文件已经具有数据库和表,以及结构和数据。

 grep -i 'current database' db_dump.txt 
-- Current Database: `db1`
-- Current Database: `db2`
-- Current Database: `db3`

grep -i 'data for table' db_dump.txt 
-- Dumping data for table `TABLE1`
-- Dumping data for table `TABLE2`
-- Dumping data for table `TABLE3`

As you can see, its a .txt file and this is partly where my confusion is coming in. Much of what I have read is that in order to import a text file you must already have the database's and tables created. 如您所见,它是一个.txt文件,这在某种程度上引起了我的困惑。我读到的大部分内容是,要导入文本文件,您必须已经创建了数据库和表。 However they are already defined in the file. 但是,它们已在文件中定义。 So that lead me to running a command such as this: 这样就导致我运行如下命令:

mysql -u <user> -p < filename.dump

But some of the documentation says you must have a .sql file in order to do this. 但是某些文档说您必须具有.sql文件才能执行此操作。 So can I just rename my .txt file to .sql or just import as is? 那么我可以将.txt文件重命名为.sql还是直接导入? What would the command look like? 该命令是什么样的? I am really a noob when it comes to MySQL so any guidance is much appreciated. 对于MySQL来说,我真的是个菜鸟,因此,对任何指导都非常感谢。

You command is correct. 您的命令是正确的。 The extension of the filename is not important. 文件名的扩展名并不重要。 It is what's inside that matters. 重要的是内部。

Oh! 哦! There is actually one thing that needs to change: 实际上,有一件事情需要改变:

mysql -u<username> -p database_name < filename.dump

The database name should be the last part of the command and the username needs to go after -u , so if you are the root user you should type: 数据库名称应该是命令的最后一部分,用户名必须在-u之后,因此,如果您是root用户,则应该键入:

mysql -uroot -p database_name < filename.dump

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

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