The preface

Idle to nothing, recently bought a ali cloud server, want to deploy your own program, thus began the difficult journey of ali cloud deployment, the most began to try many CSDN and blog articles, many of them ended in failure, finally in the interpretation of the continuous trial and error and enthusiastic netizens, finally succeeded, idiopathic a blog to record it. The selected installation is online, version 5.7.

Step 1: Test for traces of Mariadb

Centos7 will install Mariadb by default, which will affect mysql installation, so we first check whether the system has Mariadb, if it does, delete it, if it does not, we can proceed to the next installation.

rpm -qa|grep mariadb
Copy the code

I’m showing it here, so I need to use the command to uninstall mariadb installed by default.

#-e --nodep is forcibly deleted, regardless of dependencies, followed by the mariadb file name.- e -- nodeps mariadb - libs - 5.5.65-1. El7. X86_64Copy the code

Let’s look it up again after we delete it.

rpm -qa|grep mariadb
Copy the code

If not, we can start installing Mysql. 🙂

Step 2 download the mysql source installation package

wget http://dev.mysql.com/get/mysql57-community-release-el7-11.noarch.rpm
Copy the code

If you see this one hundred percent, it means that the installation is successful. We installed version 5.7. If you want to install other versions, you can go to the official website to find other download sources.

Install the mysql source

yum localinstall mysql57-community-release-el7-11.noarch.rpm
Copy the code

Seeing this complete shows that we have successfully installed, and the previous warming can be ignored.

Step 4 check whether the mysql source is installed successfully

After this long installation, we should check to see if we have successfully installed it, otherwise the following steps will be futile. :smirk:

This shows that we have successfully installed the mysql source.

Install MySql

yum install mysql-community-server
Copy the code

During the installation process, it will prompt us Is this OK [y/d/N]:, and we will directly enter y mindlessly to go to the next step.

We see the familiar complete again.

Start MySql

MySql has been installed successfully. Now you can start MySql service.

#Start the MySql
systemctl start mysqld

#Check the running status of MySql
systemctl status mysqld
Copy the code

MySql is running in active mode. To avoid having to start MysSql every time we start the server, we try to set it to start automatically after startup.

systemctl enable mysqld
systemctl daemon-reload
Copy the code

Step 7: Log in to MySql with your initial password

In MySql5.6 and later versions, MySql will default to a very complicated initial password after installation, so we need to query the initial password first, and then log in to the database to change the initial password.

#The initial password of MySql is /var/log/mysqld.log file, let's look it up.
grep 'temporary password' /var/log/mysqld.log
Copy the code

This is our default initial password, just log in. :grinning:

Step 8 change the initial password

We can change our password as soon as we log in. It’s impossible. Let’s just keep logging in with a long, smelly initial password.

If we want to design a simpler password, such as 123456, we need to change the MySql password limit first. Otherwise an error will be reported!

#Example Change the value of validate_password_policy
set global validate_password_policy=0;

#Then change the password length
set global validate_password_length=1;
Copy the code

Now we can set up our own passwords, no matter how simple.

#Statement to change a passwordSet password for 'root'@'localhost'=password(' own password ');Copy the code

Done!! We’ve already done the security and basic configuration of our MySql database by the time we get here, but this window is so dark that we use visual Windows for remote connections,

Step 9. Authorize other machines to log in

GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'root1234' WITH GRANT OPTION; FLUSH PRIVILEGES;Copy the code

Step 10. Change the default character encoding

In order to prevent Chinese garbled characters, we usually change the default character encoding to UTF-8. CNF / /etc/my.cnf/mysqld/mysqld/mysqld

#Modify/etc/my CNF
vim /etc/my.cnf

#Add the configuration
character_set_server = utf8
init_connect='SET_NAMES UTF8'
Copy the code

After the modification, let’s query it. Don’t forget to restart the database and verify whether the modification is successful.

#Restarting the Database
systemctl restart mysqld

#Log in to the database to query information
show variables like '%character%';
Copy the code

After the modification, let’s query it. Don’t forget to restart the database and verify whether the modification is successful.

#Restarting the Database
systemctl restart mysqld

#Log in to the database to query information
show variables like '%character%';
Copy the code