CentOS 7 is a free and open source operating system based on Red Hat Enterprise Linux 7. MySQL is a free open source database management system that is widely used in various industries, including the Internet, e-commerce, telecommunications, banking, finance, government, etc. Installing MySQL is a basic skill for Linux system administrators. This article will introduce how to install MySQL on CentOS 7.
In CentOS 7, we can install MySQL through the yum package manager and enter the following command in the terminal:
sudo yum install mysql-server mysql
This will automatically install the MySQL service and MySQL client on your CentOS 7 system.
After the installation is complete, we need to start the MySQL service, enter the following command:
sudo systemctl start mysqld
This will start the MySQL service and will It is set to start randomly.
After the MySQL installation is complete, we need to perform some basic configuration on it so that it can work properly. Execute the following command:
sudo mysql_secure_installation
This is the MySQL secure installation wizard. It will prompt you to perform the following operations:
When setting the root password, you need to enter a strong password , and write it and store it in a safe place.
After installing and configuring MySQL, you can log in to MySQL using the following command:
mysql -u root -p
After entering the root password, you can log in MySQL and start managing and using it.
In a production environment, security is crucial, and we can ensure data security by setting different permissions for different users. The following are the basic commands on how to manage MySQL permissions:
GRANT SELECT,INSERT,UPDATE,DELETE ON mydb.* TO '<username>'@'localhost' IDENTIFIED BY '<password>'; FLUSH PRIVILEGES;
The above commands will set SELECT, INSERT, UPDATE, and DELETE permissions for the database specified by the user.
To protect your MySQL server, you should take appropriate steps to restrict access to it. It is recommended to use a firewall to restrict access to the MySQL server. You can use the following commands to allow remote access, and specify a specific IP address:
sudo firewall-cmd --zone=public --add-service=mysql --permanent sudo firewall-cmd --zone=public --add-rich-rule 'rule family="ipv4" source address="<ip address>" service name="mysql" accept' --permanent sudo firewall-cmd --reload
The first command adds the port of this server (3306), the second command allows specific IP access, and the third command restarts Firewall.
In this article, we introduced how to install MySQL on CentOS 7 and performed some basic configurations on it. We also covered how to use different permission settings to ensure the security of your data and how to restrict access to your MySQL server. If you are a Linux system administrator, these are essential skills.
The above is the detailed content of centos 7 mysql installation. For more information, please follow other related articles on the PHP Chinese website!