|
SQL: Visual QuickStart Guide, Third EditionCreating the Sample Database - MySQL |
To create books in MySQL:
-
At a command prompt, type:
mysqladmin -h host -u user -p create books
host is the host name, and user is your MySQL user name. MySQL will prompt you for your password (for a passwordless user, either omit the-poption or press Enter at the password prompt). MySQL creates a new, empty database namedbooks.
If MySQL is running on a remote network computer, ask your database administrator (DBA) for the connection parameters. If you're running MySQL locally (that is, on your own computer), then set host tolocalhost, set user toroot, and use the password that you assigned torootwhen you set up MySQL.
-
At the command prompt, type:
mysql -h host -u user -p -f books < books_mysql.sql
The-foption forcesmysqlto keep running even if an SQL error occurs. The<redirection operator reads from the specified SQL file. You can include an absolute or relative pathname (see the "Pathnames" sidebar in "Running SQL Programs" in Chapter 1).
mysqldisplays the results. Ignore the messages about unknown tables — they're caused by the script'sDROPTABLEstatements, which you'll need to rerunbooks_mysql.sqllater to restore the tables to their original states.
-
To run SQL scripts and interactive statements against
books, see "MySQL" in Chapter 1.
Tips
-
As an alternative to the command prompt, you can use the graphical tools at MySQL Workbench.
-
The script
books_mysql.sqlis identical to the standard SQL scriptbooks_standard.sql.