Pages - পৃষ্ঠাসমূহ

Mysql - Learn mysql easily with command

In database system mysql is popular one. It is easy to learn. One thing remind for database, maintainence and security is more difficult. Here is a simple tutorial with mysql commands. How to start first. This tutorial begins post installation of mysql. I use mysql in command prompt. I also use mysql from easyphp software. But you can do it your mysql software.
First install your mysql software. Now tell me what is your Harddisk location of your mysql installation.My mysql mysql installation folder is D:\EasyPHP5.2.10\mysql\

Click Start - All Programs - Acessories - Command Prompt.
After starting your command prompt you see like this
Microsoft Windows XP [Version 5.1.2600]
(C) Copyright 1985-2001 Microsoft Corp.
F:\Documents and Settings\Administrator>

(click on the command you will see the output)
F:\Documents and Settings\Administrator>cd D:\EasyPHP5.2.10\mysql\bin

F:\>

F:\>d:

D:\EasyPHP5.2.10\mysql\bin>

D:\EasyPHP5.2.10\mysql\bin>mysql -u root -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 10 Server version: 5.1.37-community-log MySQL Community Server (GPL) Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql> create database if not exists jahid;

Query OK, 1 row affected (0.00 sec)

mysql> show databases;

+--------------------+ | Database | +--------------------+ | information_schema | | jahid | | mysql | | phpmyadmin | | tanin | +--------------------+ 5 rows in set (0.00 sec)

mysql> use jahid;

Database changed

mysql> show tables;

Empty set (0.00 sec)

mysql> Create table registration( -> username varchar(20) not null, -> password varchar(20) not null, -> email varchar(30) not null, -> city varchar(20), -> date timestamp not null default current_timestamp on update current_timestamp, -> Primary key(username) -> )engine=myisam default charset latin1;

Query OK, 0 rows affected (0.06 sec)

mysql> show tables;

+-----------------+ | Tables_in_jahid | +-----------------+ | registration | +-----------------+ 1 row in set (0.00 sec)

mysql> describe registration;

+----------+-------------+------+-----+-------------------+-----------------------------+ | Field | Type | Null | Key | Default | Extra | +----------+-------------+------+-----+-------------------+-----------------------------+ | username | varchar(20) | NO | PRI | NULL | | | password | varchar(20) | NO | | NULL | | | email | varchar(30) | NO | | NULL | | | city | varchar(20) | YES | | NULL | | | date | timestamp | NO | | CURRENT_TIMESTAMP | on update CURRENT_TIMESTAMP | +----------+-------------+------+-----+-------------------+-----------------------------+ 5 rows in set (0.00 sec)

mysql> create table profile( -> name varchar(20), -> birth_date date, -> photo varchar(100), -> address varchar(100), -> interest varchar(100), -> phone_number varchar(100), -> foreign key (name) references registration(username) -> )engine=myisam default charset latin1;

Query OK, 0 rows affected (0.05 sec)

mysql> create table category( -> item varchar(100), -> Id int(100), -> Primary key(item) -> -> )engine=myisam default charset latin1;

Query OK, 0 rows affected (0.03 sec)

mysql> create table illust( -> illust_category varchar(100), -> title_name varchar(160), -> username varchar(100), -> submit_date timestamp not null default current_timestamp, -> category_name varchar(100), -> foreign key(category_name) references category(item) -> ) engine=myisam default charset latin1;

Query OK, 0 rows affected (0.05 sec)

mysql> create table autocad( -> autocad_category varchar(100), -> title_name varchar(160), -> username varchar(100), -> submit_date timestamp not null default current_timestamp, -> category_name varchar(100), -> foreign key(category_name) references category(item) -> ) engine=myisam default charset latin1 -> ;

Query OK, 0 rows affected (0.02 sec)

mysql> show tables;

+-----------------+ | Tables_in_jahid | +-----------------+ | autocad | | category | | illust | | profile | | registration | +-----------------+ 5 rows in set (0.00 sec)

mysql> describe autocad;

+------------------+--------------+------+-----+-------------------+-------+ | Field | Type | Null | Key | Default | Extra | +------------------+--------------+------+-----+-------------------+-------+ | autocad_category | varchar(100) | YES | | NULL | | | title_name | varchar(160) | YES | | NULL | | | username | varchar(100) | YES | | NULL | | | submit_date | timestamp | NO | | CURRENT_TIMESTAMP | | | category_name | varchar(100) | YES | MUL | NULL | | +------------------+--------------+------+-----+-------------------+-------+ 5 rows in set (0.00 sec)

