[MySQL] MySQL installation tutorial in Centos 7 environment

1. Uninstall unnecessary environments

First check if mariadb exists

ps ajx |grep mariadb

If so, stop the mariadb service.

systemctl stop mariadb.service

2. Check the system installation package

rpm -qa | grep mysql

Delete these installation packages

rpm -qa | grep mysql | xargs yum -y remove

Insert image description here

After deletion, we will check it again, then check the configuration file and delete it if it is found.

ls /etc/my.cnf

In addition, we can also use the following command to view the previous MySQL data. This does not need to be deleted.

ls /var/lib/mysql

Insert image description here

3. Get the official yum source of mysql

Get mysql official yum source:mysql official yum source

You can see various versions as follows:

Insert image description here

It is best to install the same mysql version as your own system, otherwise there may be software compatibility issues

Check your system version

cat /etc/redhat-release

Then find the resources that are consistent with your own version on the official website, download them to your local computer, and then upload them to your Linux server (create a separate directory and download the resources to this directory)

Insert image description here

4. Install the mysql yum source and compare the yum sources before and after

View our local yum source

Insert image description here

We can use the following command to install the yum source

rpm -ivh 下载的文件名

Insert image description here

The following is the yum source after installation

Insert image description here

Let's see if it can work normally

yum list | grep mysql

Insert image description here

5. Install mysql service

Now we can install mysql

yum install -y mysql-commuinty-server

Insert image description here

If you encounter the problem of key expiration

Failing package is: mysql-community-client-5.7.39-1.el7.x86_64
GPG Keys are configured as: file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql

We use the following instructions in the command line to solve the problem:

rpm --import https://repo.mysql.com/RPM-GPG-KEY-mysql-2022

6. View configuration files and data storage locations

After installation, we will check the configuration file and data storage location and verify that the installation is successful.

ls /etc/my.cnf
which mysql
which mysqld

Insert image description here

7. Start services and view startup services

Then we can start the service

systemctl start mysqld.service

View startup services

ps axj | grep mysql

We can use the following command to view the service port number of mysql

netstat -nltp

Insert image description here

8.Login

Here we provide 3 login methods

method one

We use the following command to obtain the temporary root password

sudo grep 'temporary password' /var/log/mysqld.log
//最后的为临时密码
2021-04-12T03:23:46.153263Z 1 [Note] A temporary password is generated for
root@localhost: yLMalT:v+5l*

Then log in using the temporary password

mysql -uroot -p

Method Two

If the latest mysql you installed does not have a so-called temporary password, and root has no password by default, try logging in directly with the client.

Method three

Open mysql configuration file

vim /etc/my.cnf

Configure in the last column of [mysqld] (I don’t know what it is, so I put it at the end of the configuration file). Add: skip-grant-tables option, and save and exit.

Then restart the mysql service

systemctl restart mysqld

You can also pause the service first and then start the service

systemctl stop mysqld
systemctl start mysqld

Insert image description here

Then we can log in

After logging in, we can use the following command to change the password:

ALTER USER 'root'@'localhost' IDENTIFIED BY 密码

9.Configure my.cnf

Configure my.conf, mainly the encoding format of the database client and server

We can insert the following three lines in the etc/my.cnf file, which are port, encoding format and character set verification rules.

port=3306
character-set-server=utf8
default-storage-engine=innodb

Finally, we can set up startup. This does not need to be set.

systemctl enable mysqld
systemctl daemon-reload

Guess you like

Origin blog.csdn.net/qq_67582098/article/details/134904171