Install MySQL 5.7 on Fedora 23/22, CentOS/RHEL 7.2/6.7/5.11

MySQL Logo

Are you looking MariaDB 5.5/10.0/10.1 Install guide?

MySQL 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 version 5.7 (5.7.9) on Fedora 23/22/21, CentOS 7.2/6.7/5.11 and Red Hat (RHEL) 7.2/6.7/5.11. This guide works of course with Oracle Linux and Scientific Linux too and MySQL 5.6/5.5 installation is possible too.

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.7.9 on Fedora 23/22/21, CentOS 7.2/6.7/5.11, Red Hat (RHEL) 7.2/6.7/5.11

1. Change root user

2. Install MySQL YUM repository

Fedora

CentOS and Red Hat (RHEL)

3. Update or Install MySQL 5.7.9

Fedora 23/22

Fedora 21, CentOS 7.2/6.7/5.11 and Red Hat (RHEL) 7.2/6.7/5.11

4. Start MySQL server and autostart MySQL on boot

Fedora 23/22/21 and CentOS 7.2

CentOS 6.7/5.11 and Red Hat (RHEL) 6.7/5.11

5. Get Your Generated Random root Password

Example Output:

And password is: -et)QoL4MLid

6. MySQL Secure Installation

  • 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

Output:

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

7. Connect to MySQL database (localhost) with password

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

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

1. Fedora 23/22/21 and CentOS/Red Hat (RHEL) 7.2

1.1 Add New Rule to Firewalld

1.2 Restart firewalld.service

2. CentOS/Red Hat (RHEL) 6.7/5.11

2.1 Edit /etc/sysconfig/iptables file:

2.2 Add following INPUT rule:

2.3 Restart Iptables Firewall:

3. Test remote connection

Share this post

