Importing SQL files

Any file containing MySQL statements can be imported via this mechanism. This format is the more commonly used for backup/restore purposes. The dialog is available in the Server view, Database view, or the Table view, via the Import page, or in the Query window.

Importing SQL files

Note

There is no relation between the currently selected table (here author) and the actual contents of the SQL file that will be imported. All the contents of the SQL file will be imported, and it is those contents that determine which tables or databases are affected. However, if the imported file does not contain any SQL statements to select a database, all statements in the imported file will be executed on the currently selected database.

Let us try an import exercise. First, we make sure that we have a current SQL export file of the book table (as explained in Chapter 6). This export file must contain the structure and the data. Then we drop the book table—yes, really! We could also simply rename it. (Refer to Chapter 9 for the procedure.)

Now it is time to import the file back to the current database (the file could be imported for testing in a different database or even on another MySQL server). We should be on the Import page, where we can see the File to import dialog. We just have to hit the Browse button and choose our file.

phpMyAdmin is able to detect which compression method (if any) has been applied to the file. Depending on the phpMyAdmin version, and the extensions that are available in the PHP component of the web server, there is variation in the formats that the program can decompress.

However, to import successfully, phpMyAdmin must be informed of the character set of the file to be imported. The default value is utf-8. However, if we know that the import file was created with another character set, we should specify it here.

A SQL compatibility mode selector is available at import time. This mode should be adjusted to match the actual data that we are about to import, according to the type of server where the data was previously exported.

Another option, Do not use AUTO_INCREMENT for zero values, is marked by default. If we have a value of zero in a primary key and we want it to stay zero instead of being auto-incremented, we should use this option.

To start the import, we click on Go. The import procedure continues and we receive a message: Import has been successfully finished, 2 queries executed. We can browse our newly-created tables to confirm the success of the import operation.

An import file may contain the DELIMITER keyword. This enables phpMyAdmin to mimic the mysql command-line interpreter. The DELIMITER separator is used to delineate the part of the file containing a stored procedure, as these procedures can themselves contain semicolons.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.220.18.186