Redhat Enterprise Linux (RHEL) install and configure MySQL database

by Vivek Gite · 22 comments

Q. How do I install MySQL database server under Redhat Enterprise Linux 5?

A. You have two choices:

a) Install MySQL package using RHN

b) Install MySQL rpm from CD/DVD

Red hat Enterprise Install Mysql Database server

The best way to install mysql package is to use RHN (Red Hat Network):

Redhat Enterprise Linux - RHEL 5 MySQL installation

Type the following command as root user:
# yum install mysql-server mysql
Note above yum command works with Fedora core and Cent OS Linux.

Redhat Enterprise Linux - RHEL 4/3 MySQL installation

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

Start MySQL Service

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

Setup mysql root password

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

Test mysql connectivity

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

See also

  • See all mysql related FAQ and tips

Featured Articles:

Want to read Linux tips and tricks, but don't have time to check our blog everyday? Subscribe to our daily email newsletter to make sure you don't miss a single tip/tricks. Subscribe to our weekly newsletter here!

{ 22 comments… read them below or add one }

1 prof.swati vishnu 11.17.07 at 8:55 am

how to install mysql on Redhat Enterprise Linux 5?

2 dot22 07.22.08 at 1:23 pm

MySQL installation

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

3 vivek 07.22.08 at 7:47 pm

@dot22,

Thanks for the heads up.

4 phan tom 08.24.08 at 6:16 am
5 Andrew 11.05.08 at 11:19 am

Create ~/.my.cnf with this content:

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

6 Matt 12.01.08 at 9:39 pm

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

7 chandrashekar 04.01.09 at 12:18 pm

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

8 MONY 04.28.09 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

9 anuj 05.01.09 at 9:54 am

after installation what shoul we do to configure my sql

10 khalifah 05.27.09 at 4:13 am

hello there?

where can i download themes for ubuntu?

anyone please help me

11 selnikraj 09.02.09 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

12 Laxman 09.02.09 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]

13 Laxman 09.02.09 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!

14 kakembo 11.20.09 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.

15 Phoenix 12.30.09 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.

16 Vivek Gite 12.30.09 at 6:25 am

Use sudo to start mysql.

17 Phoenix 12.30.09 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.

18 Vivek Gite 12.30.09 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

19 Phoenix 12.30.09 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.

20 Phoenix 12.30.09 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!

21 Vivek Gite 12.31.09 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.

22 manjunath 03.04.10 at 8:58 am

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

Leave a Comment

You can use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Previous FAQ:

Next FAQ:

nixCraft FAQ PDF Collection Now Available To All