Thursday 12 April 2012

mysql installation and some basics

[root@station1 Desktop]# yum install -y mysql*
[root@station1 Desktop]# service mysqld start
[root@station1 Desktop]# mysqladmin -u root password password   ------> setting password for the root user
[root@station1 Desktop]# mysql -u root -ppassword               ------> login
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 15
Server version: 5.1.52 Source distribution

Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.
This software comes with ABSOLUTELY NO WARRANTY. This is free software,
and you are welcome to modify and redistribute it under the GPL v2 license

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

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| test               |
+--------------------+
4 rows in set (0.00 sec)
mysql> use mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> show tables;
+---------------------------+
| Tables_in_mysql           |
+---------------------------+
| columns_priv              |
| db                        |
| event                     |
| func                      |
| general_log               |
| help_category             |
| help_keyword              |
| help_relation             |
| help_topic                |
| host                      |
| ndb_binlog_index          |
| plugin                    |
| proc                      |
| procs_priv                |
| servers                   |
| slow_log                  |
| tables_priv               |
| time_zone                 |
| time_zone_leap_second     |
| time_zone_name            |
| time_zone_transition      |
| time_zone_transition_type |
| user                      |
+---------------------------+
23 rows in set (0.00 sec)
mysql> select * from user;
mysql> DELETE FROM mysql.user WHERE user = '';  ----> to delete anonymous users.
mysql> flush privileges;
mysql> show engines;
mysql> show processlist;
mysql> create database RanjithContacts;
Query OK, 1 row affected (0.00 sec)



mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| RanjithContacts    |
| mysql              |
| test               |
+--------------------+
5 rows in set (0.00 sec)
mysql> drop database RanjithContacts;  ---------->delete a database
Query OK, 0 rows affected (0.00 sec)

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| test               |
+--------------------+
4 rows in set (0.00 sec)
mysql> create database Ranjith;
mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| Ranjith            |
| mysql              |
| test               |
+--------------------+
4 rows in set (0.00 sec)
mysql> use Ranjith;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> create table contacts ( `first_name` char(20), `last_name` char(20), `mob_no` char(20), `email_id` char(30), PRIMARY KEY (`email_id`));
mysql> show tables;
+-------------------+
| Tables_in_Ranjith |
+-------------------+
| contacts          |
+-------------------+
1 row in set (0.00 sec)
mysql> describe contacts;
+------------+----------+------+-----+---------+-------+
| Field      | Type     | Null | Key | Default | Extra |
+------------+----------+------+-----+---------+-------+
| first_name | char(20) | YES  |     | NULL    |       |
| last_name  | char(20) | YES  |     | NULL    |       |
| mob_no     | char(20) | YES  |     | NULL    |       |
| email_id   | char(30) | NO   | PRI |         |       |
+------------+----------+------+-----+---------+-------+
4 rows in set (0.00 sec)
mysql> INSERT INTO contacts (first_name,last_name,mob_no,email_id) VALUES ('Ranjith','Pandurangan','+919995191323','ranoranji@gmail.com');
mysql> select * from contacts;
+------------+-------------+---------------+----------------------+
| first_name | last_name   | mob_no        | email_id             |
+------------+-------------+---------------+----------------------+
| Ranjith    | Pandurangan | +919995191323 | ranoranji@gmail.com  |
+------------+-------------+---------------+----------------------+
2 rows in set (0.00 sec)
mysql> INSERT INTO contacts (first_name,last_name,mob_no,email_id) VALUES ('Taj','Mohidheen','+918754992672','visitmetaj@gmail.com');
mysql> select * from contacts;
+------------+-------------+---------------+----------------------+
| first_name | last_name   | mob_no        | email_id             |
+------------+-------------+---------------+----------------------+
| Ranjith    | Pandurangan | +919995191323 | ranoranji@gmail.com  |
| Taj        | Mohidheen   | +918754992672 | visitmetaj@gmail.com |
+------------+-------------+---------------+----------------------+
2 rows in set (0.00 sec)
mysql> UPDATE contacts SET last_name='Jessi' WHERE first_name='Taj';
Query OK, 1 row affected (0.00 sec)
Rows matched: 1  Changed: 1  Warnings: 0

mysql> select * from contacts;
+------------+-------------+---------------+----------------------+
| first_name | last_name   | mob_no        | email_id             |
+------------+-------------+---------------+----------------------+
| Ranjith    | Pandurangan | +919995191323 | ranoranji@gmail.com  |
| Taj        | Jessi       | +918754992672 | visitmetaj@gmail.com |
+------------+-------------+---------------+----------------------+
2 rows in set (0.00 sec)
mysql> DELETE FROM contacts WHERE first_name = 'Taj';
Query OK, 1 row affected (0.00 sec)

mysql> select * from contacts;
+------------+-------------+---------------+---------------------+
| first_name | last_name   | mob_no        | email_id            |
+------------+-------------+---------------+---------------------+
| Ranjith    | Pandurangan | +919995191323 | ranoranji@gmail.com |
+------------+-------------+---------------+---------------------+
1 row in set (0.00 sec)
mysql>quit;





No comments:

Post a Comment