Improve performance, build MySQL read-write separation environment (1)

Time:2019-10-21

This is a scattered note before brother song. I’ll sort it out and share it with you!

MySQL read-write separation is a very common requirement in Internet projects. Trapped in Linux and MySQL version problems, many people often fail to build. Today, brother song will give you a successful example. Later, I will share with you how to use docker to build the environment, which will be 100% successful.

CentOS install MySQL

Generally speaking, Ubuntu is the first choice for SongGe to play Linux. However, CentOS is still used in the company. So SongGe will take CentOS as an example to show you the whole process. Today’s article focuses on MySQL installation.

Environmental Science:

  • CentOS7
  • MySQL5.7

The specific installation steps are as follows:

  • Check that MariaDB is installed, and if so, uninstall:
yum list installed | grep mariadb

If the execution result is as follows, MariaDB has been installed and uninstalled:

mariadb-libs.x86_64                   1:5.5.52-1.el7                   @anaconda

The uninstall command is as follows:

yum -y remove mariadb* 
  • Next download the official RPM package

If there is no WGet command on CentOS, first install WGet through the following command:

yum install wget

Then download the RPM package as follows:

wget https://dev.mysql.com/get/mysql57-community-release-el7-11.noarch.rpm
  • When the download is complete, install the RPM package:
rpm -ivh mysql57-community-release-el7-11.noarch.rpm
  • Check if the yum source of MySQL is installed successfully:
yum repolist enabled | grep "mysql.*-community.*"

The execution result shows that the installation is successful:

Improve performance, build MySQL read-write separation environment (1)

  • Install MySQL
yum install mysql-server
  • After installation, start MySQL:
systemctl start mysqld.service
  • Stop MySQL:
systemctl stop mysqld.service 
  • Log in to MySQL:
mysql -u root -p

No password by default. Some versions have a default password. To view the default password, first go to the directory / etc / my.cnf to view the log location of MySQL, and then open the log file. You can see that there is a prompt in the log, and a temporary default password is generated. Log in with this password, and modify the password after login.

  • Change password

First, change the password policy (this step is not necessary. If you don’t change the password policy, you need to take a more complex password. For the sake of simplicity, song Ge will change the password policy):

set global validate_password_policy=0;

Then reset the password:

set password=password("123");     
flush privileges;
  • The same way to authorize remote login:
grant all privileges on *.* to 'root'@'%' identified by '123' with grant option;
flush privileges;
  • The same way to authorize remote login is as follows:

Modify the user table in MySQL library, and change the value of host field of root user to%, and then restart mysql.

  • Turn off firewall

To access MySQL remotely, you need to turn off the firewall:

systemctl stop firewalld.service

Disable firewall startup:

systemctl disable firewalld.service

summary

With so many MySQL installed, it’s better to install MySQL under Ubuntu. Other systems are always a bit troublesome. This article mainly shares the installation steps of MySQL in centos7 with you. If you have any questions, please leave a message for discussion. In the next article, I will share with you the construction of MySQL read-write separation environment.

Pay attention to the public number, focus on spring boot + microservice, share regular video tutorials, reply to Java after paying attention, and get the Java dry goods prepared by SongGe for you!
Improve performance, build MySQL read-write separation environment (1)