[ Home ]

Cover of SQL Cover of SQL Tricks Cover of SQL Short Course Cover of SQL Visual QuickStart Guide 3rd Edition

Creating the Sample Database in MySQL

To create books in MySQL:

  1. 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 -p option or press Enter at the password prompt). MySQL creates a new, empty database named books.

    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 to localhost, set user to root, and use the password that you assigned to root when you set up MySQL.

  2. At the command prompt, type:

    mysql -h host -u user -p -f books < books_mysql.sql

    The -f option forces mysql to 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 “Paths” section in “Running SQL Programs” in Chapter 1 of SQL or SQL Tricks, or in Appendix B of SQL Short Course or SQL Crash Course for Beginners).

    mysql displays the results. Ignore the messages about unknown (nonexistent) tables — they’re caused by the script’s DROP TABLE statements, which you’ll need to rerun books_mysql.sql later to restore the tables to their original states.

    mysql
  3. To run SQL scripts and interactive statements against books, see “MySQL” in Chapter 1 of SQL or SQL Tricks, or in Appendix B of SQL Short Course or SQL Crash Course for Beginners.

Tips