How to Manually Install and Configure MySQL on Ubuntu 24.04
This guide explains how to manually install and configure MySQL Server on Ubuntu 24.04.
The instructions in this article are based directly on the supplied MySQL Ansible playbook. Instead of using Ansible to perform the installation automatically, you will manually run the equivalent commands from the Ubuntu terminal.
Operating System: Ubuntu 24.04 LTS
Application: MySQL Server
1. What You Will Install
After completing this guide, MySQL Server will be installed and configured on your Ubuntu 24.04 server.
The configuration performed in this guide includes:
- Installing MySQL Server
- Enabling the MySQL service
- Starting the MySQL service
- Checking the MySQL service status
- Configuring the MySQL bind address
- Installing the Python MySQL dependency
- Creating a MySQL user
- Checking MySQL listening ports
- Viewing recent MySQL logs
2. Requirements
Before starting, make sure you have:
- Ubuntu 24.04 LTS installed
- Access to the Ubuntu terminal
- A user account with
sudoprivileges - An active internet connection
Check your Ubuntu version with:
lsb_release -a
Make sure the system reports Ubuntu 24.04.
3. Update the Ubuntu Package Cache
The first task in the Ansible playbook updates the APT package cache.
Run:
sudo apt update
Wait for the command to complete before continuing.
4. Install MySQL Server
The Ansible playbook installs the Ubuntu MySQL Server package.
Run:
sudo apt install -y mysql-server
Ubuntu will download and install MySQL Server and its required dependencies.
Wait for the installation to finish.
5. Enable the MySQL Service
The playbook enables the MySQL service so that MySQL can start automatically when the server starts.
Run:
sudo systemctl enable mysql
6. Start MySQL
Start the MySQL service:
sudo systemctl start mysql
7. Check MySQL Service Status
The Ansible playbook checks whether the MySQL service is active.
Run:
systemctl is-active mysql
The expected result is:
active
You can also get more detailed information with:
sudo systemctl status mysql
Look for:
Active: active (running)
Press Q to exit the status screen.
8. Configure the MySQL Bind Address
The supplied Ansible playbook changes the MySQL bind address to:
0.0.0.0
This means MySQL is configured to listen on all available network interfaces.
0.0.0.0 can make MySQL reachable from other network interfaces. Do not expose MySQL directly to the public internet unless this is specifically required and properly protected by firewall rules and authentication.Open the MySQL Configuration File
The Ansible playbook modifies the following file:
/etc/mysql/mysql.conf.d/mysqld.cnf
Open the file:
sudo nano /etc/mysql/mysql.conf.d/mysqld.cnf
Find the Bind Address
Look for a line similar to:
bind-address = 127.0.0.1
Change it to:
bind-address = 0.0.0.0
If the file already contains a bind-address line, replace its value with 0.0.0.0.
Save the file:
- Press CTRL + O
- Press ENTER
- Press CTRL + X
9. Restart MySQL After Changing the Configuration
The Ansible playbook automatically restarts MySQL when the bind address configuration changes.
Manually restart MySQL:
sudo systemctl restart mysql
Check the service again:
sudo systemctl status mysql
Make sure it shows:
Active: active (running)
10. Install the Python MySQL Dependency
The Ansible playbook installs python3-pymysql.
This package allows Python applications and automation tools to communicate with MySQL.
Install it with:
sudo apt install -y python3-pymysql
11. Create the MySQL User
The supplied Ansible playbook creates a MySQL user with the following details:
| Setting | Value |
|---|---|
| Username | mysqluser |
| Password in playbook | StrongPassword123! |
| Host | localhost |
| Permissions | ALL, GRANT |
Create the User
First open the MySQL command-line client as the root MySQL user:
sudo mysql
You should see a prompt similar to:
mysql>
Create the user:
CREATE USER 'mysqluser'@'localhost' IDENTIFIED BY 'YOUR_STRONG_PASSWORD';
Replace YOUR_STRONG_PASSWORD with your own password.
For example:
CREATE USER 'mysqluser'@'localhost' IDENTIFIED BY 'YourStrongPasswordHere';
12. Give the MySQL User Permissions
The Ansible playbook gives the user:
.*:ALL,GRANT
In MySQL, the equivalent manual command is to grant privileges.
Run the following inside the MySQL prompt:
GRANT ALL PRIVILEGES ON *.* TO 'mysqluser'@'localhost' WITH GRANT OPTION;
Apply the privilege changes:
FLUSH PRIVILEGES;
You can check the user's permissions with:
SHOW GRANTS FOR 'mysqluser'@'localhost';
13. Exit MySQL
When you have finished creating the user, exit the MySQL command-line client:
EXIT;
You should return to the normal Ubuntu terminal.
14. Test the MySQL User
You can test whether the new MySQL user can log in.
Run:
mysql -u mysqluser -p
Enter the password you created for mysqluser.
If the login is successful, you will see:
mysql>
Test the connection:
SELECT VERSION();
Then exit:
EXIT;
15. Check MySQL Listening Ports
The Ansible playbook checks the server's listening ports using the ss command.
Run:
sudo ss -tap
You can specifically check the standard MySQL port:
sudo ss -ltnp | grep 3306
MySQL normally uses TCP port:
3306
Because the playbook changes the bind address to 0.0.0.0, MySQL should listen on the configured network interfaces.
16. Check MySQL Logs
The Ansible playbook retrieves the latest 20 MySQL service log entries.
Run:
sudo journalctl -u mysql --no-pager -n 20
This displays the most recent 20 log entries for the MySQL service.
If you need to see more logs, run:
sudo journalctl -u mysql --no-pager
17. Check MySQL Service After Configuration
After making the configuration changes, check MySQL again:
sudo systemctl status mysql
The expected result is:
Active: active (running)
You can also use:
systemctl is-active mysql
Expected output:
active
18. Check That MySQL Starts Automatically
Verify that MySQL is enabled:
systemctl is-enabled mysql
Expected output:
enabled
19. Complete MySQL Installation Verification
Run the following commands one at a time to verify the installation:
Check MySQL version
mysql --version
Check MySQL service
sudo systemctl status mysql
Check whether MySQL is active
systemctl is-active mysql
Check whether MySQL starts automatically
systemctl is-enabled mysql
Check MySQL port
sudo ss -ltnp | grep 3306
Check recent MySQL logs
sudo journalctl -u mysql --no-pager -n 20
Test MySQL login
mysql -u mysqluser -p
20. Useful MySQL Commands
Check MySQL version
mysql --version
Check MySQL service status
sudo systemctl status mysql
Start MySQL
sudo systemctl start mysql
Stop MySQL
sudo systemctl stop mysql
Restart MySQL
sudo systemctl restart mysql
Enable MySQL at startup
sudo systemctl enable mysql
Check whether MySQL is running
systemctl is-active mysql
Open MySQL as the local root account
sudo mysql
Log in as mysqluser
mysql -u mysqluser -p
Check listening ports
sudo ss -ltnp | grep 3306
View recent MySQL logs
sudo journalctl -u mysql --no-pager -n 20
21. Installation Summary
The manual installation follows the main tasks contained in the supplied MySQL Ansible playbook:
- Update the APT package cache.
- Install MySQL Server.
- Enable the MySQL service.
- Start the MySQL service.
- Check the MySQL service status.
- Configure the MySQL bind address.
- Restart MySQL after the configuration change.
- Install
python3-pymysql. - Create the
mysqluserMySQL account. - Give the user the required privileges.
- Check MySQL listening ports.
- View recent MySQL logs.
22. Final MySQL Information
| Item | Value |
|---|---|
| Application | MySQL Server |
| Operating System | Ubuntu 24.04 LTS |
| Service | mysql |
| Configuration File | /etc/mysql/mysql.conf.d/mysqld.cnf |
| Bind Address | 0.0.0.0 |
| Default MySQL Port | 3306 |
| MySQL User | mysqluser |
| MySQL User Host | localhost |
| Python MySQL Package | python3-pymysql |
MySQL Server has been installed on Ubuntu 24.04, the MySQL service has been enabled and started, the bind address has been configured, and the MySQL user has been created.
This playbook configures MySQL to bind to
0.0.0.0 and gives the created user broad privileges. If this server is exposed to a network or the internet, review your firewall rules and MySQL permissions carefully. Use strong, unique passwords and only allow trusted systems to connect to MySQL.Note: This article converts the tasks contained in the supplied MySQL Ansible playbook into manual Ubuntu terminal commands.

