Wednesday, October 16, 2013

MySQL Basic Administration

Using Yum install mysql -

[root@joshi ~]# yum install mysql mysql-client mysql-server
Loaded plugins: fastestmirror
Determining fastest mirrors
CentOS                                                                                                                                                      | 1.1 kB     00:00    
Setting up Install Process
No package mysql-client available.
Resolving Dependencies
--> Running transaction check
---> Package mysql.i386 0:5.0.77-4.el5_4.2 set to be updated
--> Processing Dependency: perl(DBI) for package: mysql
---> Package mysql.x86_64 0:5.0.77-4.el5_4.2 set to be updated
---> Package mysql-server.x86_64 0:5.0.77-4.el5_4.2 set to be updated
--> Processing Dependency: perl-DBD-MySQL for package: mysql-server
--> Running transaction check
---> Package perl-DBD-MySQL.x86_64 0:3.0007-2.el5 set to be updated
---> Package perl-DBI.x86_64 0:1.52-2.el5 set to be updated
--> Finished Dependency Resolution

Dependencies Resolved

===================================================================================================================================================================================
 Package                                       Arch                                  Version                                           Repository                             Size
===================================================================================================================================================================================
Installing:
 mysql                                         i386                                  5.0.77-4.el5_4.2                                  CentOS                                4.8 M
 mysql                                         x86_64                                5.0.77-4.el5_4.2                                  CentOS                                4.8 M
 mysql-server                                  x86_64                                5.0.77-4.el5_4.2                                  CentOS                                9.8 M
Installing for dependencies:
 perl-DBD-MySQL                                x86_64                                3.0007-2.el5                                      CentOS                                148 k
 perl-DBI                                      x86_64                                1.52-2.el5                                        CentOS                                600 k

Transaction Summary
===================================================================================================================================================================================
Install       5 Package(s)
Upgrade       0 Package(s)

Total download size: 20 M
Is this ok [y/N]: y
Downloading Packages:
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Total                                                                                                                                              334 MB/s |  20 MB     00:00    
Running rpm_check_debug
Running Transaction Test
Finished Transaction Test
Transaction Test Succeeded
Running Transaction
  Installing     : perl-DBI                                                                                                                                                    1/5
  Installing     : mysql                                                                                                                                                       2/5
  Installing     : perl-DBD-MySQL                                                                                                                                              3/5
  Installing     : mysql                                                                                                                                                       4/5
  Installing     : mysql-server                                                                                                                                                5/5

Installed:
  mysql.i386 0:5.0.77-4.el5_4.2                          mysql.x86_64 0:5.0.77-4.el5_4.2                          mysql-server.x86_64 0:5.0.77-4.el5_4.2                        

Dependency Installed:
  perl-DBD-MySQL.x86_64 0:3.0007-2.el5                                                         perl-DBI.x86_64 0:1.52-2.el5                                                      

Complete!

Start MySQL database service as:

[root@joshi ~]# service mysqld start
Initializing MySQL database:  Installing MySQL system tables...
OK
Filling help tables...
OK

To start mysqld at boot time you have to copy
support-files/mysql.server to the right place for your system

PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !
To do so, start the server, then issue the following commands:
/usr/bin/mysqladmin -u root password 'new-password'
/usr/bin/mysqladmin -u root -h joshi.tenongroove.com password 'new-password'

Alternatively you can run:
/usr/bin/mysql_secure_installation

which will also give you the option of removing the test
databases and anonymous user created by default.  This is
strongly recommended for production servers.

See the manual for more instructions.

You can start the MySQL daemon with:
cd /usr ; /usr/bin/mysqld_safe &

You can test the MySQL daemon with mysql-test-run.pl
cd mysql-test ; perl mysql-test-run.pl

Please report any problems with the /usr/bin/mysqlbug script!

The latest information about MySQL is available on the web at
http://www.mysql.com
Support MySQL by buying support/licenses at http://shop.mysql.com
                                                           [  OK  ]
Starting MySQL:                                            [  OK  ]


Create password for mysql -

[root@joshi ~]# /usr/bin/mysqladmin -u root password root

Login mysql db using root user.

[root@joshi ~]# mysql -u root -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.0.77 Source distribution

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.


Create a new database uttrakhand

mysql>  create database uttrakhand
    -> ;
Query OK, 1 row affected (0.00 sec)

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| test               |
| uttrakhand         |
+--------------------+
4 rows in set (0.00 sec)

use database for doing task.

mysql> use uttrakhand;
Database changed

Create Table.

mysql> CREATE TABLE Delhi (
    ->      Emp_id Int(3),
    ->      first_name Varchar (19),
    ->      email Varchar(15) ) ;
Query OK, 0 rows affected (0.00 sec)

mysql> show tables;
+----------------------+
| Tables_in_uttrakhand |
+----------------------+
| Delhi                |
+----------------------+
1 row in set (0.00 sec)

mysql> show columns from Delhi;
+------------+-------------+------+-----+---------+-------+
| Field      | Type        | Null | Key | Default | Extra |
+------------+-------------+------+-----+---------+-------+
| Emp_id     | int(3)      | YES  |     | NULL    |       |
| first_name | varchar(19) | YES  |     | NULL    |       |
| email      | varchar(15) | YES  |     | NULL    |       |
+------------+-------------+------+-----+---------+-------+
3 rows in set (0.00 sec)

No comments:

Post a Comment