Home  >  Article  >  Database  >  centos 7 mysql installation

centos 7 mysql installation

WBOY
WBOYOriginal
2023-05-11 15:52:37752browse

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.

  1. Install MySQL

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.

  1. Start the MySQL service

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.

  1. Configuring MySQL

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:

  • Change root password
  • Delete anonymous user
  • Disable root remote login
  • Delete test database and access permissions
  • Reload MySQL security options

When setting the root password, you need to enter a strong password , and write it and store it in a safe place.

  1. Login to MySQL

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.

  1. Permission Management

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.

  1. Firewall Configuration

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.

  1. Conclusion

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn