user53029
user53029

Reputation: 695

How to Import MySQL dump file with Red Hat 6

I have a VM that I'll be installing mysql server on. I have a dump file that I need to import into 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. 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. So can I just rename my .txt file to .sql or just import as is? What would the command look like? I am really a noob when it comes to MySQL so any guidance is much appreciated.

Upvotes: 0

Views: 1075

Answers (2)

Josh Rumbut
Josh Rumbut

Reputation: 2710

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:

mysql -uroot -p database_name < filename.dump

Upvotes: 1

DreamWave
DreamWave

Reputation: 1940

You command is correct. The extension of the filename is not important. It is what's inside that matters.

Upvotes: 1

Related Questions