How to keep backup of our database in MySql - mysql

I want to keep backup of my database and import it into different System? and how to make .dmp
or store file in MySql?

You can dump a database with the mysqldump command-line utility ; using a command like this :
mysqldump --user=USERNAME --password=PASSWORD --host=ORIGIN_HOST DATABASE_NAME > backup.sql
Then, as the backup is just a bunch of SQL instruction, importing it to another database is as easy as using the mysql command-line utility :
mysql --user=USERNAME --password=PASSWORD --host=DESTINATION_HOST NEW_DATABASE_NAME < backup.sql
And, as a couple of references to the relevant manual pages :
4.5.4. mysqldump — A Database Backup Program
4.5.1. mysql — The MySQL Command-Line Tool
and Chapter 6. Backup and Recovery

Read the manual. If there's something there that you're not sure about, ask a more specific question.

Related

MySQL data backup?

I have an database with tons of data in it.
I also wrote a new program that will change the data in the database.
Is there any way to make a copy of the database before i run my program?
Or is there any other solution?
What I'm thiking is making a copy of the database,
Run the program, which modified the main database. If things goes wrong, how do I use my copied database data to revert the main database?
Please provide steps and commands on linux. I'm new with the database mysql and its commands.
You can use the mysqldump command to make a backup of your database and overwrite the backup file everytime
mysqldump -u <user> -p <db> > dump.sql
Read the following link this will tell you how to dump your database via different ways and restore it.
http://www.thegeekstuff.com/2008/09/backup-and-restore-mysql-database-using-mysqldump/
Basic command to dump a single database is:
mysqldump -u root -p[root_password] [database_name] > dumpfilename.sql
Is there any way to make a copy of the database before i run my program?
Yes, there's. You have to use the client utility mysqldump before run you app.
It is something like
shell> mysqldump [options] > dump.sql

Avoid blocking mysql and PC with mysqldump

I have a root access to a mysql server, I need to dump ALL the database inside the server.
I tried with a simple mysqldump, but the server and pc seems blocked due to the large size of the databases and tables. Can I "optimize" this DUMP avoiding locking the server (and PC) ?
Thank you so much!
EDIT:
I want to EXPORT all the databases from a Mysql Server.
I need to understand what options to pass to mysqldump to avoid blocking:
The Mysql Server <---- it CAN'T go down
The PC that is goind to do this DUMP
You can disable locking:
mysqldump --skip-lock-tables
Of course you will not be able to create a consistent dump that way, so I would not recommend to use that option.
When only using MyISAM and ARCHIVE tables you might want to consider using mysqlhotcopy (included with a regular mysql package). There is similar software for other table engines like InnoDB available.
Another option is using a replication slave for backup.
Fire the dump command from commandline. :
mysqldump <other mysqldump options> --routines > outputfile.sql
If we want to backup ONLY the stored procedures and triggers and not the mysql tables and data then we should run something like:
mysqldump --routines --no-create-info --no-data --no-create-db --skip-opt <database> > outputfile.sql
If you need to import them to another db/server you will have to run something like:
mysql <database> < outputfile.sql

Exporting a table in mysql

I am doing some prototyping and so created a database with a few tables and dependencies. The project became bigger than I thought and now want to clean up the names, dependencies etc and so want to create the DB anew. But I don't want to go through the whole process of creating individual tables again, instead I want to start with what I have, clean the creation scripts up and run them if possible. Is there a way I can export all the scripts to create the DB and tables? Are there tools or mysql command line options to do this?
Thanks,
-S
This can get you started:
mysqldump -u user -ppassword -h host --no-create-db --no-data [other options] old_database > dump.sql
then you can edit the dump file for any necessary changes and import back into the new database:
mysql -u user -ppassword -h host new_database < dump.sql
More information about the mysqldump #MySQL Reference Manual
I recommend you to look at MySql WorkBench
It can do everything you need
Here's the list of all the features
Reverse Engineer from Live Database
Reverse Engineer from SQL Script
Also, good to mention that it's free (community version)

Update online MySQL with local computer SQL via Command Prompt?

I have an online sql database which is used by a PHP web-script.
I'm working with someone who is managing a local database on their computer.
I need a way to replace the content of my online sql database with the updated version from the computer, preferably using Windows Command Line. How can I do this?
You could use the mysql utilities to do this. mysqldump will create a backup of the updated database and then you can feed that into your online database using the mysql utility.
C:>mysqldump -uUSER -pPASSWORD DATABASE > database.sql
C:>mysql -hHOST -pPORT -uUSER -pPASSWORD DATABASE < database.sql

Is there a way to copy all the data in a mysql database to another? (phpmyadmin)

I want to copy all the tables, fields, and data from my local server mysql to my hosting sites mysql. Is there a way to copy all the data? (It's only 26kb, very small)
In phpMyAdmin, just export a dump (using the export) tab and re-import it on the other server using the sql tab.
Make sure you compare the results, I have had phpMyAdmin screw up the import more than once.
If you have shell access to both servers, a combination of
mysqldump -u username -p databasename > dump.sql
and a
mysql -u username -p databasename < dump.sql
on the target server is the much more fast and reliable alternative in my experience.
Have a look at
Copying MySQL Databases to Another Machine
Copy MySQL database from one server to another remote server
Please follow the following steps:
Create the target database using MySQLAdmin or your preferred method. In this example, db2 is the target database, where the source database db1 will be copied.
Execute the following statement on a command line:
mysqldump -h [server] -u [user] -p[password] db1 | mysql -h [server]
-u [user] -p[password] db2
Note: There is NO space between -p and [password]
I copied this from Copy/duplicate database without using mysqldump.
It works fine. Please ensure that you are not inside mysql while running this command.
If you have the same version of mysql on both systems (or versions with compatible db file sytsem), you may just copy the data files directly. Usually files are kept in /var/lib/mysql/ on unix systems.