You are on page 1of 14

MySQL Basics -- A Helpful MySQL Tutorial Introduction Welcome.

This MySQL tutorial is a guide for new MySQL users, providing a referen ce of very basic, step by step, instructions on how to get started. This MySQL h elp page also gives more advanced users assistance in upgrading and running mult iple versions of MySQL on a computer at the same time. MySQL is an SQL based relational database management system (DBMS) that runs und er a broad array of operating systems. MySQL is frequently used by PHP and Perl scripts. The SQL commands discussed in this tutorial apply to MySQL operating un der all operating systems. Only the installation instructions are Windows specif ic. The focus is on Windows XP Professional and Windows 2000 Professional machin es. We'll be covering the installation of MySQL versions 5.0.51b, 4.1.16 as well as how to configure everything so they'll all be able to run on your system at the same time. Plus, the data directories will be moved to another location in order to make backups easier. If you only want to install one version of MySQL, ignor e the instructions relating to the other versions. If your operating system or versions of MySQL are different, the instructions sh ould still work, but keep an eye out for slight differences, like which working directory you'll need to be in. Usage: Commands to type in and items that require appropriate substitutions are display ed like this. Resulting screen text looks like this. File names appear in this fashion. Contents Windows 2000 and Windows XP Installation Creating Command Prompt Shortcuts Operating System Privileges for the MySQL Service File System Permissions for the MySQL Directories Quick Tips for Other Windows Operating Systems Start the Client and Log In Tighten Security Creating a Simple Database and Displaying its Structure Putting Data into a Table Adding Fields Multi-line Command Entry Insert Some More Records into the Table Updating Existing Records Deleting Records Time to Call it Quits In Closing Windows 2000, XP and NT 4.0 Installation Log in to your computer using an account having Administrator privileges. If you're not upgrading, just skip down to the next section. If you are upgrading, there are MANY changes that you HAVE TO be aware of. Caref ully read the pages in the MySQL manual that apply to you. If you intend to jump over a release series in your upgrade (e.g.: going straight from 4.0 to 5.0) yo u are strongly advised NOT to do so. You should do the upgrade process one relea

se series at a time (e.g.: go from 4.0 to 4.1, then to 5.0). Upgrading from MySQL 5.0 Upgrading from MySQL 4.1 to 5.0 (also includes several changes made between 5.0 versions) Upgrading from MySQL 4.0 to 4.1 Backup Old Data Here's a quick rundown of how to save your old MySQL data so it can be used in y our new system. Open up a Command Prompt window. If you don't know how to do that, go to Sta rt | Run, then type in cmd and hit ENTER. Switch to the drive which has your present mysql\bin directory. Eg: L:\> C: Move into the MySQL bin directory: cd mysql\bin Dump all of your data: mysqldump -u root -p -A -r C:\secure\myolddata.sql Stop the MySQL service: net stop mysql. If your service has a different name , do this net stop service_name. The ISAM table format has been deprecated in 4.0 and removed from 5.0. If ha ve some tables in that format, you'll need to fix that now. There are several wa ys to do this. Here are three possibilities: sed: ren C:\secure\myolddata.sql C:\secure\myolddataorig.sql sed 's/^) TYPE=ISAM/) TYPE=MyISAM/' C:\secure\myolddataorig.sql > C: \secure\myolddata.sql Perl: ren C:\secure\myolddata.sql C:\secure\myolddataorig.sql perl -wpe 's;^\) TYPE=ISAM;\) TYPE=MyISAM;i' < C:\secure\myolddataor ig.sql > C:\secure\myolddata.sql Your favorite text editor: open C:\secure\myolddata.sql then do a search and replace on TYPE=ISAM to TYPE=MyISAM. Remove the existing service by typing in mysqld --remove. If your service ha s a different name, do this mysqld --remove service_name Jump up two directory levels: cd ..\.. Rename your old mysql directory as a backup: ren mysql mysqlold Get and Install a Recent Version Download the "Windows ZIP/Setup.EXE" file for the versions you want: 5.0, an d/or 4.1. For now, do NOT pick the "Windows Essentials (x86)" or "Without instal ler (unzip in C:\)" downloads. Find the downloaded file, unzip it and start the setup program: Via Cygwin: cd /path/to/file unzip mysql-version.number-win.zip -d temp chmod 700 temp/* explorer temp Double click on Setup.exe. Via Windows XP: Open up Windows Explorer. If you don't know how to do that, go to St art | Run, type in explorer and hit ENTER. Find the downloaded file. Double click on it. Windows XP has a built in zip file reader. In the zip viewer, double click on Setup.exe . Via WinZip or PKZIP for Windows, or other such utilities: Open up Windows Explorer. If you don't know how to do that, go to St art | Run, type in explorer and hit ENTER. Find the downloaded file.

