≡ Menu

How to Install MySQL Database Using Yum groupinstall on CentOS

In this article, let us review how to install MySQL on CentOS using yum. Instead of searching and installing mysql and related packages one-by-one, it is better to install MySQL using yum groups.

If you are interested in installing the full LAMP stack, refer to our earlier article on how to install/upgrade LAMP using yum.

1. Identify the Group name of MySQL Packages

yum grouplist displays all package groups that are available in the repository. As shown below, mysql package group is called “MySQL Database”.

# yum grouplist | grep -i mysql
   MySQL Database

2. What is bundled in the “MySQL Database” group?

yum groupinfo displays all the packages that are bundled in a group. This displays the mandatory, default and optional packages that are available in that particular group.

As shown below, “MySQL Database” group contains 1 mandatory package, 6 default packages, and 5 optional packages.

# yum groupinfo "MySQL Database"
Group: MySQL Database
 Description: This package group contains packages useful for use with MySQL.
 Mandatory Packages:
   mysql
 Default Packages:
   MySQL-python
   libdbi-dbd-mysql
   mysql-connector-odbc
   mysql-server
   perl-DBD-MySQL
   unixODBC
 Optional Packages:
   mod_auth_mysql
   mysql-bench
   mysql-devel
   php-mysql
   qt-MySQL

3. Install the “MySQL Database” group using yum groupinstall

yum groupinstall will install the “MySQL Database” group of packages as shown below.

# yum groupinstall "MySQL Database"

Resolving Dependencies
Dependencies Resolved

Transaction Summary
=========================
Install     12 Package(s)         
Update       0 Package(s)         
Remove       0 Package(s)         

Installed:
  MySQL-python.i386 0:1.2.1-1 libdbi-dbd-mysql.i386 0:0.8.1a-1.2.2  
  mysql.i386 0:5.0.77-4.el5_4.2  mysql-connector-odbc.i386 0:3.51.26r1127-1.el5
  mysql-server.i386 0:5.0.77-4.el5_4.2  perl-DBD-MySQL.i386 0:3.0007-2.el5 
  unixODBC.i386 0:2.2.11-7.1    

Dependency Installed:
  libdbi.i386 0:0.8.1-2.1 libdbi-drivers.i386 0:0.8.1a-1.2.2 
  libtool-ltdl.i386 0:1.5.22-7.el5_4 
  mx.i386 0:2.0.6-2.2.2 perl-DBI.i386 0:1.52-2.el5  

Complete!

Note: If you are having some issues during the installation, verify the full mysql install log to see what you are missing.

4. Verify MySQL Installation

Execute rpm -qa, to confirm that the mysql related packages are installed.

# rpm -qa | grep -i mysql
MySQL-python-1.2.1-1
mysql-5.0.77-4.el5_4.2
mysql-connector-odbc-3.51.26r1127-1.el5
mysql-server-5.0.77-4.el5_4.2
libdbi-dbd-mysql-0.8.1a-1.2.2
perl-DBD-MySQL-3.0007-2.el5

Check the /etc/passwd and /etc/group to make sure it has created a mysql username and group.

# grep mysql /etc/passwd
mysql:x:27:27:MySQL Server:/var/lib/mysql:/bin/bash

# grep mysql /etc/group
mysql:x:27:

5. MySQL Post installation – Execute mysql_install_db

mysql_install_db program will setup the necessary grant tables. The mysql_install_db program gets executed as part of the rpm installation. But, it doesn’t hurt to execute the mysql_install_db program again to make sure the grant tables are setup properly.

# /usr/bin/mysql_install_db --user=mysql
Installing MySQL system tables...OK
Filling help tables...OK
.....
The latest information about MySQL is available on the web at http://www.mysql.com

6. Start MySQL Server

# service mysqld status
mysqld is stopped

# service mysqld start
Starting MySQL:                                            [  OK  ]

7. Verify that the MySQL server is up and running.

# /usr/bin/mysqladmin version
/usr/bin/mysqladmin  Ver 8.41 Distrib 5.0.77, for redhat-linux-gnu on i686
Copyright (C) 2000-2006 MySQL AB
This software comes with ABSOLUTELY NO WARRANTY. This is free software,
and you are welcome to modify and redistribute it under the GPL license

Server version		5.0.77
Protocol version	10
Connection		Localhost via UNIX socket
UNIX socket		/var/lib/mysql/mysql.sock
Uptime:			39 sec

Threads: 1  Questions: 2  Slow queries: 0  Opens: 12  Flush tables: 1  
Open tables: 6  Queries per second avg: 0.051
# /usr/bin/mysqlshow
+--------------------+
|     Databases      |
+--------------------+
| information_schema |
| mysql              |
| test               |
+--------------------+

# /usr/bin/mysqlshow mysql
Database: mysql
+---------------------------+
|          Tables           |
+---------------------------+
| columns_priv              |
| db                        |
| func                      |
| help_category             |
| time_zone_transition      |
| time_zone_transition_type |
| user                      |
+---------------------------+

Stop and start the mysql server again to make sure they are no issues.

# service mysqld stop
Stopping MySQL:                                            [  OK  ]

# service mysqld start
Starting MySQL:                                            [  OK  ]

8. Change the MySQL root account password

Change the MySQL root account password to something secure.

# mysql -u root
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 5
Server version: 5.0.77 Source distribution

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

mysql> select host, user from mysql.user;
+-----------+------+
| host      | user |
+-----------+------+
| 127.0.0.1 | root | 
| localhost |      | 
| localhost | root | 
+-----------+------+
5 rows in set (0.00 sec)

