In this chapter, you'll learn how to connect and login to MySQL, how to issue MySQL statements, and how to obtain information about databases and tables.
Making the Connection
Now that you have a MySQL DBMS and client software to use with it, it would be worthwhile to briefly discuss connecting to the database.
MySQL, like all client-server DBMSs, requires that you log in to the DBMS before being able to issue commands. Login names might not be the same as your network login name (assuming that you are using a network); MySQL maintains its own list of users internally, and associates rights with each.
When you first installed MySQL, you were probably prompted for an administrative login (often named root) and a password. If you are using your own local server and are simply experimenting with MySQL, using this login is fine. In the real world, however, the administrative login is closely protected (as access to it grants full rights to create tables, drop entire databases, change logins and passwords, and more).
To connect to MySQL you need the following pieces of information:
The hostname (the name of the computer)—this is localhost if connecting to a local MySQL server
The port (if a port other than the default 3306 is used)
A valid user name
The user password (if required)
As explained in Chapter 2, "Introducing MySQL," all of this information can be passed to the mysql command-line utility, or entered into the server connection screen in MySQL Administrator and MySQL Query Browser.
After you are connected, you have access to whatever databases and tables your login name has access to. (Logins, access control, and security are revisited in Chapter 28, "Managing Security").