Double click on it. Extract the files. Flip back to Windows Explorer and double click on Setup.exe . In the Installation Program: MySQL 5.0.x and 4.1.x: In the "Please select a setup type" step, click the "Custom" radio b utton, then "Next." The next step gives you choices of which components to install and w here to install it. Click the "Change" button at the bottom right of the dialog box and put in C:\program files\mysql50\ then click "OK" If you're upgrading, make sure to click on the plus sign next to the "Developer Components" item, then click on "Scripts, Examples" and set it to "T his feature will be installed on the local hard drive." Adjust the other entries per your desires. Make sure the "MySQL Serv er" and the "Client Programs" are selected. Once you have everything lined up as you want, click "Next." Click "Install." When you get to the "MySQL.com Sign-Up" step, let's cut to the chase ... click the "Skip Sign-Up" radio button and go to "Next." UN-check "Configure the MySQL Server" and click "Finish." Taking a moment to make Command Prompt shortcuts now will save loads of time later: Open Windows Explorer (Start | Run, explorer, ENTER). Navigate to C:\Documents and Settings\All Users\Start Menu directory. Create a new directory (File | New | Folder). That makes a new folder ca lled, "New Folder" (imagine that!) which is now ready for you to type in a new n ame for. So, type in Databases and hit ENTER. Now hit ENTER again to get into that folder. Open another Windows Explorer window. In the Address Bar, type in %UserProfile% and hit the ENTER key. If the Address Bar isn't visible, in Windows Explorer's menu: View | Toolbars | Address Bar. Navigate to the Start Menu\Programs\Accessories directory. Select the Command Prompt file. Hit CTRL-C Now come back to the "Databases" folder window and hit CTRL-V. That shou ld have pasted a copy of the Command Prompt shortcut in your new directory. Select the Command Prompt file. What you do here depends on whether you're installing 5.0 and/or 4.1. MySQL 5.0.x: Use the follow these steps verbatim. MySQL 4.1.x: Use these steps, but change 50 to 41. Multiple versions: Do the steps for 50, make a copy of MySQL 50 Prompt and then follow steps I and II, but change 50 to 41. Hit the F2 key and rename the shortcut MySQL 50 Prompt then hit ENTE R. Open it's properties via File | Properties and go to the "Shortcut" tab, then the "Start In" box and type the following in, including the quotes: "C :\program files\mysql50\bin" Go to the "Options" tab and check the "QuickEdit mode" and "Insert m ode" boxes. Go to the "Layout" tab and go to the "Height" box in the "Screen buf fer size" section and put in a larger number, like 2000.

Click OK Now, you'll be able to quickly get to either of the Command Prompts by g oing to Start | Databases | MySQL 50 Prompt. Plus, you'll be able to paste commands into the the Command Prompt! To d o that, copy the command from this tutorial (or wherever) then go to the Command Prompt window and hit the following keys: ALT-SPACE (to open the menu in the upper left corner of the window) E (the access key for Edit) P (the access key for Paste) For the rest of this lesson, we'll be calling this these the "MySQL 50 S hortcut" and "MySQL 41 Shortcut" Time to create the data directories. MySQL's data files should be stored on a drive, or a portion thereof, that contains your other data files. This will si mplify finding and backup up your information. The M: drive on my machine is ded icated solely to storing actively used data. That's the location we'll use in th is tutorial. Open up a Command Prompt window. If you don't know how to do that, go to Start | Run, then type in cmd and hit ENTER. Switch to the drive where the data will be placed: C:\> M: Make the needed directories: MySQL 5.0.x: mkdir mkdir mkdir mkdir mkdir mysql50 mysql50\data mysql50\data\mysql mysql50\ibdata mysql50\iblogs

