Installation environment: CentOS 7 64-bit MINI version, MySQL 5.7 installation
1. Configure YUM source
Download YUM source RPM installation package from MySQL official website: http://dev.mysql.com/downloads/repo/yum/
# Download MySQL source installation package shell> wget http://dev.mysql.com/get/mysql57-community-release-el7-8.noarch.rpm # Install MySQL source shell> yum localinstall mysql57-community-release-el7-8.noarch.rpm
Check whether the MySQL source was installed successfully
shell> yum repolist enabled | grep "mysql.*-community.*"
See the figure above to show that the installation was successful.
Can be modifiedyumSource, change the default version of MySQL installed. For example, to install version 5.7, change the enabled = 0 of the 5.7 source to enabled = 1. The effect after the modification is as follows:
2. Installing MySQL
shell> yum install mysql-community-server
3. Start MySQL Service
shell> systemctl start mysqld
View MySQL startup status
shell> systemctl enable mysqld shell> systemctl daemon-reload
5. Modify the root local login password. It is possible that the default root password is empty.
1. If the default password is empty, login directly by return.
With a password, after the installation of MySQL is completed, a default password is generated for root in the / var / log / mysqld. log file. Find the root default password by following, then login Mysql to modify it:
shell> grep 'temporary password' /var/log/mysqld.log
shell> mysql -uroot -p mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyNewPass4!';
mysql> set password for 'root'@'localhost'=password('MyNewPass4!');
Note: Mysql 5.7 installs the password security checking plug-in (validate_password) by default. The default password checking policy requires that the password must contain upper and lower case letters, numbers and special symbols, and the length must not be less than 8 bits. Otherwise ERROR 1819 (HY000): Your password does not satisfy the current policy requirements error, as shown in the following figure:
The MSYQL environment variable allows you to view information about password policies:
mysql> show variables like '%password%';
Validate_password_policy: Password policy, default to MEDIUM policy
Validate_password_dictionary_file: Password Policy File, which is required for STRONG
Validate_password_length: Minimum password length
Validate_password_mixed_case_count: Upper and lower case character length, at least 1
Validate_password_number_count: at least one number
Validate_password_special_char_count: at least one special character
The above parameters are the password checking rules for the default policy MEDIUM.
There are several cryptographic strategies:
MySQL official password policy: http://dev.mysql.com/doc/refman/5.7/en/validate-password-options-variables.html#sysvar_validate_password_policy
Modifying password policy
Add the validate_password_policy configuration to the / etc/my.cnf file to specify the password policy
# Select one of 0 (LOW), 1 (MEDIUM), 2 (STRONG), and choose 2 to provide a password dictionary file validate_password_policy=0
If no password policy is required, add the following configuration to my.cnf file to disable it:
validate_password = off
Restart the MySQL service to make the configuration effective:
systemctl restart mysqld
6. Add remote login users
By default, only root accounts are allowed to log in locally. To connect mysql on other machines, you must modify root to allow remote connections or add an account that allows remote connections. For security reasons, I add a new account:
mysql> GRANT ALL PRIVILEGES ON *.* TO 'yangxin'@'%' IDENTIFIED BY 'Yangxin0917!' WITH GRANT OPTION;
7, configure the default encoding to be utf8
Modify the /etc/my.cnf configuration file and add the encoding configuration under [mysqld].
[mysqld] character_set_server=utf8 init_connect='SET NAMES utf8'
Restart the MySQL service to view the default encoding of the database as shown below.
Default profile path:
Configuration file: /etc/my.cnf
Log file: / var/log//var/log/mysqld.log
Service startup script: / usr / lib / system D / system / mysqld. service
Socket file: / var / run / mysqld / mysqld. PID
Centos7 uninstalls MySQL
View the current installation status
rpm -qa|grep -i mysql
yum remove mysql
rpm -e mysql-community-release-el7-5.noarch
If prompted for dependency errors
rpm -ev --nodeps mysql-community-libs-5.6.43-2.el7.x86_64
Delete in accordance with this method
Next, I looked up the directory of the old version of MySQL and deleted the files and libraries of the old version of mysql. I did not delete the old version of MySQL and did an upgrade installation directly.
find / -name mysql
Delete the corresponding MySQL directory
rm -rf /var/lib/mysql
Note: After uninstallation, / etc/my.cnf will not be deleted. It needs to be deleted manually.
rm -rf /etc/my.cnf
My. CNF is sometimes not necessarily in / etc, but can be found by command
find / -name my.cnf
Find again if MySQL is installed on the machine
rpm -qa|grep -i mysql
I did not delete the original configuration file, database, direct installation of 5.7, the original database storage, but the database can not be used, I used two commands to solve.
The original database can be used normally.