Thursday, November 26, 2009

MySql Installation on Linux Guide

Download the required packages.

http://mirror.cogentco.com/pub/mysql/MySQL-5.2/

Installing MySql :-

# rpm -ivh MySQL-devel-5.2.0-0.glibc23.i386.rpm

# rpm -ivh MySQL-client-5.2.0-0.glibc23.i386.rpm

# rpm -ivh MySQL-server-5.2.0-0.glibc23.i386.rpm

# rpm -ivh MySQL-shared-5.2.3-0.glibc23.i386.rpmc23

# /etc/init.d/mysql start

Starting MySQL [OK]

Note:- If you get any error or fail to start mysql.

# /etc/init.d/mysql start

Starting MySQL [Failed]

Ø Then Check the following things.

# sestatus

must be disabled

# vim /selinux/config

SELINUX=disabled

# /etc/init.d/iptables stop

#ps -ef | grep mysql
#kill -9 (pid of mysql process)

Now Start Mysql :

#/etc/init.d/mysql start

Starting MySQL [OK]

Copy the sample my.cnf file to /etc directory

# cp /usr/share/mysql/my-medium.cnf /etc/my.cnf

Set Mysql root user password:

# mysqladmin -u root password mypassword

Login to Mysql Database server

# mysql –u root –pmypassword

mysql>

Once MySQL client is running, you should get the mysql> prompt. Type the following at this prompt:

mysql>show databases;

You will now get a list of databases like:

+----------------+
| Database       |
+----------------+
| mysql          |
| test           |
+----------------+
2 rows in set (0.00 sec)

Let's create a database!

mysql> create database databasename;

Check databases:

mysql>show databases;

+-------------+
| Database    |
+-------------+
|databasename |  
| mysql       |
| test        |
+-------------+

Connecting to database:

mysql>use databasename;

Checking Tables:

mysql>show tables;;

Reading Tables:

mysql>describe tablename;

Show All data in Table:

mysql> SELECT * FROM tablename;

You will get the output something like:-

+-------------+---------+------+-----+---------+-------+
| Field       | Type    | Null | Key | Default | Extra |
+-------------+---------+------+-----+---------+-------+
| abc         | text    |      |     |         |       |
| ghi        | text    |      |     |         |       |
+-------------+---------+------+-----+---------+-------+
2 rows in set (0.00 sec)

Deleting a database:

mysql>drop database databasename;

Deleting a table:

mysql>use databasename;

mysql>drop table tablename;

Creating Mysql User and setting permissions:

 
mysql> create user 'username'@'localhost' IDENTIFIED BY 'password';
mysql> grant all on *.* TO 'username'@'localhost' IDENTIFIED BY 'password';

mysql> flush privileges;

Backup of Mysql Database:-

# mysqldump –u root –pmypassword databasename > databasename.sql

Restore Mysql database:

# mysql –u root –pmypassword databasename < style="">

Backup of single table in Mysql :-

# mysqldump –u root –pmypassword databasename tablename > tablename.sql

Restore of single table in Mysql :-

# mysql –u root –pmypassword databasename tablename < style="">

No comments:

Post a Comment

How to Change Mysql Data Directory

Here I am going to move my default mysql data directory (/var/lib/mysql on RHEL5) to a new directory /mysqldata. First, we mu...