MySQL 4.1.x: mkdir mkdir mkdir mkdir mkdir mysql41 mysql41\data mysql41\data\mysql mysql41\ibdata mysql41\iblogs

Copy the default mysql database/privileges to the new location: MySQL 5.0.x: copy "C:\program files\mysql50\data\mysql" mysql50\data\mysql MySQL 4.1.x: copy "C:\program files\mysql41\data\mysql" mysql41\data\mysql I suggest putting empty my.cnf files in place in order to keep your MySQL se rvers from being subverted. While this step isn't strictly necessary, it's bette r to be safe than sorry. We'll do this via the Command Prompt window we were usi ng above. Be aware that Windows considers .cnf files to be a "SpeedDial" configuration file and automaticlaly hides the file extension. You can make the extension vis ible via Windows Explorer's "hide file extensions" option (Tools | Folder Option s | View). Also note that Windows Server 2003 hides the extension even if this o ption is turned off. Just MySQL 5.0.x: notepad mysql50\data\my.cnf In notepad, type in [mysqld] , save the file and exit. copy mysql50\data\my.cnf "C:\program files\mysql50\data"

Just MySQL 4.1.x: notepad mysql41\data\my.cnf In notepad, type in [mysqld] , save the file and exit. copy mysql41\data\my.cnf "C:\program files\mysql41\data" All of the above notepad mysql50\data\my.cnf In notepad, type in [mysqld] , save the file and exit. copy mysql50\data\my.cnf "C:\program files\mysql50\data" copy mysql50\data\my.cnf mysql41\data copy mysql50\data\my.cnf "C:\program files\mysql41\data" The my.cnf configuration files need to be put in place. First, we'll put bla nk files in the default locations in order to prevent the server from potential subversion. Do this via the Command Prompt window we were using above. notepad C:\my.cnf In notepad, paste in the following, then adjust the the port numbers and drive letters and paths as needed. NOTE: This sample file puts 5.0.x on the default port (3306) and 4.1.x o n 3341. These port numbers will be used throughout the rest of the tutorial. So, if you change anything in your my.cnf file, you will need to adjust all of our commands accordingly. On the command line, MySQL uses the -P flag to tell the cl ient which port to connect to, for example -P 3341. # # # # # This config file contains settings for MySQL versions 5.0.x and 4.1.x. Be aware that only one server instance can be on a given port. This sample puts version 5.0.x on MySQL's default port, 3306. Adjust the port numbers to suit your situation.

[mysql] # Displaying the version number in the prompt # helps when running multiple instances. prompt = mysql\\_\v>\\_ [mysqld-5.0] port = 3306 basedir = C:/Program Files/mysql50/ datadir = M:/mysql50/data/ innodb_data_home_dir = M:/mysql50/ibdata/ innodb_log_group_home_dir = M:/mysql50/iblogs/ innodb_data_file_path = ibdata1:10M:autoextend # Make table names case sensitive. # Ensures portability when moving applications to other os's. set-variable = lower_case_table_names=0 # Roll back entire transactions that time out, # OPTION AVAILABLE SINCE 5.0.32. innodb_rollback_on_timeout = 1 [mysqld-4.1] port = 3341 basedir = C:/Program Files/mysql41/ datadir = M:/mysql41/data/ innodb_data_home_dir = M:/mysql41/ibdata/