255 Comments

  1. Yes, i believe so, but my “/etc/init.d/httpd start” isn’t working. Says there’s no such file or directory.

    Reply
  2. Hi,
    I had the same problem

    I get this error/message:
    http: syntax error on line 56 of /etc/httpd/conf/httpd.conf: Syntax error on line 6 of /etc/httpd/conf.modules.d/10-php.conf: Cannot load modules/libphp5.so in to server: /etc/httpd/modules/libphp5.so: symbol SSLeay_version, version OPENSSL_1.0.1 not defined in file libcrypto.so.10 with link time reference

    Do this:

    yum update openssl

    Reply
  3. Good Solution~~~ Thank you….

    Reply
    • Step 2 in fedora 22 is not working. yum localinfo command is depriciated in dnf. I had to download rpm manually

      Reply
  4. can u solve this error
    [root@localhost Desktop]# service mysql start
    Starting MySQL………………………………………………………………… SUCCESS!
    [root@localhost Desktop]# mysqladmin -u root password pinkuupadhyay
    mysqladmin: connect to server at ‘localhost’ failed
    error: ‘Access denied for user ‘root’@’localhost’ (using password: NO)’
    [root@localhost Desktop]# mysql -u root -p
    Enter password:
    ERROR 1045 (28000): Access denied for user ‘root’@’localhost’ (using password: NO)
    [root@localhost Desktop]# mysql -u root -p
    Enter password:
    ERROR 1045 (28000): Access denied for user ‘root’@’localhost’ (using password: YES)
    [root@localhost Desktop]# mysql -h localhost -u root -p
    Enter password:
    ERROR 1045 (28000): Access denied for user ‘root’@’localhost’ (using password: YES)
    [root@localhost Desktop]#

    Reply
    • Hi shaurabh,

      So what password you used on last two attempts?

      Reply
  5. Thank you for this tutorial. Did this installation many times already, but it is always good to have a tutorial like this that can be followed.

    Reply
  6. It worked like a charm! :D Thank you VERY much!

    Bye from
    Portugal

    Reply
  7. I followed the instructions and have according to that I have MySQL 5.5.36 server installed, however the client still shows up as 5.1.73 inside phpMyAdmin. phpMyAdmin gives me a warning message:

    Your PHP MySQL library version 5.1.73 differs from your MySQL server version 5.5.36. This may cause unpredictable behavior.

    How can I fix that? Please someone give me a solution. Thank you!

    Reply
    • Hi Martin,

      Could you post output of following command:

      Reply
  8. Hi JR,

    Here is what I get.

    # rpm -qa mysql\*
    mysql55w-5.5.36-3.w6.x86_64
    mysql55w-libs-5.5.36-3.w6.x86_64
    mysql55w-server-5.5.36-3.w6.x86_64

    Reply
  9. Hello,

    I have successfully installed MySQL, but it starts together with the system (as specified in the tutorial). Now, two short questions:

    1. to disable autostart on boot should I enter this under root?

    “systemctl disable mysqld.service”

    2, And how terrible is it (systemwise) to close the computer with mysql server running?

    Reply
    • Hello Vasile,

      1. Yes, you can disable mysql service it using that command as root.

      2. Do you mean close computer using “poweroff command”? Or close computer using “power switch”?

      Reply
      • Hello JR,

        I’m so sorry for not getting back on this earlier. I just stopped manually MySQL when booting the computer.

        To your question – close computer – I mean shutting down.

        I mean systemctl kind of controls that the server is starting and closing when I’m starting or shutting down the computer. Once I disable it, I might get into the situation when I shut down my laptop without stopping the server…How bad is that? For Fedora and for MySQL.

        Reply
        • First, it shouldn’t be fatal at all. If you are just writing something to db, then you might lost it, but normally everything is okay. And you can of course take daily / hourly backups to make sure that you can restore your db easily.

          I understand what you mean. One possible way is create custom systemctl script to only stop MySQL, but another question, before doing any script is why you don’t want to run MySQL background always? It shouldn’t use CPU or RAM that much, if you are not using it.

          Reply
          • Hi JR,

            Thank you for your reply. It uses up 100 000 kB, which is not much, but when you have a lot of things pile up, you try to figure what you need on permanent basis.

            I use it for the dev projects to store some data, so losing it would be undesirable. I guess, I’ll stick with running it in the background.

            Reply
  10. For Fedora 22 starting and enabling mysql :

    systemctl start mysql.service ## use restart after update
    systemctl enable mysql.service

    The correct commands should be:

    systemctl start mysqld.service ## use restart after update
    systemctl enable mysqld.service

    Reply
    • Thanks Mumo,

      Guide updated and typo fixed.

      Reply
  11. Once I ran the command(below) on Fedora 22(64-bit):

    dnf install mysql-community-server

    I noticed it replaced a package mariadb though I had not touched it prior.
    Afterwards when I ran the command :

    /usr/bin/mysql_secure_installation

    I am prompted for a root password for which there is no correct response.
    A catastrophic failure on my first attempt at setting up LAMP. Kindly assist

    Reply
    • If you have never set any root password, then it is just empty. So press just Enter and setup your own password.

      Reply
    • I am having this same problem. Even leaving the password empty doesn’t work.

      Reply
  12. Hi JR, I’m having trouble at section 6. I try to give no password for root and then I give a password but it doesn’t work. Here’s what I’m getting

    [me@mecomp~]$ /usr/bin/mysql_secure_installation

    Securing the MySQL server deployment.

    Enter password for user root:
    Error: Access denied for user ‘root’@’localhost’ (using password: NO)

    As you can see I didn’t enter a password here. This is a fresh install of MySql on Fedora 23. I can’t seem to find a solution. I’ve searched for a .pid file to reset the password but one doesn’t exist for MySql on my hard drive.

    Reply
    • Hi Graham,

      Do you have set any root password on your MariaDB installation?

      Here is instructions howto reset your mysql root password.

      If you don’t have any import data on your db, then you could of course remove your installation and reinstall it:

      Reply
      • Thank you for the reply. I never installed MariaDB so I have no import data on my db.

        I have tried reinstalling MySQL several times using the same commands you specified but that hasn’t fixed the problem.

        I’ve been reading more and it could be that a random password is being generated when the MySQL service is started for the first time. This is my current theory and I’ll be trying the solution at the link below later today. From your experience do you think this could be the problem?

        http://dba.stackexchange.com/questions/22053/reset-mysql-root-password-in-lampp-server-on-ubuntu

        Reply
        • You are totally right, root password is really generated randomly, since mysql 5.7.7 RC version. Sorry this is totally my mistake, because I didn’t tested clean installation between minor versions, just updated and everything worked normally.

          I updated this guide, so could you please check/test Step 5. to get your generated password from /var/log/mysqld.log and then try /usr/bin/mysql_secure_installation again.

          Reply
          • The new steps worked perfectly, thank you!

            Reply
  13. Hello JR!

    I have recently upgraded to Fedora 23 and discovered that I am missing MySQL Workbench. It is disappointing as I don’t know the MySQL command line commands and have a Java project in Dev that uses the DB already installed and running…

    There is no Workbench RPM for Fedora 23, installing the 22 RPM results in: error: Failed dependencies:
    libzip.so.2()(64bit) is needed by mysql-workbench-community-6.3.5-1.fc22.x86_64

    Running: dnf install libzip

    Returns: Last metadata expiration check performed 0:00:01 ago on Sat Dec 5 20:33:17 2015.
    Package libzip-1.0.1-2.fc23.x86_64 is already installed, skipping.
    Dependencies resolved.
    Nothing to do.
    Complete!

    And, alas, there is no libzip.so.2()(64bit) version for Fedora 23: https://www.rpmfind.net/linux/rpm2html/search.php?query=libzip.so.2()(64bit)

    I would appreciate any help.

    Thank you!

    Reply
  14. This is very helpful for me..

    Thank you!

    Reply
  15. Problem please help: (first of)Hello, this was very helpful thank you for the tutorial.It was a life saver for Fedora 23. I am trying to create an user but it gives me this error
    “ERROR 1819 (HY000): Your password does not satisfy the current policy requirements”

    when i type in
    “create user ‘user_name’@’localhost’ identified by ‘user_name0’;”

    any help would be much appreciated and thank you in advance.

    Reply

Submit a Comment

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