Installing MySQL on Linux
Introduction
MySQL is an open-source relational database management system. It is widely used in web applications and is known for its reliability, performance, and ease of use. This tutorial will guide you through the process of installing MySQL on a Linux system.
Step 1: Update the Package Index
Before installing MySQL, it's essential to update the package index to ensure that you get the latest version of the software. Open a terminal and run the following command:
sudo apt update
This command updates the package index to reflect the latest available packages.
Step 2: Install MySQL Server
After updating the package index, you can install MySQL by running the following command:
sudo apt install mysql-server
This command installs the MySQL server package and its dependencies.
Step 3: Secure the MySQL Installation
Once the installation is complete, it's crucial to secure the MySQL installation. Run the following command to start the security script:
sudo mysql_secure_installation
You will be prompted to set up various security options, such as setting a root password, removing anonymous users, disallowing remote root login, and removing the test database.
Enter current password for root (enter for none): <press Enter>
Set root password? [Y/n] Y
New password: <your_password>
Re-enter new password: <your_password>
Remove anonymous users? [Y/n] Y
Disallow root login remotely? [Y/n] Y
Remove test database and access to it? [Y/n] Y
Reload privilege tables now? [Y/n] Y
Step 4: Verify MySQL Service
After securing the installation, verify that the MySQL service is running using the following command:
sudo systemctl status mysql
● mysql.service - MySQL Community Server
Loaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset: enabled)
Active: active (running) since ...
...
The output should indicate that the MySQL service is active and running.
Step 5: Log in to MySQL
To log in to the MySQL server as the root user, use the following command:
sudo mysql -u root -p
After entering the command, you will be prompted to enter the root password you set during the secure installation process.
Enter password: <your_password>
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is ...
Server version: ...
...
You are now logged in to the MySQL shell and can start managing your databases.
Conclusion
Congratulations! You have successfully installed MySQL on your Linux system. You can now create databases, manage users, and run queries using MySQL. For more advanced configurations and usage, refer to the official MySQL documentation.