0

I have a .sql file with some database backups inside. Now I want to restore them back to MySQL. How can I this using command line of MySqL please? I found this:

mysql -u username -p -h localhost database_name < dumpfile.sql  

but I don't know what username should be, what database_name should be and how I could browse to a .sql file in another folder.

7
  • You need the username in order to login so MySQL can check the account for privileges to make sure the account is allowed to do it. Commented May 24, 2010 at 0:27
  • I'm having an SQL syntax error with this. Why? Commented May 24, 2010 at 0:31
  • And browsing in the shell is done through the cd command. computerhope.com/unix/ucd.htm Commented May 24, 2010 at 0:31
  • @Krt_Malta: Post the error and the relevant line in the sql file. Commented May 24, 2010 at 0:32
  • Error 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'u root -p -h localhost support <SupportDataSample.sql' at line 1 Commented May 24, 2010 at 0:34

3 Answers 3

1

You need to replace username with your database username and it will prompt you for a password. If the dump file has the "create database [name];" and "use [name];" instructions then you dont need to specify the database_name attribute.

To pull the .sql from another folder you just need to specify the path (/home/user/Downloads/file.sql, for example).

You could also try downloading mysql administrator from the mysql website.

Check this link too

http://www.techiecorner.com/31/how-to-restore-mysql-database-from-sql-dump-file/

Sign up to request clarification or add additional context in comments.

Comments

0

Redirecting a .sql file into the MySQL CLI works because that's the format that mysqldump produces. And people usually call mysqldump to dump a whole database, so they get one file afterwards.

The username and password are dependant on what's been setup on the database instance you want to reload the data in to. On a clean, empty install, the MySQL root user will work (and probably won't have a password). On an established install, you should find an appropriate user. The user you use will need substantial permissions as it needs to create and write to tables.

The .sql file may have CREATE database and USE database statements near the top. If this is present, then make sure that database does not exist before you pipe the file in. If not, you will need to find out what name is expected by whatever program will be using the database.

As for piping another file in in a different directory, this is simple shell notation. The < filename notation fully supports paths so you can do < some/other/path/filename.sql or < ~/sql/filename.sql, for example. (Note that I've assumed you're using a Unix shell.)

Comments

0

You can use cmd

  1. type cmd run as adminstration (C:\windows\system32>)
  2. give path of mysql of bin folder (C:\windows\system32> cd `C:\xampp\mysql\bin)
  3. C:\xampp\mysql\bin>mysql -u username -p -h localhost database_name
  4. type-> use database_name
  5. type-> source F:/example.sql

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.