Installation and configuration of MySQL 5.7 under CentOS7 (YUM)

Installation environment: CentOS7 64-bit MINI version, install MySQL5.7

1. Configure the YUM source

Download the YUM source rpm installation package from the MySQL official website: http://dev.mysql.com/downloads/repo/yum/ 

# 下载mysql源安装包
shell> wget http://dev.mysql.com/get/mysql57-community-release-el7-8.noarch.rpm
# 安装mysql源
shell> yum localinstall mysql57-community-release-el7-8.noarch.rpm

Check if the mysql source is installed successfully

shell> yum repolist enabled | grep "mysql.*-community.*"

 
If you see the picture above, the installation is successful.

2. Install MySQL

shell> yum install mysql-community-server

3. Start the MySQL service

shell> systemctl start mysqld

Check the startup status of MySQL

shell> systemctl status mysqld
● mysqld.service - MySQL Server
   Loaded: loaded (/usr/lib/systemd/system/mysqld.service; disabled; vendor preset: disabled)
   Active: active (running) since 五 2016-06-24 04:37:37 CST; 35min ago
 Main PID: 2888 (mysqld)
   CGroup: /system.slice/mysqld.service
           └─2888 /usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid

624 04:37:36 localhost.localdomain systemd[1]: Starting MySQL Server...
624 04:37:37 localhost.localdomain systemd[1]: Started MySQL Server.

4. Start up

shell> systemctl enable mysqld
shell> systemctl daemon-reload

5. Modify the root default password

After the mysql installation is complete, a default password is generated for root in the /var/log/mysqld.log file. Find the root default password in the following way, and then log in to mysql to modify it:

shell> grep 'temporary password' /var/log/mysqld.log

shell> mysql -uroot -p
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyNewPass4!'; 

or

mysql> set password for 'root'@'localhost'=password('MyNewPass4!'); 

Note: The password security check plugin (validate_password) is installed by default in mysql5.7. The default password check policy requires that the password must contain: uppercase and lowercase letters, numbers and special symbols, and the length cannot be less than 8 characters. Otherwise, it will prompt ERROR 1819 (HY000): Your password does not satisfy the current policy requirements error, as shown in the following figure: 

You can view information about password policies through the msyql environment variable:

mysql> show variables like '%password%';



  validate_password_policy: password policy, the default is MEDIUM policy validate_password_dictionary_file: password policy file, only required if the policy is 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: number at least 1 validate_password_special_char_count: special character at least 1   above parameters is the password checking rule for the default policy MEDIUM.

There are the following password policies:

Policy Check Rules
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

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

Modify password policy

Add the validate_password_policy configuration to the /etc/my.cnf file to specify the password policy

# 选择0(LOW),1(MEDIUM),2(STRONG)其中一种,选择2需要提供密码字典文件
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 for the configuration to take effect:

systemctl restart mysqld

6. Add remote login user

By default, only the root account is allowed to log in locally. If you want to connect to mysql on other machines, you must modify root to allow remote connections, or add an account that allows remote connections. For security, I add a new account:

mysql> GRANT ALL PRIVILEGES ON *.* TO 'yangxin'@'%' IDENTIFIED BY 'Yangxin0917!' WITH GRANT OPTION;

7. Configure the default encoding as utf8

Modify the /etc/my.cnf configuration file and add the encoding configuration under [mysqld], as follows:

[mysqld]
character_set_server=utf8
init_connect='SET NAMES utf8'

Restart the mysql service and view the default encoding of the database 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/mysqld.pid

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326325086&siteId=291194637