Ice9web.com

 

INTRODUCTING MySQL

It is the database software (DBMS or Database Management System) that actually does all the work of storing, retrieving, managing, and manipulating data. MySQL is a DBMS; that is, it is database software.


MySQL has been around for a long time, and is now installed and in use at millions of installations worldwide. Why do so many organizations and developers use MySQL? Here are some of the reasons:
Cost MySQL is open-source, and is usually free to use (and even modify) the software without paying for it. Performance MySQL is fast (make that very fast).
Trusted MySQL is used by some of the most important and prestigious organizations and sites, all of whom entrust it with their critical data.
Simplicity MySQL is easy to install and get up and running.

 

What Is MySQL?

In the previous tutorial you learned about databases and SQL. As explained, it is the database software (DBMS or Database Management System) that actually does all the work of storing, retrieving, managing, and manipulating data. MySQL is a DBMS; that is, it is database software.

MySQL has been around for a long time, and is now installed and in use at millions of installations worldwide. Why do so many organizations and developers use MySQL? Here are some of the reasons:

  • Cost MySQL is open-source, and is usually free to use (and even modify) the software without paying for it.
  • Performance MySQL is fast (make that very fast).
  • Trusted MySQL is used by some of the most important and prestigious organizations and sites, all of whom entrust it with their critical data.
  • Simplicity MySQL is easy to install and get up and running.

In fact, the only real technical criticism of MySQL is that it has not always supported the functionality and features offered by other DBMSs. But as new features are added to each new version, this is changing.

 

Client-Server Software

DBMSs fall into two categories: shared filebased and client-server. The former (which include products such as Microsoft Access and FileMaker) are designed for desktop use and are generally not intended for use on higher-end or more critical applications.

Databases such as MySQL, Oracle, and Microsoft SQL Server are client-serverbased databases. Client-server applications are split into two distinct parts. The server portion is a piece of software that is responsible for all data access and manipulation. This software runs on a computer called the database server.

Only the server software interacts with the data files. All requests for data, data additions and deletions, and data updates are funneled through the server software. These requests or changes come from computers running client software. The client is the piece of software with which the user interacts. If you request an alphabetical list of products, for example, the client software submits that request over the network to the server software. The server software processes the request; filters, discards, and sorts data as necessary; and sends the results back to your client software.

 

Note

How Many Computers? The client and server software may be installed on two computers or on one computer. Regardless, the client software communicates with the server software for all database interaction, be it on the same machine or not.

All this action occurs transparently to you, the user. The fact that data is stored elsewhere or that a database server is even performing all this processing for you is hidden. You never need to access the data files directly. In fact, most networks are set up so that users have no access to the data, or even the drives on which it is stored.

Why is this significant? Because to work with MySQL you'll need access to both a computer running the MySQL server software and client software with which to issue commands to MySQL:

  • The server software is the MySQL DBMS. You can be running a locally installed copy, or you can connect to a copy running a remote server to which you have access.
  • The client can be MySQL-provided tools, scripting languages (such as Perl), web application development languages (such as ASP, ColdFusion, JSP, and PHP), programming languages (such as C, C++, and Java), and more.

 

MySQL Versions

Client tools are revisited in a moment. First, a quick word about DBMS versions.

The current version of MySQL is version 5 (although MySQL 3 and 4 are in use in many organizations). Here are the major changes introduced in recent revisions:

  • 4 InnoDB engine adding support for transactions and more (Tutorial 31, "Managing Transaction Processing"), unions (Tutorial 22, "Combining Queries"), improved full text searching (Tutorial 23, "Full-Text Searching"), and more.
  • 4.1 Significant additions to function libraries, sub-queries (Tutorial 19, "Working with Sub-queries"), integrated help, and more.
  • 5 Stored procedures (Tutorial 28, "Working with Stored Procedures"), triggers (Tutorial 30, "Using Triggers"), cursors (Tutorial 29, "Using Cursors"), views (Tutorial 27, "Using Views"), and more.
  • Versions 4.1 and 5 added significant functionality to MySQL, much of which is covered in the later tutorials in this book.

Tip

Use 4.1 or Higher MySQL 4.1 introduced significant changes to the MySQL function libraries, and this book was written for use with that version or later. While much of the early content does indeed apply to MySQL 3 and 4, many of the examples will not work with those versions.

Note

Version Requirements Noted Any tutorial that requires a specific version of MySQL is clearly noted as such at the start of that tutorial.

Caution

Beta Software At the time that this book goes to press, MySQL 5 is still in beta and is not yet final-release software. This does not mean that you cannot use MySQL 5, but it does mean that you should proceed with caution as the software might contain bugs or problems that have yet to be addressed.

 

MySQL Tools

As just explained, MySQL is a client-server DBMS, and so to use MySQL you'll need a client, an application that you'd use to interact with MySQL (giving it commands to be executed).