innodb_log_group_home_dir = M:/mysql41/iblogs/ innodb_data_file_path = ibdata1:10M:autoextend # Make table names case sensitive. # Ensures portability when moving applications to other os's. set-variable = lower_case_table_names=0 Save the file and exit. Next, we need to "install" the appropriate MySQL services. MySQL 5.0: Open the MySQL 50 Shortcut, pick one of the following and typ e its command into the Command Prompt: NT/2000/XP. Named pipes. mysqld-nt --install mysql50 Transactions. mysqld --install mysql50 Support for debugging MySQL crashes. mysqld-debug --install mysql50 MySQL 4.1: Open the MySQL 41 Shortcut, pick one of the following and typ e its command into the Command Prompt: NT/2000/XP. Named pipes. mysqld-nt --install mysql41 Transactions. mysqld --install mysql41 Support for debugging MySQL crashes. mysqld-debug --install mysql50 Good security procedures call for running services as a non-privileged user. So, let's create such a user and configure the MySQL services to use it: net user mysql * /add /passwordreq:yes /passwordchg:no /comment:"runs My SQL services" You'll be prompted for the password. Perform the following steps for each mysql server instance, substituting your version numbers for the underscores (__): Start up the services manager by typing in services.msc and hitting ENTER. Locate the "mysql__" service in the right hand pane and double click it. Go to the "Log On" tab Click the "This account" radio button Type mysql into the box. Enter the password into the "Password" and "Confirm password" inputs . Hit OK Let's lock down the file permissions on the directories we created by enteri ng the following commands into a Command Prompt: cacls C:\my.cnf /g administrators:f system:r "authenticated users":r If you may get the following error message: The cacls command can only be ru n on disk drives that use the NTFS file system. Don't worry about it (for now). Skip all the cacls commands in the rest of our tutorial. Enter each line below separately because some of them require user confirmat ion. MySQL 5.0.x: cacls M:\mysql50 /t /g administrators:f system:f mysql:c cacls M:\mysql50\data\my.cnf /t /g administrators:f system:r cacls "C:\program files\mysql50" /t /g administrators:f system:f mysql:r "authenticated users":r cacls "C:\program files\mysql50\data" /t /g administrators:f

MySQL 4.1.x: cacls M:\mysql41 /t /g administrators:f system:f mysql:c cacls M:\mysql41\data\my.cnf /t /g administrators:f system:r cacls "C:\program files\mysql41" /t /g administrators:f system:f mysql:r "authenticated users":r cacls "C:\program files\mysql41\data" /t /g administrators:f Start the services: MySQL 5.0.x: net start mysql50 MySQL 4.1.x: net start mysql41 If System error 1069 has occurred comes up, your passwords didn't match. You can create a new password by typing net user mysql * into the Command Prompt. T hen put that new password into the MySQL services' properties' "Log On" tab. Getting a System error 5 has occurred indicates problems getting to the dire ctory containing the MySQL executables (for example, insufficient permissions). If you get an error saying System error 1067 has occurred it means a configu ration directive in C:\my.cnf couldn't be processed. That can be due to a typogr aphical error in the name or value of a setting. Similarly, the path referred to by the setting's value could be inaccessible due to insufficient permissions. To help narrow down what's going on, check out the Event Viewer: Start | Run , then type in eventvwr.msc and hit ENTER. Click the "Application" item in the l eft pane. Now examine the top of the right hand pane for recent MySQL errors. Do uble click the first item and look at the message in the "Description" box. Either of the following mean there's a boo-boo in the path value assigned to the datadir setting in C:\my.cnf: Fatal error: Can't open privilege tables: Table 'mysql.host' doesn't exist or Warning: Can't create test file In this situation, make sure the actual path is a case-sensitive match to th e path in the configuration file and that the directories in question have the p ermissions they need to be accessed by the MySQL daemon. Then try the net start command again. Along the same lines, error logs showing Can't find messagefile 'C:\Program Files\mysql\share\english\errmsg.sys' points to a mismatch between the basedir value and the actual path to the My SQL executables. An unknown variable notice is clear enough, no? If there are no MySQL related error messages in the Event Log's Application section, you have a major typo in the C:\my.cnf. Perhaps one of the [mysql...] s ection headings are wrong. If you're upgrading and followed our instructions at the top of this tutoria l, now it's time to import your old data. These steps assume upgrading from 4.1 to 5.0. C:\Program Files\mysql50\bin> mysql -u root < C:\secure\myolddata.sql C:\Program Files\mysql50\bin> mysql -u root -f mysql < ..\share\mysql_fi x_privilege_tables.sql This SQL file was in the scripts directory prior to version 5.0.38. You can ignore all of the query error messages (for example Unknown colu mn, Duplicate column name, etc).

