TestingDocs.com
Software Testing website
  • Automation
    • Selenium
    • JBehave Framework
  • Tutorials
    • MySQL Tutorials
    • Testlink
    • Maven
    • Git
  • IDEs
    • IntelliJ IDEA
    • Eclipse
  • Flowcharts
    • Flowgorithm
    • Raptor
  • About

MySQL

MySQL mysqldump Export

Overview

In this tutorial, we will learn about MySQL mysqldump Export utility. The mysqldump utility dumps structure and contents of MySQL databases and tables.

We can use this utility in different ways:

  • To dump full structure
  • To dump only data
  • To dump only table structure
  • To dump in a standard format

 

mysqldump Utility

The mysqldump utility only dumps the SQL statements. In order to use the dumped statements, we need to connect to a target MySQL server using with a client, and execute the dumped SQL statements.

We can use mysqldump from the command shell. To view the options open command shell/prompt and issue the mysqldump command.

>mysqldump
Usage: mysqldump [OPTIONS] database [tables]
OR mysqldump [OPTIONS] –databases [OPTIONS] DB1 [DB2 DB3…]
OR mysqldump [OPTIONS] –all-databases [OPTIONS]
For more options, use mysqldump –help

Examples

To dump a database to a text (.txt) file or (.sql) file using the mysqldump utility, use the redirect operator
to indicate the filename and the location.

In this example,we will export all the database tables and the data for a database. To dump the full world database to ‘world.sql’ file, we can issue the following command:

> mysqldump world -u root -p > world.sql

 

The -p option tells MySQL to prompt for a password. The –u option sets the database username. For example, root user.

We can also dump a database to a text file using the mysqldump utility. To dump the world
database to ‘world.txt’ file:

> mysqldump world -u root -p > world.txt

The data created in the dump file assumes that no table exists on the destination database server.
The –add-drop-table option adds code to drop a table if it exists in the new target database
when the file is imported.

DROP TABLE IF EXISTS `city`;

For example, a statement like above before creating the city table.

MySQLDump Export Utility

We can use the MySQL Workbench tool to open the dump file when dumped in .sql file. On Windows, we can right click on the world.sql file and choose open with MySQL Workbench utility.

 

MySQL Workbench MySQL Dump File

To dump some tables in the database, we can specify the tables as arguments after the database:

> mysqldump world Country City

This command will dump only the tables specified in the command.

If we do not specify any table names following the database name or if we use the –databases
or –all-databases option, the entire databases are dumped.

Dump multiple databases

To dump multiple databases, we can use the following commands:

> mysqldump—all-databases

> mysqldump—databases world sakila

—

MySQL Tutorials

MySQL Tutorials on this website:

https://www.testingdocs.com/mysql-tutorials-for-beginners/

For more information on MySQL Database:

https://www.mysql.com/

Related Posts

DataGrip Desktop Shortcut

MySQL /

Launch DataGrip on Windows

DataGrip Download

MySQL /

Install DataGrip IDE on Windows 11

MySQL Workbench Windows 11

MySQL /

New MySQL Connection in Workbench

MySQL Command-line Client

MySQL /

Command-Line MySQL Client

Start MySQL Client

MySQL /

Start MySQL Client on Windows 11

‹ MySQL Export using INTO OUTFILE› Import Data Using MySQLImport Utility

Recent Posts

  • MS Access Data Types
  • Install RAPTOR Avalonia on CentOS
  • Download RAPTOR Avalonia Edition on Windows
  • npm doctor command
  • Build & Run CLion Project
  • Create New CLion C Project on Windows
  • Configure CLion Toolchains on Windows
  • Launch CLion IDE on Windows
  • Activate CLion IDE
  • CLion IDE for C/C++ Development

Back to Top

Links

  • Contact
  • Privacy Policy
  • Cookie Policy

www.TestingDocs.com

Go to mobile version