
Importing the data exported by mysqldump
Importing data from a mysqldump
backup is easy and quick. In this recipe, we'll import a backup of the Internet Speculative Fiction Database (ISFDB). This database is licensed under the Creative Commons Attribution license (CC BY) which allows us to use this database for this recipe and many of the other recipes in this book.
How to do it...
- Go to http://www.isfdb.org/wiki/index.php/ISFDB_Downloads and download the latest MySQL 5.5 compatible file. The file will be almost 80 megabytes and will be named with the date the backup was made. In this recipe, we'll be using the
backup-MySQL-55-2014-02-22.zip
file. We can download that file or a more recent one. If we do use a more recent file, we'll need to update the names in the following steps. - After the download finishes, we unzip the file using the following command:
unzip backup-MySQL-55-2014-02-22.zip
- When unzipped, the file will be over 300 megabytes.
- Our next step is to launch the
mysql
command-line client and create a database to import into:CREATE DATABASE isfdb;
- After creating the database, quit the
mysql
command-line client. - Lastly, we import the file into MariaDB using the following command:
mysql isfdb < backup-MySQL-55-2014-02-22
- Depending on the speed of our computer processor, the size of the memory we have, and the speed of our hard drive, the file will be imported in a time span of a few seconds to a couple of minutes, and the
isfdb
database will be full of data tables. We can now go ahead and take a look at it if we're interested.
Tip
Downloading the example code
You can download the example code files for all Packt books you have purchased from your account at http://www.packtpub.com. If you purchased this book elsewhere, you can visit http://www.packtpub.com/support and register to have the files e-mailed directly to you.
How it works...
The special character <
sends the contents of the backup-2014-02-22
file to the mysql
command. The mysql
command, in turn, is set to connect to the isfdb
database we just created, so that is where the data goes. In addition to the data, the backup file contains the necessary commands to create all of the necessary tables.
There's more...
To keep the recipe short, I didn't put down any of the usual options for the mysql
command-line client. Depending on how we have things set up, we may need to specify the user (-u
), password (-p
), host (-h
), or other options. We just need to be sure to put them before the name of the database (isfdb
in the recipe).
See also
- The full documentation of the
mysqldump
command can be found at https://kb.askmonty.org/en/mysqldump/