How to Install MySQL on Ubuntu 24.04: A Comprehensive Guide
MySQL is a powerful and widely-used relational Database Management System (DBMS) that utilizes Structured Query Language (SQL) for data management. Commonly found in LAMP stacks on Linux, MySQL can also be installed independently. If you’re a Linux enthusiast or developer looking to set up MySQL on Ubuntu 24.04, you’re in the right place. This article provides a straightforward and detailed guide to help you install and configure MySQL successfully.
Step-by-Step Guide to Install MySQL on Ubuntu 24.04
Step 1: Update Your System’s Repository
Before installing any package, it’s essential to update your system’s repository. This ensures that you have access to the latest versions of software packages. Open your terminal and execute the following command:
$ sudo apt update
Step 2: Install MySQL Server
Once the repository is updated, you can install the MySQL server package. This is done by running the following command:
$ sudo apt install mysql-server
After the installation process, you need to start the MySQL service by executing:
$ sudo systemctl start mysql.service
Step 3: Configure MySQL Security Settings
It’s crucial to configure some basic security settings for MySQL after installation. Access the MySQL shell using the command below:
$ sudo mysql
Next, secure your MySQL installation by setting a password for the root user. Use the following syntax:
ALTER USER ‘root’@’localhost’ IDENTIFIED WITH mysql_native_password BY ‘your_password’;
Make sure to replace ‘your_password’ with a strong password!
After setting the password, exit the shell:
EXIT;
Step 4: Run the MySQL Security Script
MySQL provides a built-in security script that you can run to enhance the security of your database. Execute the following command:
$ sudo mysql_secure_installation
This script will walk you through various settings, including the option to remove anonymous users and limit root access. Follow the prompts to customize these settings based on your needs.
Step 5: Modify the Authentication Method
For better authentication practices, it’s often recommended to use the auth_socket plugin. Re-enter the MySQL shell:
$ sudo mysql
Then, execute the command below to alter the authentication plugin:
ALTER USER ‘root’@’localhost’ IDENTIFIED WITH auth_socket;
Step 6: Create a New MySQL User
For security and best practices, it’s advisable to create a new user instead of using the root account. Create a new user with the desired username and password using:
CREATE USER ‘username’@’localhost’ IDENTIFIED BY ‘password’;
Replace ‘username’ and ‘password’ with your chosen credentials.
After creating the user, specify their privileges. Here’s how to grant a new user rights to manage all databases:
GRANT CREATE, ALTER, INSERT, UPDATE, SELECT ON *.* TO ‘username’@’localhost’ WITH GRANT OPTION;
Flush the privileges and exit MySQL:
FLUSH PRIVILEGES;
EXIT;
Step 7: Verify User Permissions
Finally, confirm that your newly created user can access the database and has the proper permissions. First, check the MySQL service status:
$ sudo systemctl status mysql
Now, log in using the new user credentials:
$ mysql -u username -p
If you log in successfully, congratulations! You’ve installed and configured MySQL on Ubuntu 24.04 effectively.
Conclusion
MySQL is a fundamental component for many applications, especially in web development. This guide detailed the step-by-step process to install MySQL on Ubuntu 24.04, covering all the necessary configurations along the way. By following these steps, you can harness the full power of MySQL on your Linux setup, turning it into a robust data management solution.
FAQ
What is MySQL used for?
MySQL is primarily used for managing structured data in relational databases. It’s widely adopted for web applications, data warehousing, and e-commerce platforms.
Can I install MySQL without a graphical interface?
Yes, you can install MySQL entirely through the command line, making it ideal for server environments and remote installations.
What’s the difference between MySQL and other DBMS?
MySQL stands out for its high performance, reliable transaction support, and open-source nature, making it a popular choice compared to alternatives like PostgreSQL and SQLite.