Tuesday, February 15, 2005
mySQL Hour 4
Okay, mySQL Hours 1 to 3 covered basic databasey stuff. Hour 3 touched on "normalisation", which is something I haven't come across in my many hours playing around with the QBE grid in MS Access!
Hour 4 gets into the detail of how mySQL actually works.
We are introduced to several mySQL applications; most bundled with the distribution, some that need to be got from other sources.
mySQL monitor
First up is mySQL monitor. This is a command line interface (read the book p.40!) with mySQL.
Bingo, you've started mysql monitor and have a mysql> prompt in your DOS window.
If your using Linux then it's a bit different but not much.
Then onto trying out some commands:
use test;
Being about the extent of it for mysql monitor.
Before you move on though, and the book doesn't tell you this, you need to end your mysql monitor session and get back to the c:\mysql\bin> prompt or mysqladmin won't work.
Here's how: type exit at the mysql> prompt.
Handy DOS window tip
Okay, you can probably figure this yourselves but let me save you the bother.
You can't cut and paste windows-styley in the DOS window, it just doesn't do that! Instead right-click your mouse, select Select All and then hit Enter / Return. Strangely enough the contents of the DOS window are copied to your clipboard and you can then paste them using Ctrl + V into your favourite, Notepad.
Means you can print out the scree from mysqladmin --help (see below) and read it at you leisure.
Escaping characters
Veterans of TT281 (aka Javascript) will remember that sometimes you need to "escape characters". You need to do it in SQL too! Luckily the escape character is the good old backslash : "\". So no excuses!
En passant we are told to use either single or double quotes consistently. It doesn't matter, except that single quotes (like this: ') are the wider SQL standard. I'll be using single quotes then.
mySQL administration
Start up DOS, change directories and then start using mySQL administration.
It's not hard, you know when you're using mySQL admin because you type:
mysqladmin
in front of everything you do.
You can:
mysqladmin create test_DB
mysqladmin drop test_DB
and even
mysqladmin status
Go on, you can do it! And it's fun!
mysqldump
While you're there at the c:\mysql\bin> prompt you can mysqldump too!
You can
mysqldump test_DB
if you haven't just "dropped" it (keep up!).
You can
mysqldump test_DB > mydump.sql
which dumps your dbase into an sql file - handy.
When you get stuck you can
mysqldump --help
and it helps you. Complicated isn't it?
What about the ;'s?
Every so often something pops up about commands ending in ;s but they aren't doing it in the book. Why not I wonder? Is it because these are application commands we are issuing here and not propa SQL?????
I think I'll ask....
EDIT: I asked in the Teach forum and this is what Barbara said in reply:
"Just SQL commands must have semi-colons. The command prompts are different - no colons semi or otherwise required!"
Thanks Barbara!
phpMyAdmin
Is a browser based php tool for playing with mySQL. You need to have php installed (see TT381 for further details).
MySQL-Front
IS FREE for Windows users; Linux users, you can't have it, get over it. It's a bit like MSAccess, apparently...
MySQLManager
Is included in the distribution, alledgedly. I'll check later.
Summary
That didn't take an hour did it?
Still haven't found all the bits I think I need about setting up a database and a user so I can verify my myODBC / mySQL install is working okay.
Maybe mySQL Hour 5 will hold the answers?
;0)
Hour 4 gets into the detail of how mySQL actually works.
We are introduced to several mySQL applications; most bundled with the distribution, some that need to be got from other sources.
mySQL monitor
First up is mySQL monitor. This is a command line interface (read the book p.40!) with mySQL.
- Start up your DOS prompt (in Windows: Start>Run type in either "dosprompt" or "cmd", dependent on your Windows version).
- Change directory: cd C:\mysql\bin
- Start mysql monitor by typing: mysql
Bingo, you've started mysql monitor and have a mysql> prompt in your DOS window.
If your using Linux then it's a bit different but not much.
Then onto trying out some commands:
use test;
Being about the extent of it for mysql monitor.
Before you move on though, and the book doesn't tell you this, you need to end your mysql monitor session and get back to the c:\mysql\bin> prompt or mysqladmin won't work.
Here's how: type exit at the mysql> prompt.
Handy DOS window tip
Okay, you can probably figure this yourselves but let me save you the bother.
You can't cut and paste windows-styley in the DOS window, it just doesn't do that! Instead right-click your mouse, select Select All and then hit Enter / Return. Strangely enough the contents of the DOS window are copied to your clipboard and you can then paste them using Ctrl + V into your favourite, Notepad.
Means you can print out the scree from mysqladmin --help (see below) and read it at you leisure.
Escaping characters
Veterans of TT281 (aka Javascript) will remember that sometimes you need to "escape characters". You need to do it in SQL too! Luckily the escape character is the good old backslash : "\". So no excuses!
En passant we are told to use either single or double quotes consistently. It doesn't matter, except that single quotes (like this: ') are the wider SQL standard. I'll be using single quotes then.
mySQL administration
Start up DOS, change directories and then start using mySQL administration.
It's not hard, you know when you're using mySQL admin because you type:
mysqladmin
in front of everything you do.
You can:
mysqladmin create test_DB
mysqladmin drop test_DB
and even
mysqladmin status
Go on, you can do it! And it's fun!
mysqldump
While you're there at the c:\mysql\bin> prompt you can mysqldump too!
You can
mysqldump test_DB
if you haven't just "dropped" it (keep up!).
You can
mysqldump test_DB > mydump.sql
which dumps your dbase into an sql file - handy.
When you get stuck you can
mysqldump --help
and it helps you. Complicated isn't it?
What about the ;'s?
Every so often something pops up about commands ending in ;s but they aren't doing it in the book. Why not I wonder? Is it because these are application commands we are issuing here and not propa SQL?????
I think I'll ask....
EDIT: I asked in the Teach forum and this is what Barbara said in reply:
"Just SQL commands must have semi-colons. The command prompts are different - no colons semi or otherwise required!"
Thanks Barbara!
phpMyAdmin
Is a browser based php tool for playing with mySQL. You need to have php installed (see TT381 for further details).
MySQL-Front
IS FREE for Windows users; Linux users, you can't have it, get over it. It's a bit like MSAccess, apparently...
MySQLManager
Is included in the distribution, alledgedly. I'll check later.
Summary
That didn't take an hour did it?
Still haven't found all the bits I think I need about setting up a database and a user so I can verify my myODBC / mySQL install is working okay.
Maybe mySQL Hour 5 will hold the answers?
;0)