views:

34

answers:

2

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.

+1  A: 

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/

dabito
A: 

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.)

staticsan