Log into the server using the permissions from your old MySQL installati on: C:\Program Files\mysql50\bin> mysql -u root -p mysql The upgrade script gives some privilges that you probably don't want mos t users having. Let's change them back (adjusting the "otherimportantusers..." b elow as needed for your system): mysql 5.0.51b-community-nt> UPDATE user SET Create_tmp_table_priv='N' WH ERE user NOT IN ('root', 'otherimportantusers...'); Exit the client and restart the server: mysql 5.0.51b-community-nt> exit C:\Program Files\mysql50\bin> net stop mysql50 C:\Program Files\mysql50\bin> net start mysql50 If you've never done this tutorial's "Tighten MySQL's Security" steps, b elow, check them out now. If you've already done them, you can jump down to the Start the Client section. Tighten MySQL's Security MySQL has good security controls, but the default installation is wide open. So, if you're doing a new installation, let's close things up before we go any further. In the following commands, don't forget that if you changed the ports in the my.cnf file, you'll have to adjust the port numbers here. MySQL 5.0.x: Activate the "MySQL 50 Shortcut" we created earlier then type in: mysql -u root mysql MySQL 4.1.x: Activate the "MySQL 41 Shortcut" we created earlier then type in: mysql -u root -P 3341 mysql (If you get the following error message: ERROR 2003 (HY000): Can't connect to MySQL server on 'localhost' (10061) That means the servers didn't stay started. The most likely reason is the my .cnf file has errors in it. Go back to the Start the services step and carefully read the section about checking the Event Viewer logs.) Once you are logged in, copy the following queries to Notepad and change New Pw to something unique. Now copy that and paste it into the command prompt windo w(s) you just opened. delete from user where Host <> 'localhost' and User <> 'root'; delete from db; update user set Password=password('NewPw') where User='root'; flush privileges; exit Tada! Quick Tips for Other Windows Operating Systems If you're using Windows 95, 98 or ME do not run mysqld --install. These operatin g systems don't have the ability to host a "service." So, you need to run MySQL as a standalone application by executing the command mysqld --standalone. I haven't run MySQL on these systems myself, so, for more information, check out the Starting MySQL on Windows 95, 98 or Me and Running MySQL on Windows section s of the manual or explore the MySQL Win32 Mailing List Archive. Start the Client and Log In

We'll be using MySQL 5.0.x here. Adjust the shortcut and port as necessary. Activate the "MySQL 50 Shortcut" we created earlier and type in mysql -u root -p then enter your password when prompted. You will then see the following output: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 1 to server version: 5.0.51b Type 'help;' or '\h' for help. Type '\c' to clear the buffer. If your root account doesn't have a password on it, the above command won't work for you. You really need to get on top of security. Log in without the pass word: mysql -u root mysql Then set a password (changing "NewPw", of course): update user set Password=password('NewPw') where User='root'; flush privileges; If you get an error saying Client does not support authentication protocol reque sted by server; consider upgrading SQL client when trying to connect, that means your client is from before version 4.1 while the server you are connecting to i s using version 4.1 or later. The best solution is to install a current version of the MySQL client. Creating a Simple Database and Displaying its Structure Instruct MySQL to setup a new database mysql 5.0.51b> create database database01; Database "database01" created. All that really does is create a new subdirectory in your M:\mysql50\data direct ory. Open the database mysql 5.0.51b> use database01 Database changed Create a table mysql 5.0.51b> create table table01 (field01 integer, field02 char(10)); Query OK, 0 rows affected (0.00 sec) !Enclose entire list of field names between one pair of parentheses. !Commas are used between each field. iA space may be used after the comma between fields. !A comma is not used after last field. !This, and all SQL statements, are concluded by a semicolon ";". List the tables mysql 5.0.51b> show tables; +----------------------+ | Tables in database01 | +----------------------+ | table01 | | table02 | +----------------------+

