In the modern Internet era, the role of the database is self-evident. It is the cornerstone of a website or application. Among them, MySQL, as a free, open source, reliable, fast and efficient database management system, is widely used in all walks of life on the Internet. This article will introduce how to install MySQL database on Linux system.
Step 1. Prepare the environment before installation
Before starting the installation, we need to check whether MySQL has been installed in the system. Enter the following command in the terminal:
mysql --version
If MySQL has been installed on the system, the MySQL version information will be output.
If you have confirmed that MySQL is not installed, you need to download the MySQL software package first. You can go to the MySQL official website (https://dev.mysql.com/downloads/mysql/) to download the corresponding version. This time I am using MySQL version 8.0.
Step 2. Install MySQL
First, we need to use the terminal to log in to the root account. Then, execute the following command:
sudo apt-get update
This command is to update your system packages.
Next, you need to execute the following command to install MySQL:
sudo apt-get install mysql-server
During the installation process, the system will prompt you to enter the MySQL root account password. Please note that this password needs to be kept secret as it is the credential used to connect to the database.
After the installation is complete, run the following command to start the MySQL service:
sudo service mysql start
At this time, the MySQL service is running normally.
Step 3. Configure MySQL
After installing MySQL, we need to perform some configurations. First, we need to set a new root account password for MySQL to ensure security. Run the following command in the terminal:
sudo mysql_secure_installation
Then, follow the terminal prompts for the next step, such as asking you to set a new root password, confirm deletion of anonymous users, etc.
Step 4. Connect to MySQL
Now, MySQL has been installed and configured correctly. Next you need to test whether you can connect to the MySQL server.
Enter the following command in the terminal to connect to MySQL:
mysql -u root –p
This command will prompt you for your password. Here, we enter the root account password we set previously.
If you successfully log in to MySQL, it means that we have successfully installed the MySQL database. If any errors occur or login fails, please make sure your root account and password are correct.
Step 5. Operate MySQL in the terminal
The MySQL operation commands executed in the terminal are the same as using the MySQL client. Here are some of the most common MySQL terminal commands.
Summary
The article on how to install MySQL on a Linux system has been completed. In actual work, MySQL database, as an excellent open source database management system, is favored by more and more enterprises and developers, and upgrading and managing MySQL has also become a skill requirement. I hope this article can help readers who need to learn MySQL.
The above is the detailed content of Linux database mysql installation. For more information, please follow other related articles on the PHP Chinese website!