Install MySQL 5.5.20 on Fedora 16/15, CentOS/Red Hat (RHEL) 6.2/5.7

MySQL LogoMySQL is a relational database management system (RDBMS) that runs as a server providing multi-user access to a number of databases. This is guide, howto install or upgrade MySQL Community Server latest and greatest version 5.5.20 on Fedora 16/15/14/13/12, CentOS 6.2/6.1/6/5.7 and Red Hat (RHEL) 6.2/6.1/6/5.7.

Note: If you are upgrading MySQL (from earlier version), then make sure that you backup (dump and copy) your database and configs. And remember run mysql_upgrade command.

Install MySQL Database 5.5.20 on Fedora 16/15/14/13/12, CentOS 6.2/6.1/6/5.7, Red Hat (RHEL) 6.2/6.1/6/5.7

1. Change root user

su -
## OR ##
sudo -i

2. Install Remi repository

Fedora

Currently extra repos are not needed on Fedora 16.

## Remi Dependency on Fedora 15, 14, 13, 12, 11, 10, 9, 8
rpm -Uvh http://download1.rpmfusion.org/free/fedora/rpmfusion-free-release-stable.noarch.rpm
rpm -Uvh http://download1.rpmfusion.org/nonfree/fedora/rpmfusion-nonfree-release-stable.noarch.rpm

## Fedora 15 ##
rpm -Uvh http://rpms.famillecollet.com/remi-release-15.rpm

## Fedora 14 ##
rpm -Uvh http://rpms.famillecollet.com/remi-release-14.rpm

## Fedora 13 ##
rpm -Uvh http://rpms.famillecollet.com/remi-release-13.rpm

## Fedora 12 ##
rpm -Uvh http://rpms.famillecollet.com/remi-release-12.rpm

CentOS and Red Hat (RHEL)

## Remi Dependency on CentOS 6 and Red Hat (RHEL) 6 ##
rpm -Uvh http://download.fedora.redhat.com/pub/epel/6/i386/epel-release-6-5.noarch.rpm

## CentOS 6 and Red Hat (RHEL) 6 ##
rpm -Uvh http://rpms.famillecollet.com/enterprise/remi-release-6.rpm

## Remi Dependency on CentOS 5 and Red Hat (RHEL) 5 ##
rpm -Uvh http://download.fedora.redhat.com/pub/epel/5/i386/epel-release-5-4.noarch.rpm

## CentOS 5 and Red Hat (RHEL) 5 ##
rpm -Uvh http://rpms.famillecollet.com/enterprise/remi-release-5.rpm

3. Check Available MySQL versions

Fedora 16

yum list mysql mysql-server

Fedora 15, 14, 13, 12

yum --enablerepo=remi list mysql mysql-server

CentOS 6.2/6.1/6/5.7 and Red Hat (RHEL) 6.2/6.1/6/5.7

yum --enablerepo=remi,remi-test list mysql mysql-server

Output:

Loaded plugins: changelog, fastestmirror, presto, refresh-packagekit
...
remi                                                            | 3.0 kB     00:00
remi/primary_db                                                 | 106 kB     00:00
Available Packages
mysql.i686                               5.5.20-1.fc14.remi                        @remi
mysql-server.i686                        5.5.20-1.fc14.remi                        @remi

4. Update or Install MySQL 5.5.20

Fedora 16

yum install mysql mysql-server

Fedora 15, 14, 13, 12

yum --enablerepo=remi install mysql mysql-server

CentOS 6.2/6.1/6/5.7 and Red Hat (RHEL) 6.2/6.1/6/5.7

yum --enablerepo=remi,remi-test install mysql mysql-server

5. Start MySQL server and autostart MySQL on boot

Fedora 16

systemctl start mysqld.service ## use restart after update

systemctl enable mysqld.service

Fedora 15/14/13/12/11, CentOS 6.2/6.1/6/5.7 and Red Hat (RHEL) 6.2/6.1/6/5.7

/etc/init.d/mysqld start ## use restart after update
## OR ##
service mysqld start ## use restart after update

chkconfig --levels 235 mysqld on

If you get following error on Fedora 16:

