Mysql restore from backup file - mysql

I made a backup from a database in mysql with the command mysqldump -u root -p Test > test.sql and it saved correctly the database in the file, but when I restore it in a different database with the command mysql -u root -p Test2 < test.sql after create the new and clean Test2 database, it restore the originally backed up Test database and not the one that I want, if someone could tell me how can I change this behavior or what am I doing wrong, I'll appreciate it. Thanks

Please follow this code.
Step 1:
mysql -u <user> -p < db_backup.dump
Step 2
USE <database-name-here>;
I hope it will help you

Related

"successful" MySQL dump with no result

I am having a weird problem trying to upload a heavy MySQL dump file into a database.
The PuTTY command I'm using is the following:
homedirectory/userfolder/ mysql -u username –-password=password database_name < file.sql
The procedure runs as it would normally do (I've done this many times already) but when I look for the table that was supposed to be created in 'database_name' I dont see it!
Maybe it is because the file is too big? (4,5GB).
The command used to obtain the dump file was:
mysqldump --user=user --password=password --no-create-db
-h localhost --single-transaction --lock-tables=false
--skip-tz-utc database_name table_name > file.sql
After getting the .sql file, from the same location I ran the command and it seems to work for a few moments, dont get any error messages or any of the like.
After it finishes "loading" I check my database but the table is not there.
Not sure what else to specify, this is a simple procedure I do regularly and I have never had any complications, or at least never without at least an error message.
I recently tried creating sql dump using these commands :
backup: # mysqldump -u root -p[root_password] [database_name] > dumpfilename.sql
restore:# mysql -u root -p[root_password] [database_name] < dumpfilename.sql
Please refer to this link for more information you may need:
http://www.thegeekstuff.com/2008/09/backup-and-restore-mysql-database-using-mysqldump/
Hope this helps!

Restore MySQL dump file into database

I have a mysql dump file named dblp.sql
I am trying to restore it to database named DBLP
I tried the command:
source dblp.sql
mysql -u root -p -h localhost DBLP < dblp.sql
And those did not work. I keep getting an error SQL syntax on the second command. And failed to open file on the first command.
Any help would be really appreciated thank you.
Try restoring the data using the 'force' flag. One of the server's I helped maintain did not like to restore it's dump'ed data.
mysql -u root -p -h localhost DBLP --force < dblp.sql
try
mysql -hlocalhost -uroot DBLP < dblp.sql

Restoring a MySQL table back to the database

I have a trouble in restoring MySQL table back to the database from command line. Taking backup of a table is working with mysqldump.Taking backup and restoring of a database is also working properly. I have used:
mysql -uroot -p DatabaseName TableName < path\TableName.sql
Thanks in advance
Ah, I think I see the problem here.
Your backup script looks fine. tbl_name works correctly as the optional 2nd argument.
To restore, you should simply run
mysql -uroot -p DatabaseName < path\TableName.sql
Running man mysql would have shown you the correct arguments and options
mysql [options] db_name
As your backup script only contains one table, only that table will be restored into your database.
Taking backup
mysqldump -u -p mydatabase table1 > database_dump.sql
restoring from backup flie need not include table name
mysql -u -p mydatabase < database_dump.sql
Best way to restore your database:
open cmd at bin folder
login to mysql:
mysql -uroot -pyour_password
show databases;
use db_name;
now hit source and put the complete path from address bar where your sql file is stored and hit ;
for example :
source db_name.sql;
Copy your db.sql file to your Mysql Server if you are in a remote machine:
$rsync -Cravzp --progress db.sql user#192.168.10.1:/home/user
Now you can go to your remote server as:
$ssh -l user 192.168.10.1
In the Mysql Server you must to do this:
user#machine:~$mysql -h localhost -u root -p
Obs: The file db.sql must be in the same place (/home/user).
Now type this command in you Mysql Server:
mysql>'\'. db.sql + Enter. Obs: Remove all ' from this command to work

how to restore the database backup in test server database?

i am using mysql database. i am trying to restore the database backup in test server.
my backup file called steer_backup.sql is stored in /root. from the command prompt i am executing the command
mysqldump - u root -p steer < steer_backup.sql
and i will give the password on asking.
but it does not restore the database. i am not sure whether i am doing some mistakes because this is my first time experience of committing the code to test server ... please help me ..
Thanks in advance
mysqldump is use to create a dump.
If you want to restore a sql backup, just use
mysql -u [user] -p [databaseName] < [file]
mysqldump is for dumping. To import, just use mysql.
mysql -uRoot -pPassword dbname < file.sql

Where do I put mysql recover file?

I'm trying to migrate a mysql database from a server with phpMyAdmin to one that doesn't. I have a .sql file exported from the phpMyAdmin server, and am not quite sure where to go from there. While searching for an answer, I keep on finding websites that say to use this command:
mysql -u USER -p DBNAME < dump.sql
but nowhere describes WHERE that file should be located. Is it just supposed to be in the var/lib/mysql directory?
Thanks for the help.
It can be anywhere. Use full path if not in the current directory
mysql -u USER -p DBNAME <
/home/dump.sql
(if the file is in /home/ folder)
EDIT: Thanks for the correction, TehShrike.
You may follow -p with the password for user USER -- in which case there is no space between the option p and the password. Otherwise, mysql will prompt you for password. So the syntax is like the following:
mysql -u <user> -p<password> <database-name> < <path-to-mysqldump-file>
If the database does not already exist, you will have to login to your mysql server and create it first (Before the above line):
mysql -u <user> -p <password>
create database <database-name>