Install MySQL 5.7 on Fedora 23/22, CentOS/RHEL 7.1/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.1/6.7/5.11 and Red Hat (RHEL) 7.1/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.1/6.7/5.11, Red Hat (RHEL) 7.1/6.7/5.11

1. Change root user

2. Install MySQL YUM repository


CentOS and Red Hat (RHEL)

3. Update or Install MySQL 5.7.9

Fedora 23/22

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

4. Start MySQL server and autostart MySQL on boot

Fedora 23/22/21 and CentOS 7.1

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


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
  • PASSWORD = password123

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.1

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


  1. Good Solution~~~ Thank you….

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

  2. 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]#

    • Hi shaurabh,

      So what password you used on last two attempts?

  3. 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.

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

    Bye from

  5. 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!

    • Hi Martin,

      Could you post output of following command:

  6. Hi JR,

    Here is what I get.

    # rpm -qa mysql\*

  7. 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?

    • 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”?

      • 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.

        • 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.

          • 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.

  8. 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

    • Thanks Mumo,

      Guide updated and typo fixed.

  9. 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 :


    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

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

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

  10. 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.

    • 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:

      • 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?

        • 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.

          • The new steps worked perfectly, thank you!



  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: [...]

Submit a Comment

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