First lets look at what is mySQL database?
MySQL is a relational database management system (RDBMS) which has more than 11 million installations. The program runs as a server providing multi-user access to a number of databases.
Why use import or export of sql dump file (scenario)?
I have two MySQL databases located on a server somewhere. I connect via secure shell. I don't know all of the details about the configuration of this particular server but it obviously has MySQL installed/configured properly and you can assume that any other 'very likely' items would also be resident. I need to completley copy one database into the other (one is currently quite large, the second is empty).
And the easiest way to do this is use sql export to dump file and sql import of dump file to mySQL database.
How to create mySQL dump file (export database to sql file)?
The easiest way to export is use next syntax in command prompt (cmd):
mysqldump -u USER -p PASSWORD DATABASE > filename.sql
For example we have database with next parameters: database username baseu01 database password h4z56s3 database name database01 sql export file name export.sql
Appropriate command line for export is:
>mysqldump -u baseu01 -p h4z56s3 database01 > filename.sql
After executing export command you will have file "export.sql" in your folder.
How to import sql dump file to mySQL database?
The scenario: server crashes and you got mysql dump file stored on your hard drive. First you install mySQL database - then create database, database user and database password and then use next command line:
>mysql -u username -p password database_name < filename.sql
If we use the same example as we used for export command line for export is:
mysql -u baseu01 -p h4z56s3 database01 export.sql ------------------------------------------------------------------------------------------------
Advanced options for exporting or importing a database
How to Export A MySQL Database Structures Only
If you no longer need the data inside the database’s tables (unlikely), simply add –no-data switch to export only the tables’ structures.
For example, the syntax is:
>mysqldump -u username -ppassword –no-data database_name > dump.sql
How to Backup Only Data of a MySQL Database
If you only want the data to be backed up, use –no-create-info option. With this setting, the dump will not re-create the database, tables, fields, and other structures when importing. Use this only if you pretty sure that you have a duplicate databases with same structure, where you only need to refresh the data. Syntax:
>mysqldump -u username -ppassword –no-create-info database_name > dump.sql
How to Dump Several MySQL Databases into Text File
–databases option allows you to specify more than 1 database.
Example syntax:
>mysqldump -u username -ppassword –databases db_name1 [db_name2 ...] > dump.sql
How to Dump All Databases in MySQL Server
To dump all databases, use the –all-databases option, and no databases’ name need to be specified anymore. mysqldump -u username -ppassword –all-databases > dump.sql
Saturday, July 3, 2010
MySQL import and export dump file
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment