For the impatient:
# echo -e "deb http://repo.mysql.com/apt/debian/ stretch mysql-5.7\ndeb-src http://repo.mysql.com/apt/debian/ stretch mysql-5.7" > /etc/apt/sources.list.d/mysql.list # wget -O /tmp/RPM-GPG-KEY-mysql https://repo.mysql.com/RPM-GPG-KEY-mysql # apt-key add /tmp/RPM-GPG-KEY-mysql # apt update # apt install mysql-server
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).
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:
# nano /etc/apt/sources.list.d/mysql.list
And add the following lines:
deb http://repo.mysql.com/apt/debian/ stretch mysql-5.7 deb-src http://repo.mysql.com/apt/debian/ stretch mysql-5.7
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) andmysql-apt-config
the repo where the automatic apt configurator package is. While themysql-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:
# wget -O /tmp/RPM-GPG-KEY-mysql https://repo.mysql.com/RPM-GPG-KEY-mysql # apt-key add /tmp/RPM-GPG-KEY-mysql
RPM and APT repos seem to share the GPG key, and that is at https://repo.mysql.com/RPM-GPG-KEY-mysql (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:# apt-key list /etc/apt/trusted.gpg -------------------- pub dsa1024 2003-02-03 [SCA] [expires: 2019-02-17] A4A9 4068 76FC BD3C 4567 70C8 8C71 8D3B 5072 E1F5 uid [ unknown] MySQL Release Engineering
[...] 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).
Refresh your available package list
Just run:
# apt update Ign:1 http://softlibre.unizar.es/debian stretch InRelease Hit:2 http://softlibre.unizar.es/debian stretch-updates InRelease Hit:3 http://security.debian.org/debian-security stretch/updates InRelease Hit:4 http://softlibre.unizar.es/debian stretch Release Get:5 http://repo.mysql.com/apt/debian stretch InRelease [14.2 kB] Get:7 http://repo.mysql.com/apt/debian stretch/mysql-5.7 Sources [870 B] Get:8 http://repo.mysql.com/apt/debian stretch/mysql-5.7 amd64 Packages [5,643 B] Fetched 20.7 kB in 6s (3,320 B/s) Reading package lists... Done Building dependency tree Reading state information... Done All packages are up to date.
You should see a reference to
repo.mysql.com
with no errors. You probably have other main repos or pending updates, that is ok.Install MySQL Server:
# apt install mysql-server Reading package lists... Done Building dependency tree Reading state information... Done The following additional packages will be installed: libaio1 libatomic1 libmecab2 libnuma1 mysql-client mysql-community-client mysql-community-server The following NEW packages will be installed: libaio1 libatomic1 libmecab2 libnuma1 mysql-client mysql-community-client mysql-community-server mysql-server 0 upgraded, 8 newly installed, 0 to remove and 0 not upgraded. Need to get 36.7 MB of archives. After this operation, 253 MB of additional disk space will be used. Do you want to continue? [Y/n] Y Get:1 http://repo.mysql.com/apt/debian stretch/mysql-5.7 amd64 mysql-community-client amd64 5.7.18-1debian9 [8,859 kB] Get:2 http://softlibre.unizar.es/debian stretch/main amd64 libaio1 amd64 0.3.110-3 [9,412 B] Get:3 http://softlibre.unizar.es/debian stretch/main amd64 libatomic1 amd64 6.3.0-18 [8,920 B] Get:4 http://softlibre.unizar.es/debian stretch/main amd64 libnuma1 amd64 2.0.11-2.1 [33.3 kB] Get:5 http://softlibre.unizar.es/debian stretch/main amd64 libmecab2 amd64 0.996-3.1 [256 kB] Get:6 http://repo.mysql.com/apt/debian stretch/mysql-5.7 amd64 mysql-client amd64 5.7.18-1debian9 [12.6 kB] Get:7 http://repo.mysql.com/apt/debian stretch/mysql-5.7 amd64 mysql-community-server amd64 5.7.18-1debian9 [27.5 MB] Get:8 http://repo.mysql.com/apt/debian stretch/mysql-5.7 amd64 mysql-server amd64 5.7.18-1debian9 [12.6 kB] Fetched 36.7 MB in 4s (8,495 kB/s) Preconfiguring packages ... Selecting previously unselected package libaio1:amd64. (Reading database ... 27516 files and directories currently installed.) Preparing to unpack .../0-libaio1_0.3.110-3_amd64.deb ... Unpacking libaio1:amd64 (0.3.110-3) ... Selecting previously unselected package libatomic1:amd64. Preparing to unpack .../1-libatomic1_6.3.0-18_amd64.deb ... Unpacking libatomic1:amd64 (6.3.0-18) ... Selecting previously unselected package libnuma1:amd64. Preparing to unpack .../2-libnuma1_2.0.11-2.1_amd64.deb ... Unpacking libnuma1:amd64 (2.0.11-2.1) ... Selecting previously unselected package mysql-community-client. Preparing to unpack .../3-mysql-community-client_5.7.18-1debian9_amd64.deb ... Unpacking mysql-community-client (5.7.18-1debian9) ... Selecting previously unselected package mysql-client. Preparing to unpack .../4-mysql-client_5.7.18-1debian9_amd64.deb ... Unpacking mysql-client (5.7.18-1debian9) ... Selecting previously unselected package libmecab2:amd64. Preparing to unpack .../5-libmecab2_0.996-3.1_amd64.deb ... Unpacking libmecab2:amd64 (0.996-3.1) ... Selecting previously unselected package mysql-community-server. Preparing to unpack .../6-mysql-community-server_5.7.18-1debian9_amd64.deb ... Unpacking mysql-community-server (5.7.18-1debian9) ... Selecting previously unselected package mysql-server. Preparing to unpack .../7-mysql-server_5.7.18-1debian9_amd64.deb ... Unpacking mysql-server (5.7.18-1debian9) ... Setting up libatomic1:amd64 (6.3.0-18) ... Setting up libnuma1:amd64 (2.0.11-2.1) ... Setting up libmecab2:amd64 (0.996-3.1) ... Processing triggers for libc-bin (2.24-11+deb9u1) ... Setting up libaio1:amd64 (0.3.110-3) ... Processing triggers for systemd (232-25) ... Processing triggers for man-db (2.7.6.1-2) ... Setting up mysql-community-client (5.7.18-1debian9) ... Setting up mysql-client (5.7.18-1debian9) ... Setting up mysql-community-server (5.7.18-1debian9) ... Setting up mysql-server (5.7.18-1debian9) ... Processing triggers for libc-bin (2.24-11+deb9u1) ...
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.
Start, stop and manage your server
These MySQL packages initialize and start MySQL server by default:
# systemctl status mysql ● mysql.service - MySQL Community Server Loaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset: Active: active (running) since Sun 2017-06-25 12:16:50 PDT; 31min ago Process: 4399 ExecStart=/usr/sbin/mysqld --daemonize --pid-file=/var/run/my Process: 4362 ExecStartPre=/usr/share/mysql/mysql-systemd-start pre (code=e Main PID: 4401 (mysqld) Tasks: 27 (limit: 4915) CGroup: /system.slice/mysql.service └─4401 /usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mys Jun 25 12:16:50 debian mysqld[4399]: 2017-06-25T19:16:50.342805Z 0 [Note] IPv Jun 25 12:16:50 debian mysqld[4399]: 2017-06-25T19:16:50.345596Z 0 [Note] - Jun 25 12:16:50 debian mysqld[4399]: 2017-06-25T19:16:50.348320Z 0 [Note] Ser Jun 25 12:16:50 debian mysqld[4399]: 2017-06-25T19:16:50.421804Z 0 [Note] Eve Jun 25 12:16:50 debian mysqld[4399]: 2017-06-25T19:16:50.426584Z 0 [Note] /us Jun 25 12:16:50 debian mysqld[4399]: Version: '5.7.18' socket: /var/run/mysq Jun 25 12:16:50 debian mysqld[4399]: 2017-06-25T19:16:50.430667Z 0 [Note] Exe Jun 25 12:16:50 debian mysqld[4399]: 2017-06-25T19:16:50.430739Z 0 [Note] Beg Jun 25 12:16:50 debian mysqld[4399]: 2017-06-25T19:16:50.531384Z 0 [Note] End Jun 25 12:16:50 debian systemd[1]: Started MySQL Community Server
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 backwardsinit.d
compatibility- it is not the case anymore. However, execution of/etc/init.d/mysql
will be captured and converted transparently into an equivalentsystemctl
command. But get accustomed to say goodbye to the horrible mysqld_safe script and its options (but also its vulnerabilities).# systemctl restart mysql # systemctl reload mysql Failed to reload mysql.service: Job type reload is not applicable for unit mysql.service. See system logs and 'systemctl status mysql.service' for details. # systemctl status mysql ● mysql.service - MySQL Community Server Loaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset: Active: active (running) since Sun 2017-06-25 12:55:43 PDT; 18s ago Process: 4522 ExecStart=/usr/sbin/mysqld --daemonize --pid-file=/var/run/my Process: 4485 ExecStartPre=/usr/share/mysql/mysql-systemd-start pre (code=e Main PID: 4524 (mysqld) Tasks: 27 (limit: 4915) CGroup: /system.slice/mysql.service └─4524 /usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mys Jun 25 12:55:43 debian mysqld[4522]: 2017-06-25T19:55:43.670560Z 0 [Note] IPv Jun 25 12:55:43 debian mysqld[4522]: 2017-06-25T19:55:43.673504Z 0 [Note] - Jun 25 12:55:43 debian mysqld[4522]: 2017-06-25T19:55:43.674863Z 0 [Note] Ser Jun 25 12:55:43 debian mysqld[4522]: 2017-06-25T19:55:43.750799Z 0 [Note] Eve Jun 25 12:55:43 debian mysqld[4522]: 2017-06-25T19:55:43.755752Z 0 [Note] /us Jun 25 12:55:43 debian mysqld[4522]: Version: '5.7.18' socket: /var/run/mysq Jun 25 12:55:43 debian mysqld[4522]: 2017-06-25T19:55:43.755892Z 0 [Note] Exe Jun 25 12:55:43 debian mysqld[4522]: 2017-06-25T19:55:43.755929Z 0 [Note] Beg Jun 25 12:55:43 debian mysqld[4522]: 2017-06-25T19:55:43.863316Z 0 [Note] End Jun 25 12:55:43 debian systemd[1]: Started MySQL Community Server. # journalctl -u mysql Jun 25 12:55:41 debian systemd[1]: Stopped MySQL Community Server. Jun 25 12:55:41 debian systemd[1]: Starting MySQL Community Server... Jun 25 12:55:43 debian mysqld[4522]: 2017-06-25T19:55:43.028273Z 0 [Warning] Jun 25 12:55:43 debian mysqld[4522]: 2017-06-25T19:55:43.038562Z 0 [Note] /us Jun 25 12:55:43 debian mysqld[4522]: 2017-06-25T19:55:43.076552Z 0 [Note] Inn Jun 25 12:55:43 debian mysqld[4522]: 2017-06-25T19:55:43.080224Z 0 [Note] Inn Jun 25 12:55:43 debian mysqld[4522]: 2017-06-25T19:55:43.080428Z 0 [Note] Inn Jun 25 12:55:43 debian mysqld[4522]: 2017-06-25T19:55:43.080508Z 0 [Note] Inn Jun 25 12:55:43 debian mysqld[4522]: 2017-06-25T19:55:43.080651Z 0 [Note] Inn Jun 25 12:55:43 debian mysqld[4522]: 2017-06-25T19:55:43.080739Z 0 [Note] Inn Jun 25 12:55:43 debian mysqld[4522]: 2017-06-25T19:55:43.094601Z 0 [Note] Inn Jun 25 12:55:43 debian mysqld[4522]: 2017-06-25T19:55:43.096806Z 0 [Note] Inn Jun 25 12:55:43 debian mysqld[4522]: 2017-06-25T19:55:43.116165Z 0 [Note] Inn Jun 25 12:55:43 debian mysqld[4522]: 2017-06-25T19:55:43.201413Z 0 [Note] Inn Jun 25 12:55:43 debian mysqld[4522]: 2017-06-25T19:55:43.215069Z 0 [Note] Inn Jun 25 12:55:43 debian mysqld[4522]: 2017-06-25T19:55:43.241133Z 0 [Note] Inn Jun 25 12:55:43 debian mysqld[4522]: 2017-06-25T19:55:43.325375Z 0 [Note] Inn Jun 25 12:55:43 debian mysqld[4522]: 2017-06-25T19:55:43.329688Z 0 [Note] Inn Jun 25 12:55:43 debian mysqld[4522]: 2017-06-25T19:55:43.484928Z 0 [Note] Inn Jun 25 12:55:43 debian mysqld[4522]: 2017-06-25T19:55:43.496504Z 0 [Note] Inn Jun 25 12:55:43 debian mysqld[4522]: 2017-06-25T19:55:43.499790Z 0 [Note] Inn Jun 25 12:55:43 debian mysqld[4522]: 2017-06-25T19:55:43.506852Z 0 [Note] Inn Jun 25 12:55:43 debian mysqld[4522]: 2017-06-25T19:55:43.563491Z 0 [Note] Inn Jun 25 12:55:43 debian mysqld[4522]: 2017-06-25T19:55:43.570659Z 0 [Note] Inn Jun 25 12:55:43 debian mysqld[4522]: 2017-06-25T19:55:43.573444Z 0 [Note] Plu Jun 25 12:55:43 debian mysqld[4522]: 2017-06-25T19:55:43.603637Z 0 [Note] Inn Jun 25 12:55:43 debian mysqld[4522]: 2017-06-25T19:55:43.637102Z 0 [Note] Fou Jun 25 12:55:43 debian mysqld[4522]: 2017-06-25T19:55:43.646241Z 0 [Warning] Jun 25 12:55:43 debian mysqld[4522]: 2017-06-25T19:55:43.666576Z 0 [Note] Ser Jun 25 12:55:43 debian mysqld[4522]: 2017-06-25T19:55:43.670560Z 0 [Note] IPv Jun 25 12:55:43 debian mysqld[4522]: 2017-06-25T19:55:43.673504Z 0 [Note] - Jun 25 12:55:43 debian mysqld[4522]: 2017-06-25T19:55:43.674863Z 0 [Note] Ser Jun 25 12:55:43 debian mysqld[4522]: 2017-06-25T19:55:43.750799Z 0 [Note] Eve Jun 25 12:55:43 debian mysqld[4522]: 2017-06-25T19:55:43.755752Z 0 [Note] /us Jun 25 12:55:43 debian mysqld[4522]: Version: '5.7.18' socket: /var/run/mysq Jun 25 12:55:43 debian mysqld[4522]: 2017-06-25T19:55:43.755892Z 0 [Note] Exe Jun 25 12:55:43 debian mysqld[4522]: 2017-06-25T19:55:43.755929Z 0 [Note] Beg Jun 25 12:55:43 debian mysqld[4522]: 2017-06-25T19:55:43.863316Z 0 [Note] End Jun 25 12:55:43 debian systemd[1]: Started MySQL Community Server.
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:
# mysql -u root Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 3 Server version: 5.7.18 MySQL Community Server (GPL) Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql> SELECT current_user(); +----------------+ | current_user() | +----------------+ | root@localhost | +----------------+ 1 row in set (0.00 sec)
The default configuration binds the server to 127.0.0.1, 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.
The wget command complains about the certificate to download the GPG key. Just change to:
wget –no-check-certificate -O /tmp/RPM-GPG-KEY-mysql https://repo.mysql.com/RPM-GPG-KEY-mysql
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.
Yeah, I’m not saying this is a correction. It’s just a workaround in case of that.
Error->
mysql-server : mysql-community-server (= 5.7.18-1debian9) not installed
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.
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
hi, I tried installing mysql on my raspberry pi this way, but when I run apt update it gives me this:
Hit:1 http://repo.mysql.com/apt/debian stretch InRelease
Hit:2 http://mirrordirector.raspbian.org/raspbian stretch InRelease
Hit:3 http://archive.raspberrypi.org/debian 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 ‘http://repo.mysql.com/apt/debian stretch InRelease’ doesn’t support architecture ‘armhf’
N: Skipping acquire of configured file ‘mysql-5.7/binary-armhf/Packages’ as repository ‘http://repo.mysql.com/apt/debian stretch InRelease’ doesn’t support architecture ‘armhf’
N: Skipping acquire of configured file ‘mysql-tools/binary-armhf/Packages’ as repository ‘http://repo.mysql.com/apt/debian stretch InRelease’ doesn’t support architecture ‘armhf’
any suggestions?
Hi, I doubt Oracle provides precompiled binaries for ARM in .deb format (MariaDB does not offer them either).
If you cannot use MariaDB from Debian, your best option is to cross-compile mysql (it is much easier than it could seem, this is how to do it on Fedora: https://www.percona.com/blog/2013/02/25/percona-server-on-the-raspberry-pi-your-own-database-server-for-under-80/ ) or use the Ubuntu packages: https://launchpad.net/ubuntu/xenial/armhf/mysql-server-5.7
Yes, swap “stretch” with “raspberry” (or what ever debian version you are on).
Help: in mysql -u root
ERROR 1524 (HY000): Plugin ‘unix_socket’ is not loaded
Gracia me fue de utilidad!
You’re amazing. Thank’s.
This is exactly what i needed! thanks!
Great article! Was able to install mysql-server on jessie w/o a hitch following these instructions!
followed all steps ..
etering: sudo systemctl status mysql
● MariaDB.service – MySQL Community Server
instead of Mysql.service
Check the repository installation steps for errors- some steps may have failed for you.