mysql> set password for 'root'@'localhost' = PASSWORD('DoNotTell$AnyBody');
Query OK, 0 rows affected (0.00 sec)

mysql> set password for 'root'@'127.0.0.1' = PASSWORD('DoNotTell$AnyBody');
Query OK, 0 rows affected (0.00 sec)

Make sure you are able to login to MySQL using the new password as shown below.

# mysql -u root
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)

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

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

mysql>
Add your comment

If you enjoyed this article, you might also like..

  1. 50 Linux Sysadmin Tutorials
  2. 50 Most Frequently Used Linux Commands (With Examples)
  3. Top 25 Best Linux Performance Monitoring and Debugging Tools
  4. Mommy, I found it! – 15 Practical Linux Find Command Examples
  5. Linux 101 Hacks 2nd Edition eBook Linux 101 Hacks Book

Bash 101 Hacks Book Sed and Awk 101 Hacks Book Nagios Core 3 Book Vim 101 Hacks Book

Comments on this entry are closed.

  • Jose Vicente Mondejar April 29, 2010, 6:54 am

    Clean and easy. I may use it someday…

  • Ryan July 29, 2010, 4:23 am

    Thanks a lot for this. Nice easy to follow guide. Was up and running in minutes.

  • Bob September 14, 2010, 2:33 pm

    Exactly what I needed. Thanks!

    One more thing that people may find useful – once you have MySQL running you can run “/usr/bin/mysql_secure_installation” to button up security a bit before going into production.

  • barth November 4, 2010, 3:57 pm

    Nice , simple ,straight forward and accurate instructions…nice work.

  • Anand December 29, 2010, 3:57 am

    Good and easy to follow. I was setting up Mysql on centos. this tutorial made it very easy and in one go was able to install.

  • Andy January 18, 2011, 12:41 pm

    Thanks very much for producing this great guide – I’ve now got MySQL up and running.

  • manoj March 24, 2011, 12:10 am

    excellent tutoril

  • Vinoth Kumar Lakshmanan August 2, 2011, 10:40 am

    Fantastic 🙂

  • jon September 8, 2011, 2:57 am

    Excellent tutorial. Many thanks

  • Casey September 14, 2011, 11:16 pm

    Never have I seen it done so well, thanks!

  • revo November 8, 2011, 1:30 am

    Hi Ramesh anna,
    i love you 🙂
    you rescued me many a times 🙂
    and its one more time 🙂

  • Bernichiwa December 28, 2011, 8:18 am

    if mysql database does not work try teh following for group install

    MySql Database Server
    MySql Database Client

  • Thomas January 12, 2012, 1:18 pm

    You guys are awesome. Thank You!

  • mitsos February 2, 2012, 3:59 am

    Superb. Thanks a lot. Was up and running in minutes.

  • Sridhar July 16, 2012, 7:29 am

    Excellent narration. Rocking.. keep it up…

  • ty July 25, 2012, 3:31 am

    thanks alot for this post

  • norm July 29, 2012, 4:27 pm

    Great Tutorial up to the point where you set the point where you change the root password….
    mysql> set password for ‘root’@’localhost’ = PASSWORD(‘DoNotTell$AnyBody’);
    Query OK, 0 rows affected (0.00 sec)

    mysql> set password for ‘root’@’127.0.0.1’ = PASSWORD(‘DoNotTell$AnyBody’);
    Query OK, 0 rows affected (0.00 sec)

    What is the root password now?

    When I type # mysql -u root -p
    Enter password:
    I have know idea what it was set to?
    HELP!

  • norm July 29, 2012, 7:12 pm

    Well Figured out the problem(‘DoNotTell$AnyBody’) just figured out this was a dummy variable. Emphasis on “dummy” . Changed password. Now all set.

    Embarrassing.

  • Manzoorul Hassan December 28, 2012, 4:38 pm

    Excellent set of instructions. Now I just need to figure out how to update / upgrade to v5.5.9. The above instruction got v5.0.95 installed.

    – manzoor

  • sinapse January 25, 2013, 2:35 am

    Excellent, awesome, works great..

    Thanks so much!!

  • k September 26, 2013, 12:04 pm

    Excellent Article. Installation was a breeze after reading this article.
    Thanks a bunch.

  • Kiran December 14, 2013, 9:58 am

    Getting strucked below please help me unable to start mysql service after installation yum groupinstall “MySQL Database”
    while restarting getting below message.

    [root@localhost ~]# systemctl status mysqld.service
    mysqld.service – MySQL database server
    Loaded: loaded (/lib/systemd/system/mysqld.service; disabled)
    Active: failed since Sun, 15 Dec 2013 02:57:49 +0530; 17s ago
    Process: 4017 ExecStartPre=/usr/libexec/mysqld-prepare-db-dir %n (code=exited, status=254)
    Main PID: 3340 (code=exited, status=1/FAILURE)
    CGroup: name=systemd:/system/mysqld.service
    [root@localhost ~]#

  • YY January 7, 2014, 2:08 pm

    [root@CEL-550-x64-0-1-2 bin]# service mysqld status
    bash: service: command not found
    [root@CEL-550-x64-0-1-2 bin]# service mysqld start
    bash: service: command not found
    [root@CEL-550-x64-0-1-2 /]# /etc/init.d/mysqld status
    mysqld is stopped
    [root@CEL-550-x64-0-1-2 /]# /etc/init.d/mysqld start
    Starting MySQL: [ OK ]