centos7 install mysql with rpm for details
- 2020-05-12 06:36:16
- OfStack
For a recent project, we need to use centos as a data server, and mysql as a database, so we need to install mysql database. We haven't touched centos before, so we don't know anything about it. So we have checked a lot of information from the Internet, but we don't think it is the best way. Finally, combining the official information of mysql and the information of netizens, the installation of rpm is finally used and summarized for others to refer to.
First, open the mysql network and find "yum repository" to open the page or directly open the following link
http://dev.mysql.com/downloads/repo/yum/
, find what you need, click download, download rpm file, download house in centos, you can use the software manager installation, or you can use the command line installation
sudo rpm -Uvh 'filename'
Complete the installation.
The input
yum repolist all | grep mysql
You can view all the mysql packages corresponding to rpm. If it is the previous version installed, you need to set it up accordingly and open it
/etc/yum.repos.d/mysql-community.repo
File, set the enabled property of the corresponding version, 1 is enabled, 0 is disabled, if you install the latest version of the current, you do not need to make any Settings.
Enter the following command to start installing mysql
sudo yum install mysql-community-server
Waiting for the installation to complete, enter the following command to start the mysql service
sudo service mysqld start
When startup is complete, house can view the mysql service status
sudo service mysqld status
If version 5.7 is installed, the following actions will occur when the service starts because the data directory is empty:
Initialize server Generate the SSL certificate and key files in the data directory Install and enable the validate_password plug-in The superuser account 'root'@'localhost' is created and the superuser password is set and stored in the error log file. If you want to display it, execute the following commandsudo grep 'temporary password'/var log/mysqld log
A random password is generated and entered on the command line
mysql -uroot -p
Add the random password and log in mysql.
With the password after login to the server, it is necessary to change the password immediately, otherwise will be submitted to the following error (this local reference http: / / www cnblogs. com/ivictor/p / 5142809. html) :
mysql
>
select user();
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.
If you change it to a simple password, the following error will be reported:
mysql
>
ALTER USER USER() IDENTIFIED BY '12345678';
ERROR 1819 (HY000): Your password does not satisfy the policy requirements
This is actually related to the value of validate_password_policy.
validate_password_policy has the following values:
Policy | Tests Performed |
---|---|
0 or LOW | Length |
1 or MEDIUM | Length; numeric, lowercase/uppercase, and special characters |
2 or STRONG | Length; numeric, lowercase/uppercase, and special characters; dictionary file |
The default is 1, which is MEDIUM, so the initial password must match the length and must contain Numbers, lowercase or uppercase letters, and special characters.
Sometimes, just for the sake of testing myself, I don't want the password to be so complicated. For example, I just want to set the password for root to 123456.
Two global parameters must be modified:
First, modify the value of the validate_password_policy parameter
mysql
>
set global validate_password_policy=0;
Query OK, 0 rows affected (0.00 sec)
You can change it to your own password.
After setting, you need to set the remote access rights of mysql. There are two places to set, one is open to external ip address, and the other is open to port.
The most common setting is to set mysql authorization with the following command
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'youpassword' WITH GRANT OPTION;
If you want to set authorization for an ip address, change % to your ip address, set it up, and reauthorize the table
FLUSH PRIVILEGES;
Then exit exits mysql and restarts mysql
service mysqld restart
In centos7, port 3306 is opened via firewall-cmd
firewall-cmd --zone=public --add-port=3306/tcp --permanent
Setup complete, reload firewall
firewall-cmd --reload
Use the command to see if port 3306 was set successfully
firewall-cmd --list-all-zones
At this point, the installation and configuration of mysql in centos7 is complete
Thank you for reading, I hope to help you, thank you for your support of this site!