Joomla! 1.5 Cookbook
上QQ阅读APP看书,第一时间看更新

Importing a MySQL database using phpMyAdmin

In the event of a problem, such as corruption of data, or loss of the database, it may be necessary to restore your database. This is known as importing.

Importing is the process of putting copy back into a database. This is also known as restoring.

Getting ready

You will need your username and password for accessing your database in your control panel. Depending on your hosting you may need your username and password for the database.

How to do it...

IMPORTING:

  1. Login to your hosting and navigate to your cPanel®.
  2. Locate your phpMyAdmin.
    How to do it...
  3. Click the phpMyAdmin button to open. You will see a screen as follows:
    How to do it...
  4. Select your database

    Tip

    For the purpose of demonstration, a blank database has been created. However the steps to IMPORT are the same.

    The database in this case is being indicated by the arrow.

    How to do it...
  5. Once you click on your database if it contains tables and rows, you will see a number next to it and all the tables on the left side of your screen.

    In our case, we have a new (empty) database and we see:

    How to do it...
  6. You will see a message (not shown in image) that states No tables found in database, and the count next to the database name is zero (0).

    This database is now ready for IMPORT of the data from the EXPORT step.

  7. Click the Import button found on the top toolbar.
    How to do it...

    The IMPORT function will display a simple screen as follows. Please note, for publishing purposes, this is a partial screenshot:

    How to do it...

    It is important unless otherwise directed, to accept the defaults for this screen.

  8. Click the Browse…button in the previous screenshot.

    You will be presented with a dialog box such as this one. Find the location of your EXPORTED dump file from the previous recipe and choose it, then move to the next step.

    How to do it...
  9. Click the Go button in the lower right-hand corner.
    How to do it...

    The database IMPORT will commence and should only take a few seconds.

    Once done you should see a screen similar to the following one. The key thought you need to know is the number of records. In our EXPORT, we had forty-six records. As you can see in the following screenshot we have the same amount. Making sure the numbers are the same is important.

    How to do it...
  10. This completes our IMPORT operation.

How it works...

The IMPORT function works by giving the database several commands, such as the following:

INSERT INTO `jos_components` (
`id`,
`name`,
`link`,
`menuid`,
`parent`,
`admin_menu_link`,
`admin_menu_alt`,
`option`, `ordering`,
`admin_menu_img`,
`iscore`, `params`,
`enabled`)
VALUES (
1,
'Banners',
'',
0,
0,
'',
'Banner Management',
'com_banners',
0,
'js/ThemeOffice/component.png',
0,
'track_impressions=0\ntrack_clicks=0\ntag_prefix=\n\n', 1);

This tells the database to "insert" or write into the TABLE jos_components columns, the data that follows the VALUES key word.

Note

Insert is a database command that instructs the database to 'Insert' or put into, new ROWS, or content, into your database tables.

In the IMPORT process (depending on our EXPORT settings) it will execute any other commands it finds in your .sql file.

Another example:

CREATE TABLE IF NOT EXISTS `jos_bannertrack` (
`track_date` date NOT NULL,
`track_type` int(10) unsigned NOT NULL,
`banner_id` int(10) unsigned NOT NULL
) ENGINE=MyISAM DEFAULT CHARSET=utf8;

The command CREATE TABLE IF NOT EXISTS jos_bannertrack instructs the database server to create a new table called jos_bannertrack. Insert would be used to put content into the table.

The great thing for restore is the .sql file will contain the proper commands to rebuild the heart of your Joomla! site, which is the database.