
MySQL is an open-source relational database management system (RDBMS) that uses Structured Query Language (SQL) to store and manage data. It is commonly used in web applications, data platforms, and software that requires structured data handling. Installing MySQL on Ubuntu 25.04 provides a stable, consistent and secure environment for database operations across various use cases.
This article explains how to install MySQL on Ubuntu 25.04, from system preparation to securing the MySQL installation. These steps are applied on whether you're setting up a fresh server or preparing a local development environment.
Before you begin, you need to:
Ubuntu 25.04 includes MySQL packages in its default APT repositories. You can install the MySQL server directly without adding any external repositories. Follow the steps below to update your system index and install the MySQL database server on your Ubuntu instance.
Update the APT's server package index.
Install the MySQL server package.
Verify that MySQL is installed and check its version.
Your output should be similar to the one below:
MySQL server runs as a systemd service named mysql, which manages its background processes and startup behavior. Follow the steps below to enable the mysql service to start at boot and verify that its status is active and running.
Enable MySQL to start automatically when the system boots.
Start the MySQL database service.
View the MySQL service status.
Your output should be similar to the one below:
Securing the MySQL server is crucial to prevent unauthorized access and protect sensitive data. By default, the root user has unrestricted access to the MySQL console. Follow the steps below to set a new root password, disable insecure defaults, and improve the overall security of your MySQL server.
Run the following command to start the MySQL secure installation script.
Follow the prompts below to secure your MySQL server by enabling password validation, enforcing strong password policies, removing anonymous users, disabling remote root access and deleting test databases.
Open the mysqld.cnf configuration file using any text editor such as nano.
Add the following directive under the [mysqld] section to enable the mysql_native_password authentication plugin.
Your [mysqld] section should look like below:
Restart MySQL to ensure the configuration changes takes effect.
Access the MySQL console as the root user.
Set a strong password for the root user.
Replace your_strong_password with a secure password that complies with your password policy.
Execute the following to refresh MySQL’s user permissions.
Exit the MySQL database console.
Follow the steps below to access your MySQL server and manage databases and users.
Log in to the MySQL server as the root user.
When prompted, enter the root password you created earlier.
Create a sample MySQL database named app_data.
Create a new MySQL user app_user with a secure password.
Replace your_secure_password with a strong password based on your password policy.
Grant the database user app_user full privileges to the app_data database.
Grant the database user app_user permission to create new databases.
Grant the database user app_user permissions to perform CRUD operations on all databases.
Reload the MySQL privilege tables to apply the new user changes.
Exit the MySQL database console.
After creating the app_user database user, you can use it to create and manage databases without root privileges. In this section, you will log in as app_user, create a new database, add a table, and populate it with sample data.
Log in to the MySQL database server as the user app_user.
Enter the password you configured for app_user when prompted.
List all databases accessible to the current user.
Your output should be similar to the one below:
Create a new database named app_demo.
Switch to the new database context.
Create a table named items to store sample data, including an auto-incrementing ID, name, description, and a timestamp.
Insert sample records into the items table.
Query the items table to verify that the data was inserted correctly.
Your output should be similar to the one below:
Exit the MySQL database console.
You have installed and secured MySQL on Ubuntu 25.04, created a dedicated database user with granular privileges, and used that user to create and manage a sample database. MySQL is a robust and scalable open-source relational database management system (RDBMS) that integrates seamlessly with modern application stacks such as LAMP and LEMP. It is also used as the database component for dynamic websites and server-side applications. To learn more about MySQL features, refer to the official MySQL documentation.
0 Comments
Be the first to comment and share your perspective with the community.