I was trying to backup a MySQL database via command line and I typed
mysql -u -root -p -h server.com DATABASE > file.sql
INSTEAD OF
mysqldump -u -root -p -h server.com DATABASE > file.sql
It created a file on my desktop so I thought it was working and I left it for about an hour.
I then realized that it still wasn't finished, pressed ctrl + c to kill it.
I then opened file.sql and there was nothing in it.
What just happened? Did I just corrupt my database?
Related
I execute the command : mysql -u user -p -h localhost bd_new < bd_dump.dump. Dont restore the bd and dont show error message.
I use other code: mysql -u root -p bd_new < bd_dump.dump and it happens like previus one.
The trouble are a .dump?
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!
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 can I backup a mysql database which is running on a remote server, I need to store the back up file in the local pc.
Try it with Mysqldump
#mysqldump --host=the.remotedatabase.com -u yourusername -p yourdatabasename > /User/backups/adump.sql
Have you got access to SSH?
You can use this command in shell to backup an entire database:
mysqldump -u [username] -p[password] [databasename] > [filename.sql]
This is actually one command followed by the > operator, which says, "take the output of the previous command and store it in this file."
Note: The lack of a space between -p and the mysql password is not a typo. However, if you leave the -p flag present, but the actual password blank then you will be prompted for your password. Sometimes this is recommended to keep passwords out of your bash history.
No one mentions anything about the --single-transaction option. People should use it by default for InnoDB tables to ensure data consistency. In this case:
mysqldump --single-transaction -h [remoteserver.com] -u [username] -p [password] [yourdatabase] > [dump_file.sql]
This makes sure the dump is run in a single transaction that's isolated from the others, preventing backup of a partial transaction.
For instance, consider you have a game server where people can purchase gears with their account credits. There are essentially 2 operations against the database:
Deduct the amount from their credits
Add the gear to their arsenal
Now if the dump happens in between these operations, the next time you restore the backup would result in the user losing the purchased item, because the second operation isn't dumped in the SQL dump file.
While it's just an option, there are basically not much of a reason why you don't use this option with mysqldump.
This topic shows up on the first page of my google result, so here's a little useful tip for new comers.
You could also dump the sql and gzip it in one line:
mysqldump -u [username] -p[password] [database_name] | gzip > [filename.sql.gz]
mysqldump -h [domain name/ip] -u [username] -p[password] [databasename] > [filename.sql]
Tried all the combinations here, but this worked for me:
mysqldump -u root -p --default-character-set=utf8mb4 [DATABASE TO BE COPIED NAME] > [NEW DATABASE NAME]
If you haven't install mysql_client yet and using Docker container instead:
sudo docker exec MySQL_CONTAINER_NAME /usr/bin/mysqldump --host=192.168.1.1 -u username --password=password db_name > dump.sql
You can directly pipe it to the remote server where you wish to copy your data to:
mysqldump -u your_db_user_name -p --set-gtid-purged=OFF --triggers --routines --events --compress --skip-lock-tables --verbose your_local_sql_db_name | mysql -u your_db_user_name -p -h your_remote_server_ip your_remote_server_db_name
You need to have created the db on your remote sql server.
Using the above command, I was able to copy from my local sql server version 8.0.23 to my remote sqlserver running 8.0.25
This is how you would restore a backup after you successfully backup your .sql file
mysql -u [username] [databasename]
And choose your sql file with this command:
source MY-BACKED-UP-DATABASE-FILE.sql
I want to dump my DB with a click on a button in my C#.Net App.
I thought about using
Process.Start(#"mysqldump", #"-u root -p mydb > dump.sql");
but this command opens a command prompt asking for the MySQL user password.
how can I avoid this?
Instead of this command :
mysql -u root -p mydb > dump.sql
Try using this, passing the password in the command, so mysqldump doesn't ask for it :
mysqldump -u root --password=YOUR_PASSWORD mydb > dump.sql