How to Install MySQL on Ubuntu 22.04

Installing MySQL on Ubuntu 22.04 is a straightforward process. MySQL is a widely-used open-source relational database management system that helps you manage and organize your data efficiently. Follow these steps to get MySQL up and running on your Ubuntu 22.04 system.

Step 1: Update Your System
Before installing MySQL, it’s always a good idea to update your package list to ensure you have the latest information on available packages.

sudo apt update


Step 2: Install MySQL Server
Once the package list is updated, you can install the MySQL server package.

sudo apt install mysql-server


Step 3: Check MySQL Service Status
After installation, you should check the status of the MySQL service to ensure it's running.

sudo systemctl status mysql


Step 4: Start MySQL Service
If the service is not running, you can start it with the following command:

sudo systemctl start mysql


Step 5: Secure MySQL Installation
By default, MySQL is not secure enough for production use, so it’s crucial to secure it by setting a strong password for the root user.

1. Log in to the MySQL shell as the root user:

sudo mysql -u root


2. Set a strong password for the root user:

ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'your_strong_password';


3. Apply the changes by flushing the privileges:

FLUSH PRIVILEGES;


4. Exit the MySQL shell:

exit


Step 6: Connect to MySQL
Now, you can connect to your MySQL server using the root user and the password you just set.

sudo mysql -u root -p


You will be prompted to enter the password you created earlier. Once authenticated, you’ll be inside the MySQL shell, ready to manage your databases.

Conclusion
By following these steps, you have successfully installed and secured MySQL on your Ubuntu 22.04 system. MySQL is now ready to be used for your projects, whether you're building a small application or a large-scale database-driven system.

Last update on Aug 14, 2024

Tags: mysql,ubuntu,setup

Back to Posts

Comments

No comments yet.

ForceTeach Corporation 2024