Learning Mysql


--result-file=outputfile.sql



Download 4.24 Mb.
View original pdf
Page329/366
Date04.08.2023
Size4.24 Mb.
#61806
1   ...   325   326   327   328   329   330   331   332   ...   366
Learning MySQL
--result-file=outputfile.sql database_name table_name where=where_clause
For example, to use the artist table of the music database, and dump SQL statements for all the artists having a name beginning with N, you would write mysqldump --user=root --password=the_mysql_root_password \
--result-file=outputfile.sql \
--where="artist_name like 'Nb b music artist
Dumping a Database as SQL Statements | 359


Loading Data from an SQL Dump File
The previous section showed you how to backup your databases. Let’s see how to restore them from those backups.
To load the structures and data in a dump file, you can tell the MySQL monitor to read in the SQL commands from the file:
mysql> SOURCE dumpfile.sql
Alternatively, you can simply run the MySQL monitor in batch mode and execute the instructions in the dump file mysql mysql_options < dumpfile.sql
We don’t recommend this approach, as it’s a little less portable than the
SOURCE
com- mand; more importantly, it doesn’t show you any error and warning messages as the
SQL statements are processed.
If the backup file doesn’t have CREATE DATABASE
and
USE
statements, you’ll need to type these into the monitor before you read in the dump file, or add them to the dump file if you want to run the monitor in batch mode. A good step prior to carrying out a restore operation is to inspect the backup file with a text editor. Once you’ve inspected the file, you can decide whether you need to drop and recreate databases, use databases whether you need to take any other steps prior to a restore operation. Of course, you can use the mysqldump options to control what’s written to the dump file when it’s created.
You previously backed up the music database to the file music.sql. The way you did this didn’t include any CREATE DATABASE
and
USE
statements in the dump file, so you need to use the monitor to enter these yourself.
Start the monitor as the root user mysql --user=root --password=the_mysql_root_password
Now, drop the existing music database:
mysql> DROP DATABASE music;
and create anew (empty) database with the same name:
mysql> CREATE DATABASE music;
Then select the music database as the active database:
mysql> USE music;
Now you can restore the data by reading in the music.sql dump file:
mysql> SOURCE music.sql;
If your music.sql file isn’t in the current directory, you should specify the full path. If you used our earlier suggestions in Dumping a Database as SQL Statements this

Download 4.24 Mb.

Share with your friends:
1   ...   325   326   327   328   329   330   331   332   ...   366




The database is protected by copyright ©ininet.org 2024
send message

    Main page