Redhat Enterprise Linux (RHEL) Install and Configure MySQL Database Server

by on March 20, 2007 · 42 comments· LAST UPDATED June 22, 2012

in , ,

How do I install the MySQL database server under Redhat Enterprise Linux 4 / 5 / 6?

You can install mysql using any one of the following medium.

a) Install MySQL package using RHN or CentOS repo.

b) Install MySQL rpms from CD/DVD media.

Red Hat Enterprise Linux install Mysql database server

Type the following command to install mysql server using the RHN or CentOS repo:

Redhat Enterprise Linux - RHEL 5 / 6 MySQL installation

Type the following command as root user:
# yum install mysql-server mysql

Redhat Enterprise Linux - RHEL 4/3 MySQL installation

Type the following command as root user:
# up2date mysql-server mysql

Start MySQL Service

To start the mysql server type the following command:
# chkconfig mysqld on
# /etc/init.d/mysqld start

Setup the mysql root password

Type the following command to setup a password for root user:
# mysqladmin -u root password NEWPASSWORD

Test the mysql connectivity

Type the following command to connect to MySQL server:
$ mysql -u root -p

Configure the mysql server

Edit /etc/my.cnf, enter (please note that following are sample values, you need to adjust them as per your requirements):
# vi /etc/my.cnf
You can configure mysql query cache as follows (add in [mysqld] section) to speed up mysql:

 
query_cache_type               = 1
query_cache_limit              = 1M
query_cache_size               = 32M
 

You can setup MyISAM buffer size and recover options:

 
# For MyISAM #
key_buffer_size                = 24M
myisam_recover                 = FORCE,BACKUP
 

Log slow queries for troubleshooting as follows:

 
# LOGGING #
log_queries_not_using_indexes  = 1
slow_query_log                 = 1
slow_query_log_file            = /var/lib/mysql/mysqld-slow-query.log
 

Set caches and other limits as follows:

 
tmp_table_size                 = 32M
max_heap_table_size            = 32M
max_connections                = 500
thread_cache_size              = 50
open_files_limit               = 65535
table_definition_cache         = 4096
table_open_cache               = 512
 

Save and close the file. You can reload or restart the changes as follows:
# /sbin/service mysqld restart
OR
# /sbin/service mysqld reload

See also

TwitterFacebookGoogle+PDF versionFound an error/typo on this page? Help us!

{ 42 comments… read them below or add one }

1 prof.swati vishnu November 17, 2007 at 8:55 am

how to install mysql on Redhat Enterprise Linux 5?

Reply

2 piyush March 27, 2011 at 3:50 pm

create a yum in rhel 5 and then install the sql package using the following command

yum install mysql-*

Reply

3 dot22 July 22, 2008 at 1:23 pm

MySQL installation

Type the following command as root user:
# yum *install * mysql-server mysql

Reply

4 nixCraft July 22, 2008 at 7:47 pm

@dot22,

Thanks for the heads up.

Reply

5 phan tom August 24, 2008 at 6:16 am
6 Andrew November 5, 2008 at 11:19 am

Create ~/.my.cnf with this content:

[client]
user=”root”
pass=”NEWPASSWORD”

Reply

7 Matt December 1, 2008 at 9:39 pm

How to Install MySQL rpm from CD/DVD ?
i can’t use RHN

Reply

8 Masthan October 13, 2010 at 5:10 am

put ur Dvd/cd
login into server
#mount /dev/dvd /mnt
#cd /mnt
mnt#ls
show the details login into server
mnt#cd Server
Server#rpm -ivh mysql
#

Reply

9 chandrashekar April 1, 2009 at 12:18 pm

thank u very much for the information its very useful for my application.

Reply

10 MONY April 28, 2009 at 10:29 am

I want install MySQL from DVD but I can’t install MySQL .
I use command “yum install mysql -server mysql” . It is show message

Loading “securityW plugin
Loading “rhnplugin” plugin
This system is not registered with RHN.
RHN support will be disabled.
Setting up Install Process
Parsing package install arguments
No package mysql -server available.
No package mysql available.
Nothing to do

What command is to use intall MySQL ? Please tell me .
Thank you

Reply

11 rajesh April 11, 2011 at 6:56 am

1.Create YUM locally and than execute yum install mysql* it won’t need any internet connection. And will solve all dependency.
If will go for Manuall RPM installation than it would be a hectic task to solve dependency.

Reply

12 el November 9, 2012 at 4:58 pm

Hi Mony,

you can disable the gpgchek in /etc/yum.repos.d/yourrepo.
after that you run again command
yum repolist. or you can read my blog in section create local repository.
Maybe it could help you.
Thanks.

Reply

13 anuj May 1, 2009 at 9:54 am

after installation what shoul we do to configure my sql

Reply

14 khalifah May 27, 2009 at 4:13 am

hello there?

where can i download themes for ubuntu?

anyone please help me

Reply

15 selnikraj September 2, 2009 at 4:41 am

when am starting mysql

[nik@localhost ~]$ mysql -u root -p
Enter password:
ERROR 2002 (HY000): Can’t connect to local MySQL server through socket ‘/var/lib/mysql/mysql.sock’ (2)

