CentOS 7 is a widely used server operating system. When using servers for website and application development, you often need to use a database to store and manage data. MySQL is one of the most widely used relational database management systems currently. In this article, we will learn how to install and configure MySQL on CentOS 7 system.
Before starting to install MySQL, we first need to update and upgrade the system.
Command line input:
sudo yum update
This process will take some time, depending on the processing power of your server and the number of packages on your server. Once the update is complete, you can proceed with installing MySQL.
On CentOS 7 systems, MySQL can be installed through the yum package manager.
Command line input:
sudo yum install mysql-server
This will install MySQL and other necessary software packages. After the installation is complete, you can check whether the MySQL server is started.
Command line input:
systemctl status mysqld
If the MySQL server has been started, the word "active (running)" will be displayed in the terminal. If MySQL is not started, you can start it manually using the following command:
Command line input:
sudo systemctl start mysqld
After installing MySQL, we Some configuration is required. First, we need to set a password for the root user.
Command line input:
sudo mysql_secure_installation
Then enter the root mysql password to enter the MySQL security configuration wizard. Please note that if you have just completed the installation, the root user does not have a password set by default. The Security Configuration Wizard prompts you to enter some options and set a root password. It is recommended to set a strong password. After completing the guide, you have set a password for the root user and are more secure.
To connect to MySQL, you need to use the following command:
Command line input:
mysql -u root -p
This will You are prompted for the password for the MySQL administrator (root). After successfully entering the password, you will be connected to the MySQL server and can start managing the database.
If you need to create a new MySQL user, you can do it with the following command. For example, if you want to create a user "myuser" with a password "mypassword", use the following statement:
Command line input:
CREATE USER 'myuser'@'localhost' IDENTIFIED BY 'mypassword';
Note that if you are running the MySQL server locally, then You can use "localhost" as the hostname. If you wish to allow remote connections, you can change the hostname to the server's external IP address.
To create a MySQL database, use the following command:
Command line input:
CREATE DATABASE mydatabase;
In MySQL, to perform any operation, the user must have the corresponding permissions. To assign permissions to a new user, use the following command:
Command line input:
GRANT ALL PRIVILEGES ON mydatabase.* TO 'myuser'@'localhost';
This will give user "myuser" all permissions to use the "mydatabase" database on the local computer.
During this period, you will learn how to install and configure MySQL server on CentOS 7 system. MySQL can be used to develop websites and applications and store large amounts of data. Using MySQL, you can store and manage data and also establish relationships between data tables. Just follow the simple steps above and you can set up a MySQL server on CentOS 7 and start storing data.
The above is the detailed content of centos 7 install mysql. For more information, please follow other related articles on the PHP Chinese website!