The author selected the Free and Open Source Fund to receive a donation as part of the Write for DOnations program. Show IntroductionImporting and exporting databases is a common task in software development. You can use data dumps to back up and restore your information. You can also use them to migrate data to a new server or development environment. In this tutorial, you will work with database dumps in MySQL or MariaDB (the commands are interchangeable). Specifically, you will export a database and then import that database from the dump file. PrerequisitesTo import or export a MySQL or MariaDB database, you will need:
Note: As an alternative to manual installation, you can explore the DigitalOcean Marketplace’s MySQL One-Click Application. Step 1 — Exporting a MySQL or MariaDB DatabaseThe Use
The command will produce no visual output, but you can inspect the contents of Run the following command:
The top of the file should look similar to this, showing a MySQL dump for a database named
If any errors occur during the export process, Step 2 — Importing a MySQL or MariaDB DatabaseTo import an existing dump file into MySQL or MariaDB, you will have to create a new database. This database will hold the imported data. First, log in to MySQL as root or another user with sufficient privileges to create new databases:
This command will bring you into the MySQL shell prompt. Next, create a new database with the following command. In
this example, the new database is called
You’ll see this output confirming the database creation.
Then exit the MySQL shell by pressing
If the command runs successfully, it won’t produce any output. If any errors occur during the process, ConclusionIn this tutorial you created a database dump from a MySQL or MariaDB database. You then imported
that data dump into a new database. To learn more about MySQL, check out our MySQL resource page. To learn more about MySQL queries, check out our tutorial, “An Introduction to Queries in MySQL”. How do I import a database into MySQL?Importing a database from a file
To import a file, open Workbench and click on + next to the MySQL connections option. Fill in the fields with the connection information. Once connected to the database go to Data Import/Restore. Choose the option Import from Self-Contained File and select the file.
How import MySQL dump Linux?Step 1: Create New MySQL Database and Assign User. Before you can import a database using phpMyAdmin, you'll need to create a blank database first: Log into cPanel. ... . Step 2: Import MySQL Database with phpMyAdmin. To import a dump file into the new database using the phpMyAdmin web interface: Log into cPanel.. How do I import a MySQL table into terminal?Import CSV File Using Command Line. Step 1: Access MySQL Shell. Access your terminal window and log into MySQL using the following command: mysql –u username –p. ... . Step 2: Create MySQL Table for CSV Import. ... . Step 3: Import CSV into MySQL Table.. How show MySQL database in Linux?Show MySQL Databases
The most common way to get a list of the MySQL databases is by using the mysql client to connect to the MySQL server and run the SHOW DATABASES command. If you haven't set a password for your MySQL user you can omit the -p switch.
|