Install and configure MySQL5.7 in CentOS7 (YUM)
Link: http://blog.csdn.net/xyang81/article/details/51759200
Installation environment: CentOS7 64-bit MINI version, install MySQL5.7
1. Configure the YUM Source
Download the YUM source rpm installation package: http://dev.mysql.com/downloads/repo/yum/ from the MySQL website
# 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 is successfully installed.
shell> yum repolist enabled | grep "mysql.*-community.*"
The installation is successful.
2. Install MySQL
shell> yum install mysql-community-server
3. Start the MySQL Service
shell> systemctl start mysqld
View the MySQL startup status
Shell> systemctl status mysqld ● mysqld. service-MySQL Server Loaded: loaded (/usr/lib/systemd/system/mysqld. service; disabled; vendor preset: disabled) Active: active (running) since 5 04:37:37 CST; 35 min ago Main PID: 2888 (mysqld) CGroup:/system. slice/mysqld. service expose-2888/usr/sbin/mysqld -- daemonize -- pid-file =/var/run/mysqld. pid June 24 04:37:36 localhost. localdomain systemd [1]: Starting MySQL Server... june 24 04:37:37 localhost. localdomain systemd [1]: Started MySQL Server.
4. boot
shell> systemctl enable mysqldshell> systemctl daemon-reload
5. Modify the default root password.
After mysql is installed, a default password is generated for root in the/var/log/mysqld. log file. Find the default root password in the following way, and then log on to mysql to modify it:
shell> grep 'temporary password' /var/log/mysqld.log
shell> mysql -uroot -pmysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyNewPass4!';
Or
mysql> set password for 'root'@'localhost'=password('MyNewPass4!');
Note: The password security check plug-in (validate_password) is installed in mysql5.7 by default. The default password check policy requires that the password must contain uppercase and lowercase letters, numbers, and special characters, and the length cannot be less than 8 characters. Otherwise, ERROR 1819 (HY000): Your password does not satisfy the current policy requirements is returned, as shown in:
You can use the msyql environment variable to view information about the password policy:
mysql> show variables like '%password%';
Validate_password_policy: Password Policy. The default value is the MEDIUM policy validate_password_dictionary_file: password policy file. If the policy is STRONG, validate_password_length is required. The minimum password length is uppercase/lowercase, and at least one validate_password: the number must have at least 1 validate_password_special_char_count: at least 1 Special CharacterThe above parameters are the password check rules of the Default policy MEDIUM.
There are several password policies:
PolicyCheck rules0 or LOWLength1 or MEDIUMLength; numeric, lowercase/uppercase, and special characters2 or STRONGLength; numeric, lowercase/uppercase, and special characters; dictionary file
MySQL official website password policy detailed description: http://dev.mysql.com/doc/refman/5.7/en/validate-password-options-variables.html#sysvar_validate_password_policy
Change Password Policy
Add the validate_password_policy configuration in the/etc/my. cnf file and specify the password policy.
# Select either 0 (LOW), 1 (MEDIUM), or 2 (STRONG). Select 2 and provide the password dictionary file validate_password_policy = 0.
If you do not need a password policy, add the following configuration to the my. cnf file to disable it:
validate_password = off
Restart the mysql service to make the configuration take effect:
systemctl restart mysqld
6. Add a remote logon user
By default, only the root account is allowed to log on locally. To connect to mysql on other machines, you must modify the root account to allow remote connection or add an account that allows remote connection. For security reasons, add a new account:
mysql> GRANT ALL PRIVILEGES ON *.* TO 'yangxin'@'%' IDENTIFIED BY 'Yangxin0917!' WITH GRANT OPTION;
7. Set the default encoding to utf8.
Modify the/etc/my. cnf configuration file and add the encoding configuration under [mysqld], as shown below:
[mysqld]character_set_server=utf8init_connect='SET NAMES utf8'
Restart the mysql service and check the default database encoding as follows:
Default Configuration File Path: configuration file:/etc/my. cnf log File:/var/log // var/log/mysqld. log Service Startup Script:/usr/lib/systemd/system/mysqld. service socket file:/var/run/mysqld. pid