Sem 3‎ > ‎DBMS (SQL) LAB‎ > ‎

MySQL: 1 Starting Off w/ Database

posted Aug 6, 2011, 11:00 PM by Neil Mathew   [ updated Aug 7, 2011, 4:22 AM ]

It is kinda different from Oracle's PL/SQL.

First of all, when you start the MySQL 5.5 Command Line Client and enter the password, this shows:

Enter password: **********
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.5.15 MySQL Community Server (GPL)

Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> 

The installation took a while. Basically, for future references, install in typical and at the end, Make sure the MySQL Instance Manager or smt like that installs properly. That was where everything went wrong. 

Now, Syntax is similar. However, there is a difference in datatypes and how to begin.

First of all, a DATABASE must be created. Then we must USE that database. And then create tables, etc.
There are two other functions, DROP & SHOW Databases.


mysql> create database TESTER;    <-- CREATE DATABASE
Query OK, 1 row affected (0.01 sec)

mysql> USE TESTER;                <-- USE DATABASE
Database changed

mysql> create table num1
    -> ( NAME varchar(20),
    -> ROLL integer
    -> );

Query OK, 0 rows affected (0.08 sec)

mysql> desc num1;
+-------+-------------+------+-----+---------+-------+
| Field | Type        | Null | Key | Default | Extra |
+-------+-------------+------+-----+---------+-------+
| NAME  | varchar(20) | YES  |     | NULL    |       |
| ROLL  | int(11)     | YES  |     | NULL    |       |
+-------+-------------+------+-----+---------+-------+
2 rows in set (0.00 sec)

mysql> show databases;           <-- SHOW DATABASES
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| test               |
| tester             |
+--------------------+
5 rows in set (0.00 sec)

mysql> drop database test;       <-- DROP DATABASE
Query OK, 0 rows affected (0.01 sec)

mysql> drop database tester;
Query OK, 1 row affected (0.05 sec)

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
+--------------------+
3 rows in set (0.00 sec)






Comments