How to Install MySQL on Ubuntu 24.10 Complete Guide
In this comprehensive step-by-step guide, we see how to install MySQL 8.0 on Ubuntu 24.10 via APT. MySQL is the world's most widely used open source RDBMS and a key component of the LAMP stack.
For specific details on release notes, we refer you to the Official Ubuntu Server documentation.
It is very common in our Linux Server Consulting, being the basis for LAMP (Linux, Apache, MySQL, PHP), LEMP (NginX) stacks and several others, needed for webapps, CMS and e-Commerce, let's see how to install it
Installing MySQL on Ubuntu
As the first step for installing MySQL in Ubuntu 24.10 we update the list of available packages with
sudo apt updateWe proceed to install MySQL on Ubuntu with this command
sudo apt install mysql-serverThe server should already be active, let's check if the process is active
sudo service mysql statusIn 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-toolssudo 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.0:* LISTEN -
tcp6 0 0 :::33060 :::* LISTEN -Don't leave performance to chance
A default installation is not enough for production loads. We optimize your Ubuntu stack for maximum performance.
Configure MySQL
The server is active, for a new installation the configurations used are the default ones, security is poor, at this point it is recommended to run the DBMS configuration script to set up authentications and remove anonymous logins
sudo mysql_secure_installationThe script will guide us in hardening the server. For enterprise security standards, we recommend best practices on password validation in the MySQL documentation.
First we enable password checking for users, and 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: YThere 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
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.0/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) : YWe configure local authentication of the root user, which will be done 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) : YRemove test databases, useless in production
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) : YWe 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) : Is data security your business priority?
Configuring your database is just the beginning. We implement proactive monitoring systems and advanced hardening.
Console access to MySQL
The installation is finished and we can log in with the root user from our server console, and for example list the databases present
sudo mysql -u rootshow 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 Ubuntu 24.10, we can use with the usual syntax our MySQL, connect our web apps and CMS
MySQL root password
To access remotely we will need to set the MySQL root password. 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:3306Thanks to the tunnel we could connect directly to our port 33006 in localhost or 127.0.0.1 with the root credentials created earlier
For this we can use one of these commands:
mysql -h localhost -P 33006 -u root -pmysql -h 127.0.0.1 -P 33006 -u root -pLogin with MySQL Workbench
MySQL Workbench is a great tool for Database Admin (D.B.A.) MySQL and Operation, allows you to create DBs, manage server configuration, administer users, make backups, and more, and also incorporates the SSH tunneling capability already described above
- Let's create a new connection
- Let's select Standard TCP/IP over SSH
- We enter the SSH configurations for our server of
- SSH Host name
- SSH Username
- Password or SSH key
- The MySQL Database Configurations
- Host name
- Server Port
- Username
- Password
- Let's test the connection
Is data security your business priority?
Configuring the database is just the beginning. We implement proactive monitoring systems and advanced hardening.
FAQ: Frequently asked questions about MySQL and Ubuntu
Is it better to use MySQL or MariaDB on Ubuntu 24.10?
It depends on the requirements. MariaDB is a "drop-in replacement" fork that offers excellent performance and is completely open source. MySQL 8.0 (Oracle) offers advanced enterprise features such as the Document Store (NoSQL). For mission-critical environments, we offer specific advice to choose the most suitable DBMS.
How can I enable automatic MySQL backups?
In production, don't rely on manual scripts. You should use tools such as mysqldump automated via cron or enterprise solutions such as Percona XtraBackup. A robust backup system is an integral part of our DevOps and Maintenance services.
What should I do if I get the error "Access denied for user 'root'@'localhost'"?
On Ubuntu, MySQL uses the default auth_socket plugin for root. It means you need to access the database using sudo mysql from the system terminal, without a password. If you need access via password (e.g., for phpMyAdmin), you will need to change the authentication method to ALTER USER.
Can I install MySQL on Docker containers instead of Bare Metal?
Absolutely yes. Using Docker simplifies version management and isolation. However, managing data persistence (volumes) requires attention. Find out about our support for Docker and Containerization.