"SQL" serves the purpose of "loading" whole datasets or already existing databases with one action. The datasets (or the database) are presumed to be already available in a MySQL "dump file". This
is a text file containing all the necessary SQL queries that must be sent to the database server, in order for the datasets or database to be created. An example of such a dump file is the nuke.sql
file that comes with PHP-Nuke and contains all the database instructions for the tables to be created during installation (see Section
3.4.5).
The use of this function is very simple: just search your system for the dump file you want to load, by hitting the "Browse" button (Figure 3-10). MySQL dump files usually come with the ".sql" ending, but ".sql.php", ".txt" or even ".php" are also in use. Whether the file
is a MySQL dump file or not, can only be told by inspection: open it with a decent text editor (see Chapter 11) and if the first lines look like
# MySQL dump 6.6
#
...
#
# Table structure for table 'xxxxx'
#
CREATE TABLE xxxxx ...
...
#
# Dumping data for table 'xxxxx'
#
INSERT INTO xxxxx ...
|
i.e. if it contains CREATE and/or INSERT SQL statements, then it is a dump file (see also Section 3.4.3).
This function is useful when you want to create whole databases and fill them with data in one step, but it is also very useful when you want to add data to an existing database. However, this
does not mean that it will always succeed: especially if the dump files are very large, this operation my exceed the PHP CPU
limit (usually set to 30 sec. by the ISPs). (see, for example, Section 27.16)
 |
Beware of long .sql files! |
|
You can of course use phpMyAdmin to comfortably import any MySQL dump file, i.e. from a previous backup of an existing installation with thousands of forums posts. In this case, the import may
take longer than the limit on the execution time of PHP scripts that most ISPs set (usually 30 sec.). You will end up with a half-filled database!
In this case, either cut the file up into smaller chucks and use phpMyAdmin to load the smaller files, or insert the text piecewise for execution in the text area field of phpMyAdmin that is there
for this purpose, or, as a last resort, do it from the command line, as shown in Section 3.2.4.
See also how to import a '.sql' (>3M) file to mysql database with phpmyadmin?, Importing .sql files into an existing database in phpmyadmin.
|