5/23/2011

Acads this Weekend...

Okay. So, recently I have been reading about MySQL, where SQL stands for Structured Query Language, and MySQL is just one of the many versions of SQL. Although the different versions have their own specifications and special features, since SQL is ANSI standardized, there are a set of command that run on all the versions. Here is a overview of what I studied:


Basics:
1.General way to connect to the server is like this:

shell> mysql -h host_name -u user_name -p
where host_name is the server on which mysql runs, etc. and -p flag is for entering the password.

2.Once inside mysql, you can use the Quit command to exit from mysql. Most of the commands (exceptions are Quit, Use, etc.) need to be terminated by semicolon(;) like in C/C++/Java.

3. Some simple commands to try: (Carefully note the output...just kidding...)

SELECT VERSION(), CURRENT_DATE();
SELECT SIN(PI()/4), (4+1)*5;
SELECT USER(); SELECT NOW();

Some notes:
a.Keywords like select, etc. and built-in functions like version() are not case-sensitive i.e. even Select Version(), cuRRent_daTe(); will work but stick to one convention:)

b.Commands can span over more than one lines but termination by semicolon is important.

About Databases:
1. SHOW DATABASES; will show the list of currently available databases on the server that you have priveleges to.

Suppose you have 3 databases viz. epl, ipl and and apl (:P), then you can use the USE epl command to access, modify, etc. the epl database. As noted earlier (do you remember?), the USE command doesn't need semicolon at the end although putting one won't harm anyone. Also, it has to be written in a single line i.e. you cannot make it span over multiple lines.

2. GRANT ALL ON db_name.* TO 'user_name'@'host_name'; will grant all the priveleges for database named db_name to user_name on host_name. This command has to be executed on the administrator's machine.

3. CREATE DATABASE newDb; will create a new database newDb (this is VERY case-sensitive) but it won't select it for further use. So use USE newDb for selecting it. Alternatively, you can use  mysql -h host -u user -p newDb to directly select the database.


Phew... It takes more time to blog that I had thought...:P
Enough for today. Tomorrow, hopefully, I will read and write all about tables -- how to create them, modify them, play with them, etc.

No comments:

Post a Comment