|
January 2004 Technical Tip – Getting Started with MySQL
MySQL is a popular DBMS, particularly for data driven web sites using PHP (PHP stands for hypertext preprocessor and is used for server-side scripting.) This month I will show you how to set up and use MySQL. (Note: I am using Microsoft XP Home edition.)
Getting MySQL
- Although available as a single package, MySQL is often found bundled with Apache webserver and PHP: I downloaded the trio as minixampp-win32-1.2.zip from http://www.apachefriends.org/wampp-en.html and unzipped minixampp-win32-1.2.zip into c:\minixampp
- Open a command prompt window by choosing Start > Programs > Accessories > Command Prompt
- Go to the unzipped folder by typing cd\minixampp
- Configure the trio by executing the batch file setup_xampp.bat
Starting the MySQL server
- Still within the command prompt window, and still within the unzipped folder, execute the batch file mysql_start.bat
- Do not close the window while the MySQL server is running (you can minimize it, but do not close it.)
Executing MySQL
- Open another command prompt window.
- Type cd\minixampp\mysql\bin and press Enter.
- Type mysql and press Enter.
- Note the MySQL prompt is mysql>
- MySQL commands can be entered over multiple lines. All commands must end with a semicolon.
Some MySQL commands
- The following should be self-explanatory if you know SQL. If you don't know SQL, then give us a call (a shameless plug!)
show databases;
create database mydatabase;
use mydatabase;
create table mytable (name char(10), age int(2), gender char(1));
insert into mytable values ('William', 21, 'M');
insert into mytable values ('Cora', 19, 'F');
insert into mytable values ('Hannah', 15, 'F');
insert into mytable values ('Emma', 13, 'F');
update mytable set age = age + 1 where name = 'Emma';
select * from mytable;
+---------+------+--------+
| name | age | gender |
+---------+------+--------+
| William | 21 | M |
| Cora | 19 | F |
| Hannah | 15 | F |
| Emma | 14 | F |
+---------+------+--------+
quit;
Stopping the MySQL server
- Open another command prompt window.
- Type cd\minixampp and press Enter.
- Type mysql_stop.bat and press Enter.
- You can now close all open Command Prompt windows.
Learning more
Looking ahead
- Be sure to check back next month when I will show you how to access MySQL databases from Java!
Go to the articles index.
Written by Bill Qualls. Copyright © 2004 by Caliber Data Training 800.938.1222
|