List the fields in a table mysql 5.0.51b> show columns from table01; +---------+----------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +---------+----------+------+-----+---------+-------+ | field01 | int(11) | YES | | | | | field02 | char(10) | YES | | | | +---------+----------+------+-----+---------+-------+

Congratulations! Pretty straightforward, eh? Putting Data into a Table Insert a record mysql 5.0.51b> insert into table01 (field01, field02) values (1, 'first'); Query OK, 1 row affected (0.00 sec) !Enclose entire list of field names between one pair of parentheses. !Enclose the values to be inserted between another pair of parentheses. !Commas are used between each field and between each value. iA space may be used after the comma between fields. List all the records in a table mysql 5.0.51b> select * from table01; +---------+---------+ | field01 | field02 | +---------+---------+ | 1 | first | +---------+---------+ Excellent! Adding Fields ...one field at a time mysql 5.0.51b> alter table table01 add column field03 char(20); Query OK, 1 row affected (0.04 sec) Records: 1 Duplicates: 0 Warnings: 0 ...more than one at a time mysql 5.0.51b> alter table table01 add column field04 date, add column field05 t ime; Query OK, 1 row affected (0.04 sec) Records: 1 Duplicates: 0 Warnings: 0 !The "add column" must be restated for each column. !Commas are used between each add column statement. iA space may be used after these commas. iThe MySQL Manual fully explains each possible column data type. Did it work? mysql 5.0.51b> select * from table01; +---------+---------+---------+---------+---------+ | field01 | field02 | field03 | field04 | field05 | +---------+---------+---------+---------+---------+

| 1 | first | NULL | NULL | NULL | +---------+---------+---------+---------+---------+ Now we're getting somewhere! Multi-line Command Entry The MySQL command line interface allows you to put a statement on one line or sp read it across multiple lines. There's no difference in syntax between the two. Using multiple lines allows you to break down the SQL statement into steps you m ay more easily comprehend. In multiple line mode, the interpreter appends each line to the prior lines. Thi s continues until you enter a semicolon ";" to close out the SQL statement. Once the semicolon is typed in and you hit enter, the statement is executed. Here's an example of the same exact SQL statement entered both ways: Single Line Entry mysql 5.0.51b> create table table33 (field01 integer,field02 char(30)); Multiple Line Entry mysql 5.0.51b> create table table33 -> (field01 -> integer, -> field02 -> char(30)); !Don't break up words: Valid Invalid mysql 5.0.51b> create table table33 -> (field01 -> integer, -> field02 -> char(30)); mysql 5.0.51b> create table table33 -> (field01 inte -> ger, -> field02 -> char(30)); !When inserting or updating records, do not spread a field's string across multi ple lines, otherwise the line breaks are stored in the record: Standard Operation mysql 5.0.51b> insert into table33 (field02) -> values -> ('Who thought of foo?'); Line Break Stored in Record mysql 5.0.51b> insert into table33 (field02) -> values -> ('Pooh thought -> of foo.'); Results mysql 5.0.51b> select * from table33; +---------+---------------------+ | field01 | field02 | +---------+---------------------+

| NULL | Who thought of foo? | | NULL | Pooh thought of foo. | +---------+---------------------+ Insert Some More Records into the Table Add this record mysql 5.0.51b> insert into table01 (field01,field02,field03,field04,field05) val ues -> (2, 'second', 'another', '1999-10-23', '10:30:00'); Query OK, 1 row affected (0.00 sec) !Quotes must go around text values. iStandard date format is "yyyy-mm-dd". iStandard time format is "hh:mm:ss". !Quotes are required around the standard date and time formats, noted above. iDates may also be entered as "yyyymmdd" and times as "hhmmss". If entered in th is format, values don't need to be quoted. iNumeric values do not need to be quoted. This holds true regardless of the data type a column is formatted to contain (e.g. text, date, time, integer). iMySQL has a useful command buffer. The buffer stores the SQL statements you've entered thus far. Using it keeps you from having to retype the same commands ove r and over. Let's use this next step as an example. Add another record using the command buffer (and optional date and time formats) Hit the up arrow key twice. Hit the ENTER key. Type in the new values between a pair parentheses and stick a closing semico lon on the end. (3, 'a third', 'more foo for you', 19991024, 103004); Hit the ENTER key. Voil! Is it in there? mysql 5.0.51b> select * from table01; +---------+-----------+------------------+------------+----------+ | field01 | field02 | field03 | field04 | field05 | +---------+-----------+------------------+------------+----------+ | 1 | first | NULL | NULL | NULL | | 2 | second | another | 1999-10-23 | 10:30:00 | | 3 | a third | more foo for you | 1999-10-24 | 10:30:01 | +---------+-----------+------------------+------------+----------+ It's in there! Now, we're almost done... Updating Existing Records Modify one field at a time !Again, be careful with syntax. Quote marks need to go around text but not aroun d numbers. mysql 5.0.51b> update table01 set field03='new info' where field01=1; Query OK, 1 row affected (0.00 sec)

