Step-by-Step Guide- How to Install MySQL on Ubuntu in Minutes
How to Install MySQL in Ubuntu
Installing MySQL on Ubuntu is a straightforward process that can be completed in a few simple steps. MySQL is a popular open-source relational database management system, widely used for web applications and other database-driven projects. In this article, we will guide you through the process of installing MySQL on an Ubuntu server or desktop.
Prerequisites
Before you begin the installation, make sure you meet the following prerequisites:
1. A Ubuntu server or desktop with internet access.
2. sudo privileges to install packages.
3. A terminal or SSH access to your Ubuntu system.
Step 1: Update Your System
The first step is to update your Ubuntu system to ensure you have the latest packages and dependencies. Open your terminal and run the following command:
“`bash
sudo apt update
sudo apt upgrade
“`
Step 2: Install MySQL Server
Now, you can install the MySQL server package on your Ubuntu system. Use the following command to install MySQL:
“`bash
sudo apt install mysql-server
“`
This command will fetch the latest MySQL server package from the Ubuntu repositories and install it on your system. The installation process may take a few minutes.
Step 3: Secure Your MySQL Installation
After the installation is complete, it is essential to secure your MySQL installation. You can do this by running the `mysql_secure_installation` script, which will guide you through a series of security questions. Here are the steps to follow:
1. Run the following command:
“`bash
sudo mysql_secure_installation
“`
2. Enter ‘y’ when prompted to remove anonymous users. This will remove the default anonymous user account.
3. Enter ‘y’ when asked to disallow root login remotely. This will prevent the root user from logging in from a remote location.
4. Enter ‘y’ when prompted to remove the test database and access to it.
5. Set a strong password for the root user.
6. Re-enter the password for confirmation.
Step 4: Verify MySQL Installation
To verify that MySQL is installed and running correctly, use the following command:
“`bash
sudo systemctl status mysql
“`
If the MySQL service is running, you should see an output similar to this:
“`
mysql.service – MySQL Community Server
Loaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset: enabled)
Active: active (running) since Mon 2023-04-10 12:34:56 UTC; 1min 34s ago
Docs: man:mysqld(8)
Main PID: 12345 (mysqld)
CGroup: /system.slice/mysql.service
└─12345 /usr/sbin/mysqld –basedir=/usr –datadir=/var/lib/mysql –plugin-dir=/usr/lib/mysql/plugin –socket=/var/run/mysqld/mysqld.sock –pid-file=/var/run/mysqld/mysqld.pid
Apr 10 12:34:56 your_server_ip_address systemd[1]: Starting MySQL Community Server…
Apr 10 12:34:56 your_server_ip_address systemd[1]: Started MySQL Community Server.
“`
Step 5: Access MySQL
To access the MySQL server, you can use the `mysql` command-line client. Run the following command to start the MySQL client:
“`bash
mysql -u root -p
“`
Enter the root password you set during the `mysql_secure_installation` script. You should now be logged in to the MySQL server and can start managing your databases.
Conclusion
Congratulations! You have successfully installed MySQL on your Ubuntu system. Now you can start using MySQL to create, manage, and store your data. Remember to regularly update your MySQL server and apply security patches to keep your database safe and secure.