MySQL has its own client interface, allowing you to move data
around and change database configuration. Note that you must use a password to
log in. Assigning database users allows you to
limit access to server tables that have multiple users. Each MySQL server, where
tables are grouped together, can host many databases. Normally, a web
application has its own proprietary database.
You may have installed MySQL yourself or have access through
your ISP. Most ISPs that support PHP also provide a MySQL database for your use.
Should you have difficulty, check their support pages or contact them to
determine connection details. You'll need to know the following:
-
The IP address of the database server
-
The name of the database
-
The username
-
The password
If you've installed MySQL on your computer, you'll be able to
use the defaults from the installation and the password you specified. This
chapter looks at two ways to communicate with MySQL, the command line and phpMyAdmin, a web-based tool.
Once you reach the command line, type mysql and press
Enter. The syntax for the mysql command is:
mysql -h hostname -u user -p
If you've installed MySQL on your computer, the default
username is root. You can omit the hostname flag and value. Enter your
password when MySQL displays the Enter password prompt.
At the MySQL prompt, you can enter database commands followed by Enter. There is
also a set of commands that MySQL itself interprets. For a list of these
commands, type help or \h at the mysql> prompt.
Prompt
|
Meaning
|
---|---|
mysql>
|
Waiting for a command
|
->
|
Waiting for the next line of a command
|
'>
|
Waiting for the next line of a string that starts with a single
quote
|
">
|
Waiting for the next line of a string that starts with a double
quote
|
Command
|
Parameter
|
Meaning
|
---|---|---|
quit
|
Exit the command-line utility
| |
use
|
Database name
|
Use a specific database
|
show
|
tables or databases
|
Show lists such as tables or databases available
|
describe
|
Table name
|
Describe a table's columns
|
status
|
Display database version and status
| |
source
|
Filename
|
Execute commands from a file as a
script
|
To display the available databases, type:
mysql> SHOW DATABASES;