mysql> describe category;

+-------+--------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +-------+--------------+------+-----+---------+-------+ | item | varchar(100) | NO | PRI | | | | Id | int(100) | YES | | NULL | | +-------+--------------+------+-----+---------+-------+ 2 rows in set (0.00 sec)

mysql> describe profile;

+--------------+--------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +--------------+--------------+------+-----+---------+-------+ | name | varchar(20) | YES | MUL | NULL | | | birth_date | date | YES | | NULL | | | photo | varchar(100) | YES | | NULL | | | address | varchar(100) | YES | | NULL | | | interest | varchar(100) | YES | | NULL | | | phone_number | varchar(100) | YES | | NULL | | +--------------+--------------+------+-----+---------+-------+ 6 rows in set (0.00 sec)

mysql> describe illust;

+-----------------+--------------+------+-----+-------------------+-------+ | Field | Type | Null | Key | Default | Extra | +-----------------+--------------+------+-----+-------------------+-------+ | illust_category | varchar(100) | YES | | NULL | | | title_name | varchar(160) | YES | | NULL | | | username | varchar(100) | YES | | NULL | | | submit_date | timestamp | NO | | CURRENT_TIMESTAMP | | | category_name | varchar(100) | YES | MUL | NULL | | +-----------------+--------------+------+-----+-------------------+-------+ 5 rows in set (0.01 sec)

mysql> describe registration;

+----------+-------------+------+-----+-------------------+-----------------------------+ | Field | Type | Null | Key | Default | Extra | +----------+-------------+------+-----+-------------------+-----------------------------+ | username | varchar(20) | NO | PRI | NULL | | | password | varchar(20) | NO | | NULL | | | email | varchar(30) | NO | | NULL | | | city | varchar(20) | YES | | NULL | | | date | timestamp | NO | | CURRENT_TIMESTAMP | on update CURRENT_TIMESTAMP | +----------+-------------+------+-----+-------------------+-----------------------------+ 5 rows in set (0.02 sec)

mysql> INSERT INTO jahid.registration (username,password,email,city) VALUES -> ('taslim','taslim','mdtaslim','dhaka'), -> ('tanin','tanin','mdtanin','dhaka'), -> ('alam','alam','mdalam','dhaka'), -> ('sharif','sharif','mdsharif','dhaka'), -> ('kabir','kabir','mdkabir','jessore'), -> ('javed','javed','mdjaved','noa-khali');

Query OK, 6 rows affected (0.00 sec) Records: 6 Duplicates: 0 Warnings: 0

mysql> INSERT INTO jahid.profile (name,birth_date,photo,address,interest,phone_number) VALUES -> ('taslim','1982-11-11', 'taslim.jpg', '180/a paikpara','I am not the boss', '123456'), -> ('tanin','1977-11-12', 'tanin.jpg', '180/a paik para', 'go ahead', '598158'), -> ('alam','1985-06-07', 'alam.jpg', '19/d east paik para', 'sobay jane', '190200'), -> ('sharif','1989-06-09', 'sharif.jpg', '180/a paik para' ,'serif on facebook', '016999'), -> ('kabir','1984-12-10', 'kabir.jpg', '90/d paik para', 'bhai balo achen', '017996'), -> ('javed','1991-11-10', 'javed.jpg', '19/d darus salam','bhai joto tuko janar dorkar', '500601');

Query OK, 6 rows affected (0.00 sec) Records: 6 Duplicates: 0 Warnings: 0

mysql> INSERT INTO jahid.category (item,Id) VALUES -> ('illust','1'), -> ('autocad','2'), -> ('3d max','3'), -> ('maya','4');

Query OK, 4 rows affected (0.00 sec) Records: 4 Duplicates: 0 Warnings: 0

mysql> INSERT INTO jahid.illust (illust_category,title_name,username,submit_date,category_name) VALUES -> ('illust','pen tool','taslim','2010-11-19','tool'), -> ('illust','brush tool','tanin','2010-11-20','tool'), -> ('illust','line tool','kabir','2010-11-22','tool'), -> ('illust','rectangular tool', 'alam' , '2010-12-12','tool'), -> ('illust','layer','javed','2010-12-13','layer'), -> ('illust','masking','taslim','2010-12-24','layer');

