
MySQL is an open-source relational database management system (RDBMS) based on the Structured Query Language (SQL). It allows users to store, manage, and retrieve data efficiently, making it a popular choice for web applications, data storage, and complex data management. Installing MySQL on Ubuntu 24.04 provides a stable Linux environment for building, securing, and managing databases effectively. Whether you're a developer, database administrator, or system administrator, understanding the installation process is crucial for setting up a reliable and scalable database solution.
In this article, we'll walk you through the steps to install MySQL on Ubuntu 24.04, covering everything from updating your system to configuring MySQL for secure access. Whether you're setting up a new server or configuring a development environment, this guide will help you get your MySQL database up and running efficiently. If you're also interested in database management on other Linux distributions, you can check out our article on installing MySQL on Debian 12 for a similar approach.
Before you begin:
Deploy an Ubuntu 24.04 server instance on Vultr.
Access the server using SSH as a non-root user with sudo privileges.
MySQL is available in the default APT repositories on Ubuntu 24.04, and you can install a specific release version using PPA repositories. To install MySQL server on Ubuntu 24.04, follow the steps to update the server package index and install the latest MySQL database server version on your server.
Update the server package index.
Install the MySQL server package.
View the installed MySQL version on your server.
Output:
MySQL uses the mysql system service to control the database server processes and runtime on your Ubuntu 24.04 server. In the following steps, enable the mysql systemd service to start at boot time and verify the service status to manage the database processes on your server.
Enable MySQL to automatically start at boot time.
Output:
Start the MySQL database server.
View the MySQL server status and verify that it's running.
Output:
Securing the MySQL server is an important step when protecting databases from unauthorized user access. Privileged users such as root can access the MySQL database console by default. In the following steps, create a new MySQL root user password and disable insecure defaults to secure your database server.
Run the following command to start the MySQL secure installation script.
Follow the script prompts below to set up a new root user password, remove anonymous users, disallow remote root login, and remove test databases on your MySQL database server.
Restart the MySQL service to apply your configuration changes.
Log in to the MySQL database server as root.
Enter the root user password you set earlier when prompted.
Create a new sample MySQL database. For example, my_database.
Create a new MySQL database user with a strong password. For example, my_user and replace my_password with your desired password depending on your password strength policy.
Grant the database user my_user full privileges to your sample database my_database.
Refresh the MySQL privilege tables to apply the new user changes.
Exit the MySQL database console.
Non-privileged MySQL users have CREATE privileges on the database server by default. In the following sections, create an example database using your unprivileged sample user my_user and add new records to the database tables.
Log in to the MySQL database console using the database user my_user you created earlier.
Enter the my_user password you set earlier when prompted.
List all databases available to the MySQL user
Output:
Create another sample MySQL database. For example, bookstore_db.
Switch to the new database.
Create a new sample table with the 3 columns to store different data types.
Insert sample data into the sample_table table.
Select all table records to verify that the new table data is available.
Output:
You have installed MySQL on your Ubuntu 24.04 server and secured the database server to allow authenticated access for all valid users. MySQL integrates with modern web applications and you can either use your server as a dedicated remote database server or the database backend using a dynamic application stack such as LAMP. For more information about MySQL, visit the official documentation.
0 Comments
Be the first to comment and share your perspective with the community.