13.09.2016 Views

PHP and MySQL Web Development 4th Ed-tqw-_darksiderg

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

222 Chapter 9 Creating Your <strong>Web</strong> Database<br />

(If this comm<strong>and</strong> doesn’t work, verify that the <strong>MySQL</strong> server is running <strong>and</strong> the mysql<br />

comm<strong>and</strong> is somewhere in your path.)<br />

You should then enter your password. If all goes well, you should see a response<br />

something like this:<br />

Welcome to the <strong>MySQL</strong> monitor. Comm<strong>and</strong>s end with ; or \g.<br />

Your <strong>MySQL</strong> connection id is 1 to server version: 5.1.25-rc-community <strong>MySQL</strong><br />

Community Server (GPL)<br />

Type ‘help;’ or ‘\h’ for help. Type ‘\c’ to clear the buffer.<br />

mysql><br />

On your own machine, if you don’t get a response similar to this, make sure that you<br />

have run mysql_install_db if required, you have set the root password, <strong>and</strong> you’ve<br />

typed it in correctly. If it isn’t your machine, make sure that you typed in the password<br />

correctly.<br />

You should now be at a <strong>MySQL</strong> comm<strong>and</strong> prompt, ready to create the database. If<br />

you are using your own machine, follow the guidelines in the next section. If you are<br />

using somebody else’s machine, these steps should already have been done for you.You<br />

can jump ahead to the “Using the Right Database” section.You might want to read the<br />

intervening sections for general background, but you cannot run the comm<strong>and</strong>s specified<br />

there. (Or at least you shouldn’t be able to!)<br />

Creating Databases <strong>and</strong> Users<br />

The <strong>MySQL</strong> database system can support many different databases.You will generally<br />

have one database per application. In the Book-o-Rama example, the database will be<br />

called books.<br />

Creating the database is the easiest part. At the <strong>MySQL</strong> comm<strong>and</strong> prompt, type<br />

mysql> create database dbname;<br />

You should substitute the name of the database you want to create for dbname.To begin<br />

creating the Book-O-Rama example, create a database called books.<br />

That’s it.You should see a response like this (the time to execute will likely be different):<br />

Query OK, 1 row affected (0.0 sec)<br />

This means everything has worked. If you don’t get this response, make sure that you<br />

typed the semicolon at the end of the line. A semicolon tells <strong>MySQL</strong> that you are finished,<br />

<strong>and</strong> it should actually execute the comm<strong>and</strong>.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!