Change multiple fields at once !Remember to put commas between each field you're updating. mysql 5.0.51b> update table01 set field04=19991022, field05=062218 where field01 =1; Query OK, 1 row affected (0.00 sec) So, what's up with our data? mysql 5.0.51b> select * from table01; +---------+-----------+------------------+------------+----------+ | field01 | field02 | field03 | field04 | field05 | +---------+-----------+------------------+------------+----------+ | 1 | first | new info | 1999-10-22 | 06:22:18 | | 2 | second | another | 1999-10-23 | 10:30:00 | | 3 | third one | more foo for you | 1999-10-24 | 10:30:01 | +---------+-----------+------------------+------------+----------+ Update multiple records in one stroke mysql 5.0.51b> update table01 set field05=152901 where field04>19990101; Query OK, 3 rows affected (0.00 sec) Survey says... mysql 5.0.51b> select * from table01; +---------+-----------+------------------+------------+----------+ | field01 | field02 | field03 | field04 | field05 | +---------+-----------+------------------+------------+----------+ | 1 | first | new info | 1999-10-22 | 15:29:01 | | 2 | second | another | 1999-10-23 | 15:29:01 | | 3 | third one | more foo for you | 1999-10-24 | 15:29:01 | +---------+-----------+------------------+------------+----------+ Wee haw! Deleting Records The delete command mysql 5.0.51b> delete from table01 where field01=3; Query OK, 1 row affected (0.01 sec) mysql 5.0.51b> select * from table01; +---------+---------+----------+------------+----------+ | field01 | field02 | field03 | field04 | field05 | +---------+---------+----------+------------+----------+ | 1 | first | new info | 1999-10-22 | 15:29:01 | | 2 | second | another | 1999-10-23 | 15:29:01 | +---------+---------+----------+------------+----------+ Time to Call it Quits mysql 5.0.51b> quit Bye In Closing

Now you know some rudimentary commands for running a database in MySQL. Since My SQL is operated by executing SQL calls, you have a broad array of very powerful tools at your disposal. For instance, you're able to display data from several t ables at once by joining related fields. Similarly, SQL permits complex displays, updates or deletions of multiple record s which fit specific criteria. So, your next step toward mastery is learning all about SQL. James Hoffman has put a tutorial page up on the web entitled Introduction to Str uctured Query Language. Another thing to note is MySQL offers good security features you'll need to use when operating on networks. To learn more p. Also, Paul chives of the ser group has about MySQL and how to use it, the manual should be your first sto DuBois' book, MySQL, comes highly recommended. In addition, the ar main list and the Win32 list are tremendous resources. The NYPHP u started a MySQL interest group you may find helpful.

If you're curious about database portability, you may find the Building Truly Po rtable Database Applications in PHP presentation interesting. If you'll be developing hypertext interfaces out our SQL Solution . It's a powerful, user at will make your job a snap! Similarly, you pular open source database abstraction layer to your databases using PHP, check friendly, platform independent API th might want to examine PEAR DB, a po (of which I'm the lead developer).

Also, if your scripts accept user input, the Form Solution is a handy tool for cl eaning user input, generating HTML / XHTML compliant date/time form elements, va lidating and formatting date/time inputs and holding all variables submitted by a form. The result is improved security and data quality.