its giving like this

and also

[nik@localhost ~]$ mysql
ERROR 2002 (HY000): Can’t connect to local MySQL server through socket ‘/var/lib/mysql/mysql.sock’ (2)

what will the problem and what will be ans to recover it please help m,e

Reply

16 Laxman September 2, 2009 at 3:56 pm

When you don’t remember root password and enter a wrong password, you will get the following MySQL error message.
# mysql -u root mysql
ERROR 1045 (28000): Access denied for user ‘root’@’localhost’ (using password: NO)
1. Stop MySQL Server
As a first step, stop the mysql server using one of the following method.
# service mysql stop

(or)

# /etc/rc.d/init.d/mysql stop
2. Add –skip-grant-tables to mysqld_safe Startup Command
Open the mysql startup script and add -skip-grant-tables as shown below.
# vi /etc/rc.d/init.d/mysql

Old Line: $bindir/mysqld_safe –datadir=$datadir –pid-file=$server_pid_file $other_args >/dev/null 2>&1 &

New Line: $bindir/mysqld_safe –skip-grant-tables –datadir=$datadir –pid-file=$server_pid_file $other_args >/dev/null 2>&1 &
3. Start MySQL Server With –skip-grant-tables
Start the mysql server with skip-grant-tables option, which will allow anybody to login to mysql without entering a password.
# service mysql start
Starting MySQL. [ OK ]
[Note: This is using the updated /etc/rc.d/init.d/mysql script]
4. Login Using MySQL Root User Without Entering Password
Since you’ve skipped the grant table, this time when you try to login to mysql, it will not ask for password.
# mysql -u root mysql
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.1.25-rc-community MySQL Community Server (GPL)

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

mysql>

[Note: MySQL did not ask for any password]

Reply

17 Laxman September 2, 2009 at 3:58 pm

Fix: Can’t connect to local MySQL server through socket ‘/var/lib/mysql/mysql.sock’

ERROR 2002 (HY000): Can’t connect to local MySQL server through socket ‘/var/lib/mysql/mysql.sock’

if you are new to installing mysql server you might probably face this error quite often if you type mysql in the shell prompt.

> mysql
ERROR 2002 (HY000): Can’t connect to local MySQL server through socket ‘/var/lib/mysql/mysql.sock’

To fix:

First start the mysql daemon, then type mysql

> /etc/init.d/mysqld start
> mysql

Bingo! It worked for me!

To update mysql root password

mysql> USE mysql;
mysql> UPDATE user SET Password=PASSWORD(‘new-password’) WHERE user=’root';
mysql> FLUSH PRIVILEGES;

To add a new user to mysql

1. First login as root then create a database ‘demo’

> mysql -u root -p
Enter password:
mysql> create database demo;

After that create a new user named ‘guest’ with password ‘guest’ with all previleges assigned to demo database;

mysql> GRANT ALL PRIVILEGES ON mytest.* TO ‘guest’@’localhost’ IDENTIFIED BY ‘guest’ WITH GRANT OPTION;

Then exit mysql and connect through username guest;
That should work!

Reply

18 kakembo November 20, 2009 at 4:56 pm

i try to use yum install and it gives this message that says “Existing lock /var/run/yum.pid: another copy is running as pid 3406.
Another app is currently holding the yum lock; waiting for it to exit…”
what can i do to make thing right.
if any help please help me.

Reply

19 manjunath August 30, 2012 at 2:56 pm

open the file with vi /var/run/yum.pid and then remove pid 3406 which is inside that.

Reply

20 Phoenix December 30, 2009 at 4:35 am

I used yum install mysql-server mysql and it installed great. Then I tried to start the server with this: /etc/init.d/mysqld start andd it said mysqld doesn’t exist. I should mention that I’m installing this on a work machine, running REHL5 and I don’t have root permissions. I do have sudo rights. I asked whereis MySQL and it returned 4 locations. How do I start the server or configure it so I can start it? Thanks for your help.

Reply

21 nixCraft December 30, 2009 at 6:25 am

Use sudo to start mysql.

Reply

22 Phoenix December 30, 2009 at 2:05 pm

I’ve actually tried every sudo start mysql command that I’ve found and not been successful. Its funny because it was no problem from my windows install but this red hat enterprise install isn’t making sense.

Reply

23 nixCraft December 30, 2009 at 2:10 pm

Correct syntax to start / stop / restart with sudo:
sudo /etc/init.d/mysqld start
sudo /etc/init.d/mysqld status
sudo /etc/init.d/mysqld restart
sudo /etc/init.d/mysqld stop

OR
sudo /sbin/service mysqld start
What is the output of the following command?
netstat -tulnp | grep mysql

Reply

24 Phoenix December 30, 2009 at 4:17 pm

I did sudo netstat -tulnp | grep mysql and it went back to the prompt after requesting password. Without sudo, it said “(No info could be read for “-p”: getuid()=45717 but you should be root.)

sudo /sbin/service mysqld start
returned: mysqld: unrecongnized service

