MySQL is a popular open source relational database management system. It is widely used in web applications and other types of software development. In this article, we will cover the steps to install MySQL on a Linux system.
Step 1: Install MySQL
In Linux systems, MySQL can be installed in various ways, including binaries, source code, package managers, etc. In this article, we will introduce the steps to install MySQL using apt package manager in Ubuntu system.
We first need to update the apt package list on the system. Open a terminal and enter the following command:
sudo apt update
Then execute the following command to install MySQL:
sudo apt install mysql-server
During the installation process, you may be asked to set a MySQL root password. Please note that this password will be used to manage the MySQL server and database.
Step 2: Configure MySQL
After installing MySQL, we need to perform some configurations. Most importantly, we need to ensure that MySQL is only listening on localhost to prevent unauthorized remote access.
Open the MySQL configuration file and enter the following command:
sudo nano /etc/mysql/mysql.conf.d/mysqld.cnf
In the file, find the following line:
bind-address = 127.0.0.1
If you need to allow remote access, then set the parameters of this line Change to the system's public IP address or "0.0.0.0". However, we recommend allowing only local access as remote access may cause network security issues.
Step 3: Start and Stop MySQL
After configuring MySQL, we need to start the MySQL service. Execute the following command to start the service:
sudo systemctl start mysql
If you want to start the MySQL service automatically when the system starts, you can use the following command:
sudo systemctl enable mysql
To stop the MySQL service, execute the following command:
sudo systemctl stop mysql
If you no longer need the MySQL service, uninstall it using the following command:
sudo apt remove mysql-server
It is important to note that this will completely delete the MySQL program and all data and configuration files associated with it.
Conclusion
In this article, we have covered the steps to install MySQL on a Linux system. Installing and configuring MySQL is a relatively simple task, but ensuring network security is important. Before making any changes, make sure you understand the consequences of your changes.
The above is the detailed content of Install mysql under linux. For more information, please follow other related articles on the PHP Chinese website!