how to restore the database backup in test server database? - mysql

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

Related

Mysql restore from backup file

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

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

Dump all databases and reimport on another server?

It's quite simple really, I just can't figure out the syntax.
I want to replicate my server setup on another server.
I can dump all my databases with
mysqldump -uroot -p --alldatabases > all.sql
But how do I import ALL of those into a brand new mysql setup on another server?
mysql -u root -p < all.sql
will do
From command line:
mysql -uroot < all.sql
ps. If you want to see what statement is executed right now you should -v.
if the database servers are both near enough the same version, you could simply rsync the /var/lib/mysql directory over.
rsync /var/lib/mysql root#destination.server.com:/var/lib/ -a
Edit: Please note that there are some issues with this approach which require some additional steps:
http://verens.com/2016/05/11/quick-method-to-clone-a-mysql-database/
mysql -u root -p
that command will open the mysql interactive console, where you'd do this:
source all.sql
execute the dump file from shell (dump file should contain the CREATE DATABASE syntax)
mysql -uroot < /path/to/file.sql
or execute from mysql
source /path/to/file.sql

Copying MySQL database from test server to local MAMP server

I may have gone completely braindead today, but I'm having trouble copying my DB down to my local MAMP server. I'm not too familiar with mysqldump, etc, but I want to know how to copy a database from a test server to my MAMP local server in the easiest way possible. I have very limited experience with server stuff, but have a bit of experience with command line.
Any straight-forward help would be much appreciated. I look forward to smacking myself in the head when I realise what a dick I've been ;)
Dalogi
mysqldump's the best way:
on the test server: mysqldump -p name_of_db > dump.sql
on the map server: mysql -p < dump.sql
The dump file contains the full instructions in SQL query format to recreating the db, it stable structure, and data. The -p option forces both apps to prompt for your password. If your MySQL username is different than your system's login account, then you'll need the -u option as well:
mysqldump -p -u yourDBusername name_of_db > dump.sql
mysql -p -u yourDBusername < dump.sql
mysqldump -h 'remotehost' -uremoteuser -premotepass db_name | mysql -ulocaluser -plocalpass db_name

restore backup mysql

I have a backup of my database in mysql of 250MB !!
How can I restore it in a new database on another server ?
Or just use phpMyAdmin for restore porpoise.
You are providing no detail on what operating system you're on and what kind of backup you have, but the short answer is
mysql -u username -p -h hostname databasename < dumpfile.sql
where dumpfile.sql needs to be a file containing SQL statements, for example produced with mysqldump.
Using:
mysql -u USER -p -h HOST DATABASE < mysqldump.sql