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.

Logging In to <strong>MySQL</strong><br />

221<br />

we have used this approach because <strong>MySQL</strong> provides a continuation symbol; it’s an<br />

arrow that looks like this:<br />

mysql> grant select<br />

-><br />

This symbol means <strong>MySQL</strong> expects more input. Until you type the semicolon, you get<br />

these characters each time you press Enter.<br />

Another point to note is that SQL statements are not case sensitive, but database <strong>and</strong><br />

table names can be (more on this topic later).<br />

Logging In to <strong>MySQL</strong><br />

To log in to <strong>MySQL</strong>, go to a comm<strong>and</strong>-line interface on your machine <strong>and</strong> type the<br />

following:<br />

mysql -h hostname -u username -p<br />

The mysql comm<strong>and</strong> invokes the <strong>MySQL</strong> monitor, which is a comm<strong>and</strong>-line client that<br />

connects you to the <strong>MySQL</strong> server.<br />

The -h switch specifies the host to which you want to connect—that is, the machine<br />

on which the <strong>MySQL</strong> server is running. If you’re running this comm<strong>and</strong> on the same<br />

machine as the <strong>MySQL</strong> server, you can leave out this switch <strong>and</strong> the hostname parameter.<br />

If not, you should replace the hostname parameter with the name of the machine<br />

where the <strong>MySQL</strong> server is running.<br />

The -u switch specifies the username you want to connect as. If you do not specify,<br />

the default will be the username you are logged in to the operating system as.<br />

If you have installed <strong>MySQL</strong> on your own machine or server, you need to log in as<br />

root <strong>and</strong> create the database we’ll use in this section. Assuming that you have a clean<br />

install, root is the only user you’ll have to begin with. If you are using <strong>MySQL</strong> on a<br />

machine administered by somebody else, use the username that person gave you.<br />

The -p switch tells the server you want to connect using a password.You can leave it<br />

out if a password has not been set for the user you are logging in as.<br />

If you are logging in as root <strong>and</strong> have not set a password for root, we strongly recommend<br />

that you visit Appendix A right now.Without a root password, your system is<br />

insecure.<br />

You don’t need to include the password on this line.The <strong>MySQL</strong> server will ask you<br />

for it. In fact, it’s better if you don’t include it here. If you enter the password on the<br />

comm<strong>and</strong> line, it will appear as plain text on the screen <strong>and</strong> will be quite simple for<br />

other users to discover.<br />

After you enter the previous comm<strong>and</strong>, you should get a response something like<br />

this:<br />

Enter password:

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

Saved successfully!

Ooh no, something went wrong!