Query OK, 6 rows affected (0.00 sec) Records: 6 Duplicates: 0 Warnings: 0

mysql> INSERT INTO jahid.autocad (autocad_category,title_name,username,submit_date,category_name) VALUES -> ('autocad','measurement of units','taslim','2010-09-12','tutorial'), -> ('autocad','rectangular and line tool','taslim','2010-09-13','tool'), -> ('autocad','toolbox','alam','2010-10-06','tool'), -> ('autocad','create a 3d car','sharif','2010-12-22','tutorial'), -> ('autocad','create the actual layout','jahid','2010-12-29',' tutorial '), -> ('autocad','the tips and tricks of autocad','javed','2010-12-30','tips and tricks');

Query OK, 6 rows affected (0.00 sec) Records: 6 Duplicates: 0 Warnings: 0

mysql> select * from registration;

+----------+----------+----------+-----------+---------------------+ | username | password | email | city | date | +----------+----------+----------+-----------+---------------------+ | taslim | taslim | mdtaslim | dhaka | 2011-02-19 16:33:37 | | tanin | tanin | mdtanin | dhaka | 2011-02-19 16:33:37 | | alam | alam | mdalam | dhaka | 2011-02-19 16:33:37 | | sharif | sharif | mdsharif | dhaka | 2011-02-19 16:33:37 | | kabir | kabir | mdkabir | jessore | 2011-02-19 16:33:37 | | javed | javed | mdjaved | noa-khali | 2011-02-19 16:33:37 | +----------+----------+----------+-----------+---------------------+ 6 rows in set (0.00 sec)

mysql> select * from profile;

+--------+------------+------------+---------------------+-----------------------------+--------------+ | name | birth_date | photo | address | interest | phone_number | +--------+------------+------------+---------------------+-----------------------------+--------------+ | taslim | 1982-11-11 | taslim.jpg | 180/a paikpara | I am not the boss | 123456 | | tanin | 1977-11-12 | tanin.jpg | 180/a paik para | go ahead | 598158 | | alam | 1985-06-07 | alam.jpg | 19/d east paik para | sobay jane | 190200 | | sharif | 1989-06-09 | sharif.jpg | 180/a paik para | serif on facebook | 016999 | | kabir | 1984-12-10 | kabir.jpg | 90/d paik para | bhai balo achen | 017996 | | javed | 1991-11-10 | javed.jpg | 19/d darus salam | bhai joto tuko janar dorkar | 500601 | +--------+------------+------------+---------------------+-----------------------------+--------------+ 6 rows in set (0.00 sec)

mysql> select * from category;

+---------+------+ | item | Id | +---------+------+ | illust | 1 | | autocad | 2 | | 3d max | 3 | | maya | 4 | +---------+------+ 4 rows in set (0.00 sec)

mysql> select * from illust;

+-----------------+------------------+----------+---------------------+---------------+ | illust_category | title_name | username | submit_date | category_name | +-----------------+------------------+----------+---------------------+---------------+ | illust | pen tool | taslim | 2010-11-19 00:00:00 | tool | | illust | brush tool | tanin | 2010-11-20 00:00:00 | tool | | illust | line tool | kabir | 2010-11-22 00:00:00 | tool | | illust | rectangular tool | alam | 2010-12-12 00:00:00 | tool | | illust | layer | javed | 2010-12-13 00:00:00 | layer | | illust | masking | taslim | 2010-12-24 00:00:00 | layer | +-----------------+------------------+----------+---------------------+---------------+ 6 rows in set (0.00 sec)

mysql> select * from autocad;

+-----------------+------------------+----------+---------------------+---------------+ | illust_category | title_name | username | submit_date | category_name | +-----------------+------------------+----------+---------------------+---------------+ | illust | pen tool | taslim | 2010-11-19 00:00:00 | tool | | illust | brush tool | tanin | 2010-11-20 00:00:00 | tool | | illust | line tool | kabir | 2010-11-22 00:00:00 | tool | | illust | rectangular tool | alam | 2010-12-12 00:00:00 | tool | | illust | layer | javed | 2010-12-13 00:00:00 | layer | | illust | masking | taslim | 2010-12-24 00:00:00 | layer | +-----------------+------------------+----------+---------------------+---------------+ 6 rows in set (0.00 sec)

No comments:

Post a Comment