Install MySQL5.7 under Centos7.x (yum installation)

MariaDB is installed by default in CentOS, which is a branch of MySQL, but for needs, MySQL must be installed in the system, and MariaDB can be overwritten directly after the installation is complete.

1. Install mysql

(Since there is no mysql-server on the yum source. So you must go to the official website to download, here we use the wget command to get it directly)

wget -i http://dev.mysql.com/get/mysql57-community-release-el7-10.noarch.rpm

2. Install the dependency package of mysql

yum -y install mysql57-community-release-el7-10.noarch.rpm

Or rpm -ivh mysql57-community-release-el7-10.noarch.rpm

3. Install mysql database

yum -y install mysql-community-server

4. Complete the installation and restart mysql

systemctl restart mysqld.service

At this time, MySQL has started to run normally, but if you want to enter MySQL, you must first find out the password of the root user at this time. You can find the password in the log file by using the following command:
grep "password" /var/log /mysqld.log

Note: The space in front is not a password

5. Copy and paste the password above to enter the database

mysql -uroot -p

enter the initial password, you can't do anything at this time, because MySQL must modify the password by default before operating the database to modify the password command:
ALTER USER'root'@'localhost' IDENTIFIED BY '123';

6. Solve the error

The above error is that the newly set password is too simple, the solution:
//First change the complexity of the default password format
ALTER USER'root'@'localhost' IDENTIFIED BY'Xiejinming@12';

7. View MySQL's complete initial password rules

To view the complete initial password rules of MySQL, the premise of viewing is that the password must be changed with the ALTER USER command (SHOW VARIABLES LIKE'validate_password%';).


How to install MySQL5.7 under Centos7
Note: The length of the password is determined by validate_password_length, and the calculation formula of validate_password_length is: validate_password_length = validate_password_number_count + validate_password_special_char_count + (2 * validate_password_mixed_case_count)

8. Modify MySQL default policy and password length

1) Password modification policy
Because the current password is too complex to be convenient for later experiments, there are two ways to modify the password policy using commands:

The following two methods are randomly used to execute
mysql> set global validate_password_policy=0;

mysql> set global validate_password_policy=LOW;

Note: There are four password policies:
1. OFF (closed) 2. LOW (low) 3. MEDIUM (medium) 4. STRONG (strong)

2) Modify the password length
After changing the policy above, we will change the length mysql> SET GLOBAL validate_password_length=6;

9. View password rules

Check the password rules after all changes are completed mysql> SHOW VARIABLES LIKE'validate_password%';

10. Change to a simple password

Next, you can change the complex password just now to a simple four-digit password;
ALTER USER'root'@'localhost' IDENTIFIED BY '123456';

11. Uninstall the automatic update of the installation source

At this time, there is still a problem, because the Yum Repository is installed, every yum operation will be automatically updated in the future, because the current database has been installed, so uninstall this:
yum remove mysql57-community-release.noarch

12. Initialize the database

mysql_secure_installation


Note: After executing the initialization command, you need to enter the database root user password, and then press Enter all the way as shown in the screenshot above by default. (The above screenshot question can also be selected according to your actual situation)

13. Grant permissions so that remote tools can connect

1) Switch to the mysql database: use mysql;

2) Grant permissions so that any host can use the root account and password 123456 to log in

GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '123456' WITH GRANT OPTION;

3) Refresh new permissions: flush privileges;

4) View users

select user,host,authentication_string 密码 from user;

5) Turn off the firewall

View | close | open firewall systemctl status | stop | start firewalld.service

Permanently disable firewall: systemctl disable firewalld.service

6) Use the Navicat tool to test the link

14. Set the database to ignore case (some projects need to be ignored, otherwise the project will not start)

In the linux system, under the default settings:

数据库名与表名是严格区分大小写的;
列名与列的别名在所有的情况下均是忽略大小写的;
变量名也是严格区分大小写的;

In windows system, under the default settings:

都不区分大小写

Check the value of lower_case_table_names, 0 means case sensitive, 1 means case insensitive.

show Variables like '%case%';

mysql> SHOW VARIABLES LIKE '%case%';
+------------------------------------+-------+
| Variable_name                      | Value |
+------------------------------------+-------+
| lower_case_file_system             | OFF   |
| lower_case_table_names             | 0     |
| validate_password_mixed_case_count | 1     |
+------------------------------------+-------+
3 rows in set (0.01 sec)

mysql> 

Solution:

1) Use vi /etc/mysql/my.cnf to open the mysql configuration file,

2) Add the following code under [mysqld]: lower_case_table_names=1

Note: It must be placed under the mysqld node. If placed under other nodes, it will not take effect!!!!

You can add the following configuration by the way:

character_set_server=utf8

#The default storage engine of the new data table

default-storage-engine=INNODB

max_allowed_packet=128M

max_connections=1000

lower_case_table_names=1

3) After setting, save and restart the database: systemctl restart mysqld.service

4) Check the value of lower_case_table_names again

show Variables like '%case%';

mysql> SHOW VARIABLES LIKE '%case%';
+------------------------------------+-------+
| Variable_name                      | Value |
+------------------------------------+-------+
| lower_case_file_system             | OFF   |
| lower_case_table_names             | 1     |
| validate_password_mixed_case_count | 1     |
+------------------------------------+-------+
3 rows in set (0.01 sec)

mysql> 

 

Guess you like

Origin blog.csdn.net/weixin_42162451/article/details/115030822