For the impatient:

Debian Ying Yang

In the latest stable version of Debian, if you ask to install mysql-server, you now get installed mariadb automatically, with no (evident) way of installing Oracle’s MySQL. Any major version upgrade has to be done carefully (not only for MariaDB, but also for MySQL and Postgres), and I bet that a MySQL 5.5 to MariaDB 10.1 will cause a huge confusion. Not only it will fail user expectations, I think this will cause large issues now that MariaDB has chosen to become a “hard” fork, and become incompatible in many ways with MySQL. Not only the server upgrade will cause user struggle, the connector is probably going to cause pain to users (as it has already been noticed in some of my infrastructure).

In order to try to be helpful for those MySQL users that may be looking for help, here is how to install and setup MySQL server in Debian 9 “Stretch”, using MySQL upstream repo. The commands shown above may not be the best course of action on all cases (be careful when downloading things from then Internet), and as a disclaimer, you should read the official documentation on how to use Oracle’s MySQL apt repository in advance. The following is a more verbose, step-by step explanation, plus some extended explanations on why I chose to recommend this method in particular (and its disadvantages).

  1. Install Oracle’s APT Repositories

    MySQL Release Engineering team provides ready-to-use apt repositories with most of it software, including the server and many of its utilities. To enable the server repository, edit your apt sources file (or better, create a new one by executing:

    And add the following lines:

    Here, I have chosen to install MySQL 5.7, but 5.6 and 8.0 (not yet stable as of June 2017) are also available for Debian stable. You can also chose to enable mysql-tools (normally here they add the connectors, mysql-router and the mysql-utilities, but right now it is empty) and mysql-apt-config the repo where the automatic apt configurator package is. While the mysql-apt-config utility is nice to have, I like to have control over my repositories manually, even if that means having to do this again in the future.

    Before starting to use the repo, you have to add the repo public key as trusted, for that I suggest:

    RPM and APT repos seem to share the GPG key, and that is at (it is the same one that mysql-apt-config utility adds automatically on install). Not doing so will not make the rest of the install fail, but it will warn you due to the lack of a signed key.

    If you run apt-key list you will see a new trusted key for apt:

    The advantages of using a repository rather than a one-time install is that you will get automatic updates for minor versions that may correct bugs and security issues (with minimal feature changes).

  2. Refresh your available package list

    Just run:

    You should see a reference to with no errors. You probably have other main repos or pending updates, that is ok.

  3. Install MySQL Server:

    If everything has gone according to plan, after asking you for permission to install it and its dependencies, you should have NOT installed mariadb-server, but the real mysql server instead. If at some stage you got an error, check your spelling or your permissions- all of the above steps should have been run with superuser or root permissions, and not as a normal user. That means using sudo before each command, su -c CMD or logging in as root in advance.

    If you do not have network on the server you are trying to install MySQL, you may want to download the .deb bundle for Debian9 from the download page.

  4. Start, stop and manage your server

    These MySQL packages initialize and start MySQL server by default:

    You can manage the service with service wrapper or with the native systemd command. Remember that it is possible that earlier os versions had a package that still used backwards init.d compatibility- it is not the case anymore. However, execution of /etc/init.d/mysql will be captured and converted transparently into an equivalent systemctl command. But get accustomed to say goodbye to the horrible mysqld_safe script and its options (but also its vulnerabilities).

  5. Use your server

    This package sets up socket_authentication automatically for the user root, so no need to setup a password- accessing as the root unix user to the mysql root user will be directly granted:

    The default configuration binds the server to, you may want to setup your users and bind it to a public address before put it into production. Config can be found at: /etc/mysql/mysql.conf.d/mysqld.cnf.

Please use @jynus to tell me if this was useful to you, or to tell me where I am wrong.

How to install MySQL Server on Debian Stretch
Tagged on:                                     

16 thoughts on “How to install MySQL Server on Debian Stretch

    • 2017-06-27 at 22:34

      The TLS certificate on that page looks correct to me- you should not use –no-check-certificate or you expose yourself to a mitm attack. Obviously everyone should be careful to check they are adding the right key when accepting 3rd party repositories.

      • 2017-06-27 at 22:38

        Yeah, I’m not saying this is a correction. It’s just a workaround in case of that.

  • 2017-07-10 at 10:50

    mysql-server : mysql-community-server (= 5.7.18-1debian9) not installed

    • 2017-07-16 at 18:42

      What is the output of “apt search mysql-server” for you- does the install say that the package failed to configure? There can be many reasons for that to happen- upstream packages sometimes fail on configure if there are old config or other files around.

      • 2017-08-13 at 07:34

        I have the same error:
        Preparing to unpack …/mysql-community-server_5.7.19-1debian9_amd64.deb …
        dpkg: error processing archive /var/cache/apt/archives/mysql-community-server_5.7.19-1debian9_amd64.deb (–unpack):

        apt search mysql-server
        Sorting… Done
        Full Text Search… Done
        auth2db/oldstable 0.2.5-2+dfsg-5 all
        Powerful and eye-candy IDS logger, log viewer and alert generator

        default-mysql-server/stable 1.0.2 all
        MySQL database server binaries and system database setup (metapackage)

        default-mysql-server-core/stable 1.0.2 all
        MySQL database server binaries (metapackage)

        mysql-server/unknown,now 5.7.19-1debian9 amd64 [installed]
        MySQL Server meta package depending on latest version

        mysql-server-5.5/oldstable 5.5.57-0+deb8u1 amd64 [residual-config]
        MySQL database server binaries and system database setup

        mysql-server-core-5.5/oldstable 5.5.57-0+deb8u1 amd64
        MySQL database server binaries

  • 2017-09-20 at 17:59

    hi, I tried installing mysql on my raspberry pi this way, but when I run apt update it gives me this:

    Hit:1 stretch InRelease
    Hit:2 stretch InRelease
    Hit:3 stretch InRelease
    Reading package lists… Done
    Building dependency tree
    Reading state information… Done
    All packages are up to date.
    N: Skipping acquire of configured file ‘mysql-apt-config/binary-armhf/Packages’ as repository ‘ stretch InRelease’ doesn’t support architecture ‘armhf’
    N: Skipping acquire of configured file ‘mysql-5.7/binary-armhf/Packages’ as repository ‘ stretch InRelease’ doesn’t support architecture ‘armhf’
    N: Skipping acquire of configured file ‘mysql-tools/binary-armhf/Packages’ as repository ‘ stretch InRelease’ doesn’t support architecture ‘armhf’

    any suggestions?

  • 2017-11-24 at 23:07

    Help: in mysql -u root

    ERROR 1524 (HY000): Plugin ‘unix_socket’ is not loaded

  • 2017-12-14 at 22:29

    Gracia me fue de utilidad!

  • 2017-12-27 at 11:31

    You’re amazing. Thank’s.

  • 2018-02-09 at 22:28

    This is exactly what i needed! thanks!

  • 2018-02-09 at 23:47

    Great article! Was able to install mysql-server on jessie w/o a hitch following these instructions!

  • 2018-02-14 at 14:45

    followed all steps ..
    etering: sudo systemctl status mysql
    ● MariaDB.service – MySQL Community Server
    instead of Mysql.service

    • 2018-02-18 at 15:45

      Check the repository installation steps for errors- some steps may have failed for you.

Comments are closed.