This chapter provides an introductory tutorial on MySQL by demonstrating how to create and use a simple database using the MySQL client program. MySQL (sometimes called "terminal monitor" or just "watch") is an interactive program that allows you to connect to a MySQL server, run queries, and see the results. MySQL can be used in batch mode: You put the query in a file beforehand and tell MySQL to execute the contents of the file. Two ways to use MySQL are covered here.
To see a list of selected items provided by MySQL, call it with the--HELP option:
shell> MySQL--help
This chapter assumes that MySQL has been installed on your machine and that you have a MySQL server that you can connect to. If this is not true, contact your MySQL administrator. (If you are an administrator, you will need to consult the other chapters of this manual.) )
This chapter describes the entire process of establishing and using a database. If you are interested only in accessing a database that already exists, you may want to skip the chapters that describe how to create a database and the tables it contains.
Since this chapter is essentially a tutorial, many details are necessary to be omitted. For more information on the topics covered here, consult the relevant chapters of this manual.
8.1 Connection and Disconnect service providers
In order to connect to the server, when you call MySQL, you will usually need to provide a MySQL username and very likely, a password. If the server is running on a machine that you are not logged on to, you will also need to specify the host name. Contact your administrator to find out what connection parameters you should use to connect (that is, the host, user name, and password used). Once you know the correct parameters, you should be able to connect like this:
shell> mysql-h host-u user-p
Enter Password: ********
On behalf of your password; When MySQL displays enter password: When prompted, enter it.
If you can work, you should see some introductory information after the mysql> hint:
shell> mysql -h host -u user -p
Enter password: ********
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 459 to server version: 3.22.20a-log
Type 'help' for help.
mysql>
The prompt tells you that MySQL is ready to enter commands for you.
Some MySQL installations allow users to connect "anoymous" (anonymous) users to servers running on the local host. If this is the case in your machine, you should be able to connect to the server by calling MySQL without any options:
shell> MySQL
After you successfully connect, you can break into quit at any time by mysql> prompt:
Mysql> QUIT
Bye
You can also type control-d disconnect.