How to Install MySQL 8.4 in Debian 12 - Complete Guide
In this guide we will see how to install MySQL 8.4 in Debian 12 Bookworm with apt, the default package manager
It is very common in our Linux Support, being the basis for LAMP (Linux, Apache, MySQL, PHP), LEMP (NginX) stacks and several others, needed for Web App, CMS and e-commerce
Official MySQL Repository Configuration
As a first step, to install MySQL 8.4 in Debian 12 Bookworm, we download the official MySQL repository configuration package
sudo apt update && sudo apt install wget
sudo wget https://dev.mysql.com/get/mysql-apt-config_0.8.32-1_all.deb
Let's install the downloaded package
sudo apt install ./mysql-apt-config_0.8.32-1_all.deb
During configuration we can select the desired version by displaying one of these screens
│ Which MySQL product do you wish to configure? │
│ │
│ MySQL Server & Cluster (Currently selected: mysql-8.4-lts) │
│ MySQL Connectors (Currently selected: Enabled) │
Configuring mysql-apt-config
----------------------------
The MySQL APT Repository features MySQL Server along with a variety of components. You may select the desired
products to install and update from the official MySQL Repository, and also select the associated version series.
Select "Ok" to save the configuration, and then execute "apt update" to load the selected package list. This
configuration can be updated later, depending on your needs.
MySQL Server & Cluster (Currently selected: mysql-8.4-lts) 3. Ok
MySQL Connectors (Currently selected: Enabled)
Which MySQL product do you wish to configure? 3
If you prefer MySQL 8.0 change the selection to mysql-8.0
and instead follow our guide "Installing MySQL 8.0 in Debian 12 Bookworm"
Installing MySQL 8.4 in Debian 12
Let's update the list of available packages
sudo apt update
We will vote new lines containing the new MySQL 8.4 repository for Debian 12 Bookworm
Get:5 http://repo.mysql.com/apt/debian bookworm/mysql-8.4-lts Sources [951 B]
Get:6 http://repo.mysql.com/apt/debian bookworm/mysql-apt-config amd64 Packages [566 B]
Get:7 http://repo.mysql.com/apt/debian bookworm/mysql-8.4-lts amd64 Packages [16.9 kB]
Get:8 http://repo.mysql.com/apt/debian bookworm/mysql-tools amd64 Packages [4129 B]
We proceed to install MySQL with this command
sudo apt install mysql-server
The process will prompt us whether to enter a password, in this case I left it blank, so authentication will be via Socket
, only locally. We will configure it later
Check MySQL status and restart
We managed to Install MySQL 8.4 in Debian 12 Bookworm. The server should be up and running already, let's check if the process is active
sudo service mysql status
In case it is not active we can restart MySQL and repeat the check
sudo service mysql restart
* Stopping MySQL database server mysqld [ OK ]. * Starting MySQL database server mysqld [ OK ]
Let's check the default port of MySQL, the 3306 TCP, which should be listening at this point
sudo apt install net-tools
sudo netstat -tnplu |grep 3306
The command should return the following output, showing port 3306 listening locally
tcp 0 0 127.0.0.1:3306 0.0.0:* LISTEN -.
tcp6 0 0 :::33060 :::* LISTEN -
Configure MySQL 8.4
The server is up, for a new installation the configurations used are the default ones, security is poor, at this point it is recommended to run the MySQL configuration script to set authentications and remove anonymous logins
sudo mysql_secure_installation
The script will guide us in configuring the server security options
First we enable password control for users, and we select strong passwords, with dictionary lookup of common passwords
Securing the MySQL server deployment.
Connecting to MySQL using a blank password.
VALIDATE PASSWORD COMPONENT can be used to test passwords
and improve security. It checks the strength of passwords
and allows the users to set only those passwords which are
secure enough. Would you like to setup VALIDATE PASSWORD component?
Press y|Y for Yes, any other key for No: Y
There are three levels of password validation policy:
LOW Length >= 8
MEDIUM Length >= 8, numeric, mixed case, and special characters
STRONG Length >= 8, numeric, mixed case, special characters and dictionary file
Please enter 0 = LOW, 1 = MEDIUM and 2 = STRONG: 2
Please set the password for root here.
Skipping password set for root as authentication with auth_socket is used by default.
If you would like to use password authentication instead, this can be done with the "ALTER_USER" command.
See https://dev.mysql.com/doc/refman/8.4/en/alter-user.html#alter-user-password-management for more information.
Remove anonymous users, to increase security
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? (Press y|Y for Yes, any other key for No) : Y
Configure local user authentication root
, which will be via socket, only on the local machine
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? (Press y|Y for Yes, any other key for No) : Y
Disallow test databases
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? (Press y|Y for Yes, any other key for No) : Y
We reload the privilege tables, so that our changes will take effect immediately.
Reloading the privilege tables will ensure that all changes
made so far will take effect immediately.
Reload privilege tables now? (Press y|Y for Yes, any other key for No) :
Console access to MySQL
We have finished Installing MySQL 8.4 in Debian 12 Bookworm. We can log in with the user root
from the console of our server, and for example list the databases present
sudo mysql -u root
Logging in to the database, from MySQL 8.4 you may see an error, due to a missing plugin:
ERROR 1524 (HY000): Plugin 'mysql_native_password' is not loaded
MySQL 8.4 and above implement
mysql_native_password
, if you display this error, follow our guide to enable mysql_native_password authentication plugin
Having done the to MySQL list the databases present
show databases;
+--------------------+
| Databases |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
+--------------------+
4 rows in set (0.00 sec)
The output shows us the databases present, we managed to install MySQL in Debian 12 Bookworm, we can use with the usual syntax our MySQL, connect ne our Web App and CMS
MySQL root user password
To access remotely it will be necessary to set the root
password of MySQL. We can use this command, but we recommend using a "strong" password, with numbers, upper and lower case, and special characters.
ALTER USER 'root'@'localhost' IDENTIFIED BY 'LA_MIA_PASSWORD';
Accessing remote MySQL
To access a remote MySQL it is recommended to use an SSH tunnel by redirecting the remote 3306
port of our server, which only listens in localhost
, to our local 33006
port
ssh root@IP-o-DNS -L 33006:localhost:3306
Thanks to the tunnel we could connect directly to our port 33006 in localhost
with the root
credentials created earlier
Login with MySQL Workbench
MySQL Workbench is a great tool for MySQL DBAs and Operation, allowing you to create DBs, manage server configuration, administer users, make backups and more, and it already incorporates the SSH tunnel described above
- We create a new connection
- We select "Standard TCP/IP over SSH"
- We enter the SSH configurations for our server of
- SSH Host name
- SSH User name
- Password or SSH key
- The MySQL Database configurations
- Host name
- Server Port
- Username
- Password
- We test the connection
Are you looking for professional support?
Trust one of our Linux Consultant, 30' analysis of your system for Free!