Job failed. See system logs and 'systemctl status' for details.

Then Build local SELinux policy for MySQL with following commands:

grep mysqld_safe /var/log/audit/audit.log | audit2allow -M mysqlpol

semodule -i mysqlpol.pp

## Try to start MySQL again ##
systemctl start mysqld.service

6. MySQL Secure Installation

  • Set (Change) root password
  • Remove anonymous users
  • Disallow root login remotely
  • Remove test database and access to it
  • Reload privilege tables

Start MySQL Secure Installation with following command

/usr/bin/mysql_secure_installation

Output:

NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MySQL
      SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!

In order to log into MySQL to secure it, we\'ll need the current
password for the root user.  If you\'ve just installed MySQL, and
you haven\'t set the root password yet, the password will be blank,
so you should just press enter here.

Enter current password for root (enter for none):
OK, successfully used password, moving on...

Setting the root password ensures that nobody can log into the MySQL
root user without the proper authorisation.

Set root password? [Y/n] Y
New password:
Re-enter new password:
Password updated successfully!
Reloading privilege tables..
 ... Success!

By default, a MySQL installation has an anonymous user, allowing anyone
to log into MySQL without having to have a user account created for
them.  This is intended only for testing, and to make the installation
go a bit smoother.  You should remove them before moving into a
production environment.

Remove anonymous users? [Y/n] Y
 ... Success!

Normally, root should only be allowed to connect from 'localhost'.  This
ensures that someone cannot guess at the root password from the network.

Disallow root login remotely? [Y/n] Y
 ... Success!

By default, MySQL comes with a database named 'test' that anyone can
access.  This is also intended only for testing, and should be removed
before moving into a production environment.

Remove test database and access to it? [Y/n] Y
 - Dropping test database...
 ... Success!
 - Removing privileges on test database...
 ... Success!

Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.

Reload privilege tables now? [Y/n] Y
 ... Success!

Cleaning up...

All done!  If you\'ve completed all of the above steps, your MySQL
installation should now be secure.

Thanks for using MySQL!

Note: If you don’t want some reason, do a “MySQL Secure Installation” then at least it’s very important to change the root user’s password

mysqladmin -u root password [your_password_here]

## Example ##
mysqladmin -u root password myownsecrectpass

7. Connect to MySQL database (localhost) with password

mysql -u root -p

## OR ##
mysql -h localhost -u root -p

8. Create Database, Create MySQL User and Enable Remote Connections to MySQL Database

This example uses following parameters:

  • DB_NAME = webdb
  • USER_NAME = webdb_user
  • REMOTE_IP = 10.0.15.25
  • PASSWORD = password123
  • PERMISSIONS = ALL
## CREATE DATABASE ##
mysql> CREATE DATABASE webdb;

## CREATE USER ##
mysql> CREATE USER 'webdb_user'@'10.0.15.25' IDENTIFIED BY 'password123';

## GRANT PERMISSIONS ##
mysql> GRANT ALL ON webdb.* TO webdb_user@'10.0.15.25';

##  FLUSH PRIVILEGES, Tell the server to reload the grant tables  ##
mysql> FLUSH PRIVILEGES;

Enable Remote Connection to MySQL Server –> Open MySQL Port (3306) on Iptables Firewall (as root user again)

1. Edit /etc/sysconfig/iptables file:

nano -w /etc/sysconfig/iptables

2. Add following line before COMMIT:

-A INPUT -m state --state NEW -m tcp -p tcp --dport 3306 -j ACCEPT

3. Restart Iptables Firewall:

service iptables restart
## OR ##
/etc/init.d/iptables restart

4. Test remote connection:

mysql -h dbserver_name_or_ip_address -u webdb_user -p webdb
Follow If Not True Then False Updates!
  1. LAMP on Fedora 16/15, CentOS/Red Hat (RHEL) 6.2/5.7 – (Linux, Apache, MySQL, PHP)
  2. Install Apache/PHP 5.3.10 on Fedora 16/15, CentOS/Red Hat (RHEL) 6.2/5.7
  3. LEMP on Fedora 16/15, CentOS/Red Hat (RHEL) 6.2/5.7 – (Linux, Nginx, MySQL, PHP)
  4. Install VirtualBox 4.1.8 on Fedora 16/15, CentOS/Red Hat (RHEL) 6.2/5.7
  5. Install MongoDB 2.0.1 on Fedora 16/15, CentOS/Red Hat (RHEL) 6/5.7

