官术网_书友最值得收藏!

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...

  1. 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.
  2. After the download finishes, we unzip the file using the following command:
    unzip backup-MySQL-55-2014-02-22.zip
    
  3. When unzipped, the file will be over 300 megabytes.
  4. Our next step is to launch the mysql command-line client and create a database to import into:
    CREATE DATABASE isfdb;
    
  5. After creating the database, quit the mysql command-line client.
  6. Lastly, we import the file into MariaDB using the following command:
    mysql isfdb < backup-MySQL-55-2014-02-22
    
  7. 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

主站蜘蛛池模板: 威远县| 东海县| 牟定县| 青海省| 德州市| 铜陵市| 天长市| 莱阳市| 介休市| 色达县| 鄱阳县| 沙坪坝区| 平湖市| 红原县| 西城区| 商丘市| 天津市| 常熟市| 永胜县| 牙克石市| 西安市| 额尔古纳市| 嘉兴市| 绩溪县| 都匀市| 栾城县| 怀安县| 师宗县| 延川县| 沈阳市| 兴国县| 石门县| 益阳市| 湖南省| 名山县| 开江县| 边坝县| 西安市| 海口市| 万盛区| 宁远县|