Running MySQL
Now we'll check if MySQL is running. If you're using a remote UNIX server, use your terminal emulator to go to your UNIX server. At your prompt, type mysql -u username -p. The server should then ask for your password. Then you'll get a welcome message and the prompt changes to mysql>. The whole exchange should look like:
$ mysql -u username -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 31110 to server version: 3.22.25-log
Type 'help' for help.
mysql>
If your prompt changes to mysql>, then MySQL
is running. If it didn't work:
If you got a response such as
bash: mysql: command not found
then MySQL is not installed on your computer. Contact your
system administrator.
If MySQL is running, enter your database by typing (replace "dbname" with the name of your MySQL database):
use dbname;
You should get the response:
Database changed
If it didn't work:
If you got a response such as
ERROR 1044: Access denied for user
the problem may be that you need to create a database. My
system administrator did this when he set up my account, so I don't know how to do it. Look in the MySQL documentation.
Now create a table in your database. Replace "tablename" with the name of your table.
CREATE TABLE tablename (
first_name VARCHAR (25),
last_name VARCHAR (25)
);
Now check that your table is there by typing:
show tables;
You should get a list of tables:
+------------------+
| Tables in dbname |
+------------------+
| tablename |
+------------------+
2 rows in set (0.00 sec)
If PHP and MySQL are running, then the next chapter will show
you how to make HTML forms run PHP scripts that query a MySQL database. Now quit MySQL by typing
quit
You should get your UNIX prompt back. Now that everything is
running, we'll work on getting PHP and MySQL to talk to each other and to HTML.