This is a scattered note of Songgo before, sort out and share with everyone!

MySQL read-write separation is a very common requirement in Internet projects. Due to Linux and MySQL version problems, many people often fail to build, today Songko will give you a successful example, later have time to share with you the use of Docker build environment, that will be 100% successful.

CentOS install MySQL

I play Linux songo generally preferred Ubuntu, but the company generally use CentOS, so here songo on CentOS as an example to show you the whole process, today this article mainly to look at the installation of MySQL.

Environment:

  • CentOS7
  • MySQL5.7

The installation procedure is as follows:

  • Check if Mariadb is installed and uninstall it if it is:
yum list installed | grep mariadb
Copy the code

If the following command output is displayed, Mariadb is installed. Uninstall mariadb:

Mariadb - libs. X86_64 1:5. 5.52-1. El7 @ anacondaCopy the code

The uninstallation command is as follows:

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

If the wget command does not exist on CentOS, run the following command to install wget:

yum install wget
Copy the code

Then perform the following operations to download the RPM package:

wget https://dev.mysql.com/get/mysql57-community-release-el7-11.noarch.rpm
Copy the code
  • After downloading, install the RPM package:
rpm -ivh mysql57-community-release-el7-11.noarch.rpm
Copy the code
  • Check whether the MySQL yum source is installed successfully:
yum repolist enabled | grep "mysql.*-community.*"
Copy the code

If the command output is as follows, the installation is successful:

  • MySQL installation
yum install mysql-server
Copy the code
  • MySQL > install MySQL
systemctl start mysqld.service
Copy the code
  • Stop the MySQL:
systemctl stop mysqld.service 
Copy the code
  • Log on to the MySQL:
mysql -u root -p
Copy the code

By default, there is no password. Some versions have the default password to check the default password, first of all to the/etc/my CNF check MySQL log directory location, and then open the log file, you can see in the log has a prompt, generates a temporary default password, use this password to log in and modify the password after login successfully.

  • To change the password

Change the password policy first (this step is not necessary, if you do not change the password policy, you need to obtain a more complex password, songo here for simplicity, change the password policy) :

set global validate_password_policy=0;
Copy the code

Then reset the password:

set password=password("123");     
flush privileges;
Copy the code
  • Authorize remote Login in the same way:
grant all privileges on *.* to 'root'@The '%' identified by '123' with grant option;
flush privileges;
Copy the code
  • Authorize remote Login In the same way as Method 2:

Mysql > select * from Host where user = ‘root’;

  • Disable the firewall to enable remote access to MySQL.
systemctl stop firewalld.service
Copy the code

Disable firewall startup:

systemctl disable firewalld.service
Copy the code

conclusion

If you have any questions about how to install MySQL on Ubuntu, please leave a comment. The next article will share the MySQL read-write separation environment setup.

Pay attention to the public account [Jiangnan little Rain], focus on Spring Boot+ micro service and front and back end separation and other full stack technology, regular video tutorial sharing, after attention to reply to Java, get Songko for you carefully prepared Java dry goods!