There are lots of client application options, but when learning MySQL (and indeed, when writing and testing MySQL scripts) you are best off using a utility designed for just that purpose. And there are three tools in particular that warrant specific mention.

 
mysql Command-Line Utility

Every MySQL installation comes with a simple command-line utility called mysql. This utility does not have any drop-down menus, fancy user interfaces, mouse support, or anything like that.

Typing mysql at your operating system command prompt brings up a simple prompt that looks like this:

Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 14 to server version: 5.0.4-nt
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql>

CommandLine 

Note

MySQL Options and Parameters If you just type mysql by itself, you might receive an error message. This will likely be because security credentials are needed or because MySQL is not running locally or on the default port.mysqlaccepts an array of command-line parameters you can (and might need to) use. For example, to specify a user login name of ben, you'd usemysql u ben. To specify a username, host name, port, and be prompted for a password, you'd use mysql u ben p h myserver P 9999.



A complete list of command-line options and parameters can be obtained using mysql help .



Of course, your version and connection information might differ, but you'll be able to use this utility regardless. You'll note that

Commands are typed after themysql>prompt.

Commands end with; or \g; in other words, just pressing Enter will not execute the command.

Type helpor\hto obtain help. You can also provide additional textto obtain help on specific commands (for example,help selectto obtain help on using theSELECTstatement).

Type quit orexitto quit the command-line utility.

Themysqlcommand-line utility is one of the most used and is invaluable for quick testing and executing scripts (such as the sample table creation and population scripts mentioned in the previous tutorial and in Appendix B, "The Example Tables"). In fact, all of the output examples used in this book are grabs from the mysql command-line output.



Tip

Familiarize Yourself with the mysql Command-Line Utility Even if you opt to use one of the graphical tools described next, you should make sure to familiarize yourself with the mysql command-line utility, as this is the one client you can safely rely on to always be present (as it is part of the core MySQL installation).





MySQL Administrator

MySQL Administrator is a graphical interactive client designed to simplify the administration of MySQL servers.



Note

Obtaining MySQL Administrator MySQL Administrator is not installed as part of the core MySQL installation. Instead, it must be downloaded fromhttp://dev.mysql.com/downloads/ (versions are available for Linux, Mac OS X, and Windows, and source code is downloadable, too).



MySQL Administrator prompts for server and login information (and allows you to save server definitions for future selection), and then displays icons that allow for the selection of different views. Amongst these are

Server Information displays status and version information about the connected server and client.

Service Control allows you to stop and start MySQL as well as specify server features.

User Administration is used to define MySQL users, logins, and privileges.

Catalogs lists available databases and allows for the creation of databases and tables.



Note

Create a Datasource for This Book You might want to use theCreate New Schema option to create a datasource for the tables and tutorials in this book. The examples use a datasource namedcrashcourse; feel free to use the same name or one of your choice.



Tip

Quick Access to Other Tools The MySQL Administrator Tools menu contains options to launch themysqlcommand-line utility (described previously) and the MySQL Query Browser (described next).

In fact, the MySQL Query Browser also contains menu options to launch themysql command-line utility and the MySQL Administrator.



MySQL Query Browser

MySQL Query Browser is a graphical interactive client used to write and execute MySQL commands.




Note

Obtaining MySQL Query Browser Like MySQL Administrator, MySQL Query Browser is not installed as part of the core MySQL installation. Instead, it too must be downloaded fromhttp://dev.mysql.com/downloads/ (versions are available for Linux, Mac OS X, and Windows, and source code is downloadable, too).



Query Browser in MySQL 

MySQL Query Browser prompts for server and login information (saved definitions are shared between MySQL Query Browser and MySQL Administrator) and then displays the application interface. Note the following:

MySQL commands are typed into the window at the top of the screen. When the statement has been entered, click the Execute button to submit it to MySQL for processing.

Results (if there are any) are displayed in a grid in the large area to the left of the screen.

Multiple statements and results can be rendered in their own tabs to allow for rapid switching between them.

On the right of the screen is a tab that lists all available datasources (called schemata here), expand any datasource to see its tables, and expand any table to see its columns.

You can also select tables and columns to have MySQL Query Browser write MySQL statements for you.

To the right of the Schemata tab is a History tab that maintains a history of executed MySQL statements. This is very useful when you need to test different versions of MySQL statements.



History TAB in MySQL 

Help on MySQL syntax, functions, and more is available at the bottom right of the screen.



Tip

Execute Saved Scripts You can use MySQL Query Browser to execute saved scriptsthe scripts used to create and populate the tables used in throughout this book, for example. To do this, select File, Open Script, select the script (which will be displayed in a new tab), and click the Execute button.

Creating Scrip in MySQL
Example this is running the MySQL script downloaded selecting "Create" script

 Summary

In this tutorial, you learned what exactly MySQL is. You were also introduced to several client utilities (one included command-line utility and two optional but highly recommended graphical utilities).

[Next]