
MySQL is an open-source Relational Database Management System (RDBMS) that uses Structured Query Language (SQL) to organize, query, and manage data. It powers a wide range of applications, from content management systems and e-commerce platforms to analytics dashboards. MySQL supports features such as transactions, replication, and indexing, making it suitable for both development and production workloads.
This article explains how to install MySQL on an Ubuntu 26.04 server. It covers the database server setup, service management, security hardening through the built-in secure installation script, and basic database operations including user creation and table management.
Before you begin, you need to:
The default Ubuntu 26.04 APT repositories include the MySQL server package. The following steps refresh the package index and install the latest available MySQL version from the official repositories.
Refresh the APT package index.
Install the MySQL server package.
Confirm the installed MySQL version.
Your output should be similar to the one below:
The mysql systemd service controls the MySQL database server process. Enable the service to persist across reboots and verify that the server is running.
Enable MySQL to start automatically at boot time.
Start the MySQL server.
Verify that the MySQL service is active and running.
Your output should be similar to the one below:
A fresh MySQL installation allows the root user unrestricted console access without a password. The mysql_secure_installation script removes insecure defaults, and a separate configuration change enables the mysql_native_password authentication plugin so you can assign a password to the root account.
Run the MySQL secure installation script.
Respond to each prompt as described below to harden the server:
Open the MySQL server configuration file using a text editor such as Nano.
Add the following directive under the [mysqld] section to activate the mysql_native_password authentication plugin.
The [mysqld] section should look similar to the one below:
Save and close the file.
Restart MySQL to load the updated configuration.
Access the MySQL console as the root system user.
Assign a strong password to the root account. Replace your_strong_password with a secure password that meets your validation policy.
Reload the privilege tables to apply the password change.
Exit the MySQL console.
The MySQL command-line client provides an interface for database administration and query execution. The following steps log in as the root user, create a database, and configure a dedicated user with the necessary privileges.
Log in to the MySQL server as the root user.
The system prompts for a password. Enter the root password you set in the previous section.
Create a new database named example_db.
Create a database user named example_user with a strong password. Replace dbuser_password with your desired password.
Grant the user full privileges on the example_db database.
Grant the user permission to create new databases.
Grant the user permissions to perform read and write operations across all databases.
Reload the privilege tables to activate the new user permissions.
Exit the MySQL console.
The example_user account has the privileges required to create and manage databases independently. The following steps log in as that user, create a new database with a sample table, and populate it with test data.
Log in to the MySQL server as example_user.
Enter the example_user password when prompted.
List all databases accessible to the current user.
Your output should be similar to the one below:
Create a new database named example_demo.
Switch to the new database.
Create a table named services with columns for an auto-incrementing ID, a name, a description, and a timestamp.
Insert sample records into the services table.
Query the table to verify that the data was inserted correctly.
Your output should be similar to the one below:
Exit the MySQL console.
You have installed and secured MySQL on an Ubuntu 26.04 server, created a dedicated database user, and performed basic table operations. MySQL integrates with application stacks such as LAMP and LEMP, and supports replication for high-availability deployments. For more information, refer to the official MySQL documentation.
0 Comments
Be the first to comment and share your perspective with the community.