centos mysql installation and drainage (including vagrant mysql mirroring)


"SpringCloud Nginx High Concurrency Core Programming" Environment Setup-Series

Component link address
[Required] Virtual machine Linux development environment preparation https://www.cnblogs.com/crazymakercircle/p/14194688.html
Linux openresty installation Linux openresty installation
[Required] Linux Redis installation (with video) Linux Redis installation (with video)
[Required] Linux Zookeeper installation (with video) Linux Zookeeper installation, with video
Windows Redis installation (with video) Windows Redis installation (with video)
RabbitMQ offline installation (with video) RabbitMQ offline installation (with video)
ElasticSearch installation, with video ElasticSearch installation, with video
Nacos installation (with video) Nacos installation (with video)
[Required] Eureka Getting started with Eureka with video
[Required] Getting started with springcloud Config, with video Getting started with springcloud Config with video
[Required] SpringCloud scaffolding packaging and startup SpringCloud scaffolding packaging and startup
Linux self-start, suspended animation, self-start, timed self-start Linux self-starting suspended animation

centos mysql virtual machine image

Crazy Maker Circle’s network disk has prepared the springcloud.box virtual machine image for everyone, which is pre-installed with necessary components such as java, redis, zookeeper, kafka, Eureka, springcloud config, and mysql, saving you the trouble of preparing the development environment. Why not be wonderful . For the network disk address, please see [ Blog Park General Entrance ]

If you really want to install it yourself, please use the following tutorial. This is also the author's installation notes, and will continue to record the problem.

Install mysql

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 Download and install the official Yum Repository of MySQL

Since there is no mysql in the yum source of CentOS, you need to download the yum repo configuration file from mysql's official website. Download command:

[root@localhost ~]# wget -i -c http://dev.mysql.com/get/mysql57-community-release-el7-10.noarch.rpm

The execution process is as follows:

[root@localhost work]# wget -i -c http://dev.mysql.com/get/mysql57-community-release-el7-10.noarch.rpm
--2020-12-27 02:02:22--  http://dev.mysql.com/get/mysql57-community-release-el7-10.noarch.rpm
.....
HTTP request sent, awaiting response... 200 OK
Length: 25548 (25K) [application/x-redhat-package-manager]
Saving to: ‘mysql57-community-release-el7-10.noarch.rpm’

100%[==================================================================================================>] 25,548       127KB/s   in 0.2s

2020-12-27 02:04:42 (127 KB/s) - ‘mysql57-community-release-el7-10.noarch.rpm’ saved [25548/25548]


Use the above command to directly download the Yum Repository for installation, which is about 25KB.

Then install the repo:

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

The execution process is as follows:

[root@localhost work]# rpm -ivh mysql57-community-release-el7-10.noarch.rpm
warning: mysql57-community-release-el7-10.noarch.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Preparing...                          ################################# [100%]
Updating / installing...
   1:mysql57-community-release-el7-10 ################################# [100%]

After the execution is complete, two repo files will be generated in the /etc/yum.repos.d/ directory mysql-community.repo mysql-community-source.repo

Use the yum command to complete the installation

You must enter the /etc/yum.repos.d/ directory and then execute the following script , and then you can directly install yum.

[root@localhost ~]# yum install mysql-server

This step may take some time, and the previous mariadb will be overwritten after the installation is complete.


[root@localhost yum.repos.d]# yum install mysql-server
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 .....
Installed:
  mysql-community-libs.x86_64 0:5.7.32-1.el7 mysql-community-libs-compat.x86_64 0:5.7.32-1.el7 mysql-community-server.x86_64 0:5.7.32-1.el7

Dependency Installed:
  mysql-community-client.x86_64 0:5.7.32-1.el7                         mysql-community-common.x86_64 0:5.7.32-1.el7

Dependency Updated:
  openssl.x86_64 1:1.0.2k-21.el7_9             openssl-libs.x86_64 1:1.0.2k-21.el7_9             postfix.x86_64 2:2.10.1-9.el7

Replaced:
  mariadb-libs.x86_64 1:5.5.44-2.el7.centos

Complete!

Start msyql:

Start MySQL

systemctl start mysqld 

log in:

Get the temporary password during installation (this password is used when logging in for the first time): grep'temporary password' /var/log/mysqld.log

[root@localhost yum.repos.d]# grep 'temporary password' /var/log/mysqld.log
2020-12-27T02:34:04.063826Z 1 [Note] A temporary password is generated for root@localhost: LXwH6NSf*kVh

Use a temporary password to log in to mysql

mysql -u root -p


Then enter the password (temporary password just obtained) LXwH6NSf*kVh

After successful login, change the password

1. First, you need to set the password verification strength level, and set the global parameter of validate_password_policy to LOW.

Enter the setting statement "set global validate_password_policy=LOW;" to set the value,

2. The current password length is 8, if you don’t mind, you don’t need to modify it. Generally speaking, set it to a 6-digit password and set the global parameter of validate_password_length to 6.

Enter the setting statement "set global validate_password_length=6;" to set the value,

3. Now you can set a simple password for mysql, as long as it meets the length of six digits,

Enter the modification statement "ALTER USER'root'@'localhost' IDENTIFIED BY '123456';" and you can see that the modification is successful, indicating that the password policy modification is successful! ! !

The execution process is as follows:

[root@localhost yum.repos.d]# mysql -u root -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.32

Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> set global validate_password_policy=LOW
    -> ;
Query OK, 0 rows affected (0.03 sec)

mysql> set global validate_password_length=6;
Query OK, 0 rows affected (0.01 sec)

mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY '123456';
Query OK, 0 rows affected (0.04 sec)

Note: Be sure to remember to add ";" after the statement is completed when writing sql

Common commands

1. Start MySQL

systemctl start mysqld

2. Close MySQL

systemctl stop mysqld

3. Restart MySQL

systemctl restart mysqld

4. View MySQL running status

systemctl status mysqld

5. Set boot up

systemctl enable mysqld

6, turn off the boot

systemctl disable mysqld

Troubleshoot

mysql account is not allowed to log in remotely

By default, the mysql account does not allow remote login, and can only log in at localhost. This article provides two ways to set mysql to connect through a remote host.

  • 1. Change the table method
    After logging in to mysql from localhost, change the "host" item in the "user" table in the "mysql" database, and rename "localhost" to "%"
#mysql -u root -p
Enter password:
mysql>use mysql;
mysql>update user set host = '%' where user = 'root';
mysql>select host, user from user;


​ Note:% represents any client, which can be replaced with a specific IP address.

  • 2. Authorization Law

For example: If you want myuser to use mypassword (password) to connect to the mysql server from any host.

mysql>GRANT ALL PRIVILEGES ON . TO ‘myuser’@’%’IDENTIFIED BY ‘mypassword’ WITH GRANT OPTION;

If you want to allow the user myuser to connect to the mysql server from the host whose ip is 192.168.1.6, and use mypassword as the password

mysql>GRANT ALL PRIVILEGES ON *.* TO 'myuser'@'192.168.1.3'IDENTIFIED BY 'mypassword' WITH GRANT OPTION;
mysql>FLUSH PRIVILEGES


Configure the default encoding as utf8:

vi /etc/my.cnf 

#Add to

 [mysqld]

 character_set_server=utf8 
 init_connect='SET NAMES utf8'

Other configuration files:

/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

not case sensitive

Find the my.cnf file when you installed MySQL,
as shown in the following figure: Add a line
lower_case_table_names=1 under mysqld (1 is case-insensitive, 0 is case-sensitive, and the default is 0)

Remote connection to Mysql is too slow

Try to solve the above connection timeout problem, but found that it is useless, the above problem will still occur. So I wonder if the remote connection to Mysql is too slow, causing the connection to time out? Because I have no problem connecting to mysql on CentOS7 server and Windows native Navicat. After searching online, I found that the following configuration parameters have been added to the mysql configuration file /etc/my.cnf:

# Note that the configuration is added under [mysqld]

[mysqld]

skip-name-resolve

Then you need to restart the mysql service. Because according to the instructions, if the mysql host queries and resolves DNS, it will cause slowness or the connection will be slow when there are many client hosts. At the same time, please note that after adding this configuration parameter, the host field in the mysql authorization table cannot use the domain name but can only use the ip address, because this is the result of prohibiting the domain name resolution.

Open the port from the firewall, or close the firewall

#View firewalld status through systemctl status firewalld

[root@localhost yum.repos.d]# systemctl status firewalld
● firewalld.service - firewalld - dynamic firewall daemon
   Loaded: loaded (/usr/lib/systemd/system/firewalld.service; disabled; vendor preset: enabled)
   Active: inactive (dead)

If you want to turn off the firewall settings, you may turn off the function through the command systemctl stop firewalld.

systemctl stop firewalld.service   #关闭防火墙

Start firewall

systemctl start firewalld

#Check the firewalld status through systemctl status firewalld again, and it shows that running is already turned on.

Increase the firewall release rules:

#Execute firewall-cmd --permanent --zone=public --add-port=3306/tcp again, prompt success, indicating that the setting is successful,

firewall-cmd --permanent --zone=public --add-port=3306/tcp

In this way, you can continue the following settings. Reload firewall

firewall-cmd --reload

Note: For development environment, just turn off the firewall

报错:Specified key was too long; max key length is 767 bytes

1 ERROR 1071 (42000): Specified key was too long; max key length is 767 bytes

Version 5.6 solution; through the root account, set two global variables:

set global innodb_large_prefix=on;
set global innodb_file_format=Barracuda;

报错:MySql Host is blocked because of many connection errors;

Specific exception

MySql Host is blocked because of many connection errors; unblock with ‘mysqladmin flush-hosts’

  • Cause Analysis:

Check the tomcat log file and found that this error occurred at the beginning of the error report. Upon inquiry, I found that the wrong reason is: the same ip produce too much in a short time (more than mysql database max Connection maximum errors of) the database connection interruption caused by obstruction.

  • Solution:

Enter the CentOS7 server:

  • Method 1: Increase the number of allowed max connection errors (treating the symptoms but not the root cause):
  1. Enter Mysql database to view max connection errors: show variables like'%max_connection_errors%';
  2. Modify the number of max connection errors to 1000: set global max_connect_errors = 1000;
  3. Check whether the modification is successful: show variables like'%max_connection_errors%';
  • Method 2: Use the mysqladmin flush-hosts command to clean up the hosts file:
  1. Find the path of mysqladmin: whereis mysqladmin
  2. Execute commands, such as: /usr/local/mysql5.5.35/bin/mysqladmin -uroot -pyourpwd flush-hosts

Note: Method two clean up the hosts file, you can also directly enter the mysql database to execute the command: mysql> flush hosts;

Back to ◀ Crazy Maker Circle

Crazy Maker Circle-Java high-concurrency research community, open the door to big factories for everyone

Guess you like

Origin blog.csdn.net/crazymakercircle/article/details/111773678