125 Comments

  1. Great tutorial (like all the others on your site).

    Thanks Davide

  2. Thank you, JR

    Httpd start normally.

    audit.log -> http://www.sendspace.com/file/vlq3wk

    [root@rrom-notebook rrom]# grep mysql /var/log/audit/audit.log > audit.log
    [root@rrom-notebook rrom]#
    [root@rrom-notebook rrom]# wc -l /var/log/audit/audit.log
    19300 /var/log/audit/audit.log
    [root@rrom-notebook rrom]# ^C
    [root@rrom-notebook rrom]#

    • Hi Roman,

      Still sounds some SELinux problem, but I’m not sure is your auditd service running, please could you post also output of following command:

      systemctl status auditd.service
      

      Do you run MySQL just with default setup?

      • I just noticed that the selinux-policy-3.10.0-61 and selinux-policy-targeted-3.10.0-61 is released, so try update your system and try to start mysql service again…?

  3. [rrom@rrom-notebook ~]$ systemctl status auditd.service
    auditd.service – Security Auditing Service
    Loaded: loaded (/lib/systemd/system/auditd.service; enabled)
    Active: active (running) since Thu, 01 Dec 2011 10:56:07 +0300; 19min ago
    Process: 1065 ExecStartPost=/sbin/auditctl -R /etc/audit/audit.rules (code=exited, status=0/SUCCESS)
    Main PID: 1059 (auditd)
    CGroup: name=systemd:/system/auditd.service
    ├ 1059 /sbin/auditd -n
    ├ 1098 /sbin/audispd
    └ 1099 /usr/sbin/sedispatch
    [rrom@rrom-notebook ~]$

    I update system to selinux-policy-3.10.0-61 and selinux-policy-targeted-3.10.0-61, but:

    [rrom@rrom-notebook ~]$ sudo service mysqld start
    [sudo] password for rrom:
    Redirecting to /bin/systemctl start mysqld.service
    Job failed. See system logs and ‘systemctl status’ for details.
    [rrom@rrom-notebook ~]$

  4. [rrom@rrom-notebook ~]$ su
    Password:
    [root@rrom-notebook rrom]# grep mysqld_safe /var/log/audit/audit.log | audit2allow -M mysqlpol
    compilation failed:
    mysqlpol.te:6:ERROR ‘syntax error’ at token ” on line 6:

    /usr/bin/checkmodule: error(s) encountered while parsing configuration
    /usr/bin/checkmodule: loading policy configuration from mysqlpol.te
    [root@rrom-notebook rrom]# semodule -i mysqlpol.pp
    semodule: Failed on mysqlpol.pp!
    [root@rrom-notebook rrom]#

  5. Hi Roman,

    Okey, I have to believe that it’s not SELinux problem. :) And yes audit2allow fails because your grep command grep mysqld_safe /var/log/audit/audit.log output is just empty.

    So this is some totally new problem. I actually do some tests with just installed Fedora 16 and installed mysql and mysql-server packages and it’s starts normally, so this is very strange, but next I have to ask more information from you… :) Let’s check following things next, could you post following log file here (So I assume that you are using the default mysqld log file):

    /var/log/mysqld.log
    

    And then try following:

    ## Change root ##
    su -
    
    ## Change mysql user ##
    su mysql
    
    ## Run following long command ##
    ## 32-bit system ##
    /usr/libexec/mysqld --basedir=/usr --datadir=/var/lib/mysql --plugin-dir=/usr/lib/mysql/plugin --log-error=/var/log/mysqld.log --pid-file=/var/run/mysqld/mysqld.pid --socket=/var/lib/mysql/mysql.sock
    
    ## 64-bit system
    /usr/libexec/mysqld --basedir=/usr --datadir=/var/lib/mysql --plugin-dir=/usr/lib64/mysql/plugin --log-error=/var/log/mysqld.log --pid-file=/var/run/mysqld/mysqld.pid --socket=/var/lib/mysql/mysql.sock
    

    This is exactly same command what systemctl tries to run. Do you get any errors here or is it failing?

  6. Hi, I got the error:
    ‘Job failed. See system logs and ‘systemctl status’ for details.’

    After execute the command: ‘systemctl start mysqld.service’

    And then I executed: ‘grep mysqld_safe /var/log/audit/audit.log | audit2allow -M mysqlpol’

    But got the error:

    compilation failed:
    mysqlpol.te:6:ERROR ‘syntax error’ at token ” on line 6:

    /usr/bin/checkmodule: error(s) encountered while parsing configuration
    /usr/bin/checkmodule: loading policy configuration from mysqlpol.te

    I Search a lot on net, but don’t found anything! Could you help me JR?

    p.s.: Sorry for my bad english

  7. So, I Execute these commands:

    su -

    ## Change mysql user ##
    su mysql

    ## Run following long command ##

    ## 64-bit system
    /usr/libexec/mysqld –basedir=/usr –datadir=/var/lib/mysql –plugin-dir=/usr/lib64/mysql/plugin –log-error=/var/log/mysqld.log –pid-file=/var/run/mysqld/mysqld.pid –socket=/var/lib/mysql/mysql.sock

    And get no output…

    • Okey, you don’t get output, but is your MySQL server working then? :)

      Open another console and write:

      mysql
      
      • I got this:

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

        And my version of SELinux-policy is:

        selinux-policy.noarch 3.10.0-64.fc16

        • Hi Artur,

          Could you post your /var/log/mysqld.log log file here?

          • 111205 22:02:12 [ERROR] Can't open the mysql.plugin table. Please run mysql_upgrade to create it.
            111205 22:02:12 InnoDB: The InnoDB memory heap is disabled
            111205 22:02:12 InnoDB: Mutexes and rw_locks use GCC atomic builtins
            111205 22:02:12 InnoDB: Compressed tables use zlib 1.2.5
            111205 22:02:12 InnoDB: Using Linux native AIO
            111205 22:02:12 InnoDB: Initializing buffer pool, size = 128.0M
            111205 22:02:12 InnoDB: Completed initialization of buffer pool
            111205 22:02:12 InnoDB: highest supported file format is Barracuda.
            111205 22:02:13  InnoDB: Waiting for the background threads to start
            111205 22:02:14 InnoDB: 1.1.8 started; log sequence number 1595675
            111205 22:02:14 [ERROR] /usr/libexec/mysqld: Can't find file: './mysql/host.frm' (errno: 13)
            111205 22:02:14 [ERROR] Fatal error: Can't open and lock privilege tables: Can't find file: './mysql/host.frm' (errno: 13)
            111205 22:02:15 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql
            111205 22:02:15 [Note] Plugin 'FEDERATED' is disabled.
            /usr/libexec/mysqld: Can't find file: './mysql/plugin.frm' (errno: 13)
            111205 22:02:15 [ERROR] Can't open the mysql.plugin table. Please run mysql_upgrade to create it.
            111205 22:02:15 InnoDB: The InnoDB memory heap is disabled
            111205 22:02:15 InnoDB: Mutexes and rw_locks use GCC atomic builtins
            111205 22:02:15 InnoDB: Compressed tables use zlib 1.2.5
            111205 22:02:15 InnoDB: Using Linux native AIO
            111205 22:02:15 InnoDB: Initializing buffer pool, size = 128.0M
            111205 22:02:15 InnoDB: Completed initialization of buffer pool
            111205 22:02:15 InnoDB: highest supported file format is Barracuda.
            111205 22:02:15  InnoDB: Waiting for the background threads to start
            111205 22:02:16 InnoDB: 1.1.8 started; log sequence number 1595675
            111205 22:02:16 [ERROR] /usr/libexec/mysqld: Can't find file: './mysql/host.frm' (errno: 13)
            111205 22:02:16 [ERROR] Fatal error: Can't open and lock privilege tables: Can't find file: './mysql/host.frm' (errno: 13)
            111205 22:02:17 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql
            111205 22:02:17 [Note] Plugin 'FEDERATED' is disabled.
            /usr/libexec/mysqld: Can't find file: './mysql/plugin.frm' (errno: 13)
            111205 22:02:17 [ERROR] Can't open the mysql.plugin table. Please run mysql_upgrade to create it.
            111205 22:02:17 InnoDB: The InnoDB memory heap is disabled
            111205 22:02:17 InnoDB: Mutexes and rw_locks use GCC atomic builtins
            111205 22:02:17 InnoDB: Compressed tables use zlib 1.2.5
            111205 22:02:17 InnoDB: Using Linux native AIO
            111205 22:02:17 InnoDB: Initializing buffer pool, size = 128.0M
            111205 22:02:17 InnoDB: Completed initialization of buffer pool
            111205 22:02:17 InnoDB: highest supported file format is Barracuda.
            111205 22:02:17  InnoDB: Waiting for the background threads to start
            

            I post only these, because the file is too long but these sets of errors are repeated.

            • Thanks Artur,

              Try to run:

              mysql_upgrade
              

              And please post output of following commands:

              ls -la /usr/lib/mysql
              
              ls -la /var/lib/mysql/mysql/ |grep -e host -e plugin
              
              • root@artur artur# mysql_upgrade
                Looking for ‘mysql’ as: mysql
                Looking for ‘mysqlcheck’ as: mysqlcheck
                Running ‘mysqlcheck with default connection arguments
                mysqlcheck: Got error: 2002: Can’t connect to local MySQL server through socket ‘/var/lib/mysql/mysql.sock’ (2) when trying to connect
                FATAL ERROR: Upgrade failed
                root@artur artur# ls -la /usr/lib/mysql
                ls: impossível acessar /usr/lib/mysql: Arquivo ou diretório não encontrado
                root@artur artur# ls -la /var/lib/mysql/mysql/ |grep -e host -e plugin
                -rw-rw—-. 1 root root 9510 Dez 4 20:01 host.frm
                -rw-rw—-. 1 root root 0 Dez 4 20:01 host.MYD
                -rw-rw—-. 1 root root 2048 Dez 4 20:01 host.MYI
                -rw-rw—-. 1 root root 8586 Dez 4 20:01 plugin.frm
                -rw-rw—-. 1 root root 0 Dez 4 20:01 plugin.MYD
                -rw-rw—-. 1 root root 1024 Dez 4 20:01 plugin.MYI

                • Now I see your problem, you have (at least) wrong permissions on /usr/lib/mysql/mysql directory. And sorry I ask you ls output from wrong directory, so could you post also output of following commands:

                  ls -la /var/lib/ |grep mysql
                  
                  ls -la /var/lib/mysql
                  
                  • No problem! You helps me so much…Of course I won’t reclaim hehehe.

                    The Outputs:

                    root@artur artur# ls -la /var/lib/ |grep mysql
                    drwxr-xr-x. 5 mysql mysql 4096 Dez 6 17:00 mysql
                    root@artur artur# ls -la /var/lib/mysql
                    total 28696
                    drwxr-xr-x. 5 mysql mysql 4096 Dez 6 17:00 .
                    drwxr-xr-x. 43 root root 4096 Dez 4 19:41 ..
                    -rw——-. 1 mysql mysql 402 Dez 4 23:11 .bash_history
                    -rw-rw—-. 1 mysql mysql 18874368 Dez 4 21:01 ibdata1
                    -rw-rw—-. 1 mysql mysql 5242880 Dez 6 17:00 ib_logfile0
                    -rw-rw—-. 1 mysql mysql 5242880 Dez 4 20:03 ib_logfile1
                    drwx——. 2 root root 4096 Dez 4 20:01 mysql
                    drwx——. 2 root root 4096 Dez 4 20:01 performance_schema
                    drwx——. 2 root root 4096 Dez 4 20:01 test
                    root@artur artur#

                    • Thanks! :)

                      Some reason your permissions are changed from mysql:mysql to root:root, so try following (as root):

                      ## Change directory to /var/lib/mysql ##
                      cd /var/lib/mysql/
                      
                      ## Change directories permissions recursively ##
                      chown -R mysql:mysql mysql/ performance_schema/ test/
                      
                      ## Try to start mysqld again ##
                      systemctl start mysqld.service
                      
  8. It’s works! You are a linux developer or something like this? :0 Well who you understand the last output? I say, to know exataly the problem?
    And how you came to suspect that the problem was access permission?

    Thanks a lot! I am very young on linux and on fedora much more.

    • Excellent to hear that your MySQL is working… :)

      I’m not Linux developer :) But I have used Linux very long time (about 12 years now), I’m also sysadmin, database admin and developer… :)

      Your last output tells about some strange problem with your /var/lib/mysql/ directory permission, just checked my own installations and look what permissions should be when MySQL working normally (I think that some Fedora 16 MySQL update is messed those permissions, because normally MySQL is working out of the box). Actually your MySQL error log shows something interesting when mysqld try to start it doesn’t found /mysql/host.frm and /mysql/plugin.frm files which should exists, that’s why I wanted to see do have those files and what are those files permissions. ;)

      You are very welcome! And it’s always nice to see new Linux users and if you have some problems which are not related to any guides, feel free to join if !1 0 forums and ask your questions. :)

      • Joined!

        • Cool! :)

  9. thanks for such a wonderfull help in vein. It helps me lot and now I am running my mysql

  10. When I go to /etc/sysconfig/iptables, there is nothing there. I am using CentOS 6. What can I do to correct this?

  11. I found the error in my ways…lol

    Thanks for the awesome tutorial

  12. Thanks a lot for the comprehensive list :). It was very helpful.

  13. Hi JR,

    just a quick question:

    If I would like to run WordPress only from local host, with no intention to access the data from any other computer, do I still need to follow the part

    Enable Remote Connection to MySQL Server –> Open MySQL Port (3306) on Iptables Firewall (as root user again) ?

    Thanks in advance!

    -Mikko

    • Hi Mikko,

      First of all, really nice to hear that you got MySQL working! :)

      And yes, if you want use only local connections, then do not open MySQL port 3306. :)

      In any case might be better not open MySQL port to the public network. This part of guide is mainly/normally intended for LAN usage, where all (database) servers are behind firewalls, load balancers and so on… :)

  14. Hi JR.

    This site is ridiculously helpful.

    I’m having some problems that appear to be similar to but distinct from those that Roman described. I’m able to get almost done with all of step 5, but then when i try this command

    grep mysqld_safe /var/log/audit/audit.log | audit2allow -M mysqlpol

    i get the following

    -bash: audit2allow: command not found

    any idea what i’m up against here?

    your help is much appreciated.

    Ben

    • Hi Benjamin,

      Thanks! :D

      First, do you get following error when you try to start mysqld?

      Job failed. See system logs and 'systemctl status' for details.
      
  15. Hi,
    after following your steps i got this error :
    ERROR 2003 (HY000): Can’t connect to MySQL server on ’10.0.15.25′ (110)
    Can u suggest me about this ?

    My PC ENVIRONMENT : FEDORA 13 ,Apache installed ,mysql 5.5.20
    I have doubt this remote_ip .. Please explain about it..

    Thank u ..

    • Hi Rizvan,

      This REMOTE_IP 10.0.15.25, is just a hypothetical example, you have to use of course your own remote ip(s) or localhost or some other address.

Leave a Comment

Your email address will not be published. Required fields are marked *

*

You may 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> <pre lang="" line="" escaped="" highlight="">

Trackbacks/Pingbacks

  1. Install MySQL 5.1 (5.1.49) on Fedora 13, CentOS 5.5, Red Hat (RHEL … | mysql - [...] artykuł: Install MySQL 5.1 (5.1.49) on Fedora 13, CentOS 5.5, Red Hat (RHEL … a-server-providing, fedora, greatest-version, ...
  2. Creando una base de datos en MySQL para conectar con Haskell | Sólo para Mí! - [...] rows affected (0.00 sec) mysql> FLUSH PRIVILEGES; Query OK, 0 rows affected (0.00 sec) Fuente: http://www.if-not-true-then-false.com/2010/install-mysql-on-fedora-centos-red-hat-rhel/ [...]
Bear