sudo /etc/init.d/mysqld start
returned: sudo: /etc/init.d/mysqld: command not found
sudo /etc/init.d/mysqld status
returned: sudo: /etc/init.d/mysqld: command not found
sudo /etc/init.d/mysqld restart
returned: sudo: /etc/init.d/mysqld: command not found
sudo /etc/init.d/mysqld stop
returned: sudo: /etc/init.d/mysqld: command not found

This is my first foray into RHEL, I’ve used Ubuntu previously (about 2 years ago), and recently been running mysql/apache with XAMPP sucessfully, and that’s not a production platform (as you know). But I have a project that I would like to run on a Linux box (production), for obvious reasons (well, obvious to me). I appreciate your help with this.

Reply

25 Phoenix December 30, 2009 at 7:39 pm

So, update – I found that I needed to install something else: mysql-devel. Now that that is there, I ran sudo /usr/bin/mysqld_safe & and that was successful. However, when I run sudo /etc/init.d/mysqld status it returns this:

mysqld dead but subsys locked

any suggestions?

Thanks!

Reply

26 nixCraft December 31, 2009 at 4:55 am

/usr/bin/mysqld_safe &

Another way to start mysql server. I suggest you reboot your box and type the same command again. It should clean up lock files. It is possible to get rid of problem online but you need to go thorugh kill, rm and other commands.

Reply

27 manjunath March 4, 2010 at 8:58 am

I could not get the required information about installation of MYSQL on redhat enterprise 5

Reply

28 Masthan October 13, 2010 at 5:14 am

How to config LDAP in redhat linux

Reply

29 shirish November 25, 2010 at 11:55 am

I have installed mysql on rhel 5.4
# yum install *sql*
* start service & create root admin password

# /etc/init.d/mysqld restart
# chkconfig mysqld on
# sqladmin -u root password shirish

am new in mysql installation.
I want to build master slave please any one help me o this….

nice day!!!

Thanks
Shirish Shukla

Reply

30 x-Tray March 30, 2011 at 8:18 am

Thank U Very Much !
I sovled my problem with your ways !
Thanks Again !

Reply

31 Orit April 5, 2011 at 8:36 am

Thanks! It worked for me :-)

Reply

32 john May 29, 2011 at 7:04 pm

hai
there i got a problem in installing orcale dba in rhel 5.4
plz give the solution
Preparing to launch Oracle Universal Installer from /tmp/OraInstall2011-05-30_03-28-30AM. Please wait …
Error in writing to directory /tmp/OraInstall2011-05-30_03-28-30AM. Please ensure that this directory is writable and has atleast 60 MB of disk space. Installation cannot continue.

Reply

33 john May 29, 2011 at 7:13 pm

hai i got error when installing oracle dba on rhel 5.4 any other steps…

—————————————————————>
[root@rhel5 database]# ./runInstaller
Starting Oracle Universal Installer…

Checking installer requirements…

Checking operating system version: must be redhat-3, SuSE-9, redhat-4, UnitedLinux-1.0, asianux-1 or asianux-2
Passed

All installer requirements met.

Preparing to launch Oracle Universal Installer from /tmp/OraInstall2011-05-30_03-28-30AM. Please wait …
Error in writing to directory /tmp/OraInstall2011-05-30_03-28-30AM. Please ensure that this directory is writable and has atleast 60 MB of disk space. Installation cannot continue.
: No such file or directory

Reply

34 Muthukumar June 20, 2011 at 4:12 pm

Hi,
when i entered this command
mysql -u root -p
Enter password:
ERROR 1045 (28000): Access denied for user ‘root’@’localhost’ (using password: YES)

i could not solve the issue, pls help me

Reply

35 Nandkumar February 6, 2012 at 4:22 pm

can i have complete installation and configuration of mysql server and connectivity between client (linux as well as windows) ?

Reply

36 Disha March 29, 2012 at 1:33 pm

1] which version for PHP,Apache and Mysql is better to install on red hat linux and fedora?

2] when i will save the setup for all the S/w on rhel of any folder then is it right that i can type the command on terminal for the installing?

reply me for this quesions.

Reply

37 Sharda Prasad August 27, 2012 at 2:46 pm

Hello Sir

i am new in the linux redhat 6.0. i install oracle 11g in my system but give lots of error
sir can give me step by step installation information

plz help me …

Thank you

Reply

38 Sylvain September 14, 2012 at 12:47 pm

Nice tuto, pretty clean and simple.

You did a good job!

Reply

39 arun October 20, 2012 at 9:47 am

good stuff

Reply

40 sam January 18, 2013 at 9:26 am

mysql is run but hi give me error on ‘@”localhost’
don’t create databases;

Reply

41 satish August 7, 2013 at 2:28 pm

how to install mysql in rhel6?? what packages i need to install and from where i can download it please help me out….if possible il cm online please give anyone mail id so that i can take there support..plzzz

Reply

42 Chaitanya March 18, 2014 at 7:20 am

Thanks It help for configuring Mysql on RedHat Linux Enterprise 6.5

Reply

Leave a Comment

Tagged as: , , , , , , , , , ,

Previous Faq:

Next Faq: