Install MySQL on Ubuntu
MySQL is one of the most popular open-source database management systems. Installing MySQL on Ubuntu is straightforward, whether setting up a database for a web application or just exploring the world of databases. This guide walks you through the process.
Step 1: Update Your System
Before installing MySQL, it's important to ensure your system is up to date.
- Open your terminal.
- Run the following commands to update and upgrade the package list:
Step 2: Install MySQL
Ubuntu includes MySQL in its default package repositories.
- To install MySQL, run:
- Confirm the installation by typing
Y
when prompted.
Step 3: Start and Enable MySQL Service
After installation, start the MySQL service and ensure it runs automatically on system boot.
- Start the MySQL service:
- Enable it to start at boot:
Step 4: Secure the Installation
MySQL includes a security script to help configure settings for enhanced security.
- Run the security script:
- Follow the prompts to:
- Set a root password.
- Remove anonymous users.
- Disallow remote root logins.
- Remove test databases.
- Reload privilege tables.
Step 5: Test the Installation
Ensure that MySQL is installed and running properly.
Check the status of the MySQL service:
If it says "active (running)," MySQL is running.
Log in to MySQL as the root user:
Enter the password you set during the secure installation.
After logging in, test with a simple query:
Exit MySQL by typing
exit
.
Optional: Install MySQL Workbench
If you prefer a graphical interface to manage your databases, consider installing MySQL Workbench.
- Install it using the command:
Final Notes
Congratulations! You now have MySQL installed and ready to use on your Ubuntu system. From here, you can create databases, manage users, and integrate MySQL with your applications.
If you have any questions or run into issues, please leave a comment below!