[MySQL] Teach you step by step how to download MySQL for centos7

centos7 download MySQL

  • Preface
  • Officially begin
    • Uninstall unnecessary environments (you can skip if you have not installed database-related things before)
    • download mysql
    • Login mysql
      • Log in to the FAQ [If not, click next]
      • Log in to the FAQ [If not, click next]
      • Login method three

Foreword

It is more convenient to install and uninstall MySQL using the root authority of the system. After the installation is successful, it can also be used by ordinary users of the system.

Officially begins

Uninstall unnecessary environments (you can skip if you have not installed database-related things before)

Here I will introduce how to uninstall mariadb, because there is a mariadb in my system, and the same is true for uninstalling MySQL.

First, use the following command to check whether the mariadb service is running on your system:

ps ajx | grep mariadb
#Here is to check mariadb. If you want to see if mysql is running in your system, you can replace mariadb with mysql.

My system found this:

[root@VM-24-6-centos ~]# ps ajx | grep mariadb
 5779 5956 5779 5779 ? -1 Sl 27 80:43 /usr/libexec/mysqld --basedir=/usr --datadir=/var/lib/mysql --plugin-dir=/usr/lib64/mysql/plugin -- log-error=/var/log/mariadb/mariadb.log --pid-file=/var/run/mariadb/mariadb.pid --socket=/var/lib/mysql/mysql.sock
12731 13051 13050 12731 pts/12 13050 S + 0 0:00 grep --color=auto mariadb

The long process among them is the mariadb server.

If it exists in your system, then use the following command to turn it off first:

systemctl stop mariadb.service

Then use ps ajx | grep mariadb and it will disappear:

[root@VM-24-6-centos ~]# ps ajx | grep mariadb
12731 15795 15794 12731 pts/12 15794 S + 0 0:00 grep --color=auto mariadb

Generally, the installation package format obtained through yum is .rpm. If you have installed it before, you must have retained these installation packages. The same is true for mariadb here. You can use rpm -qa to view all installation packages, but here you only want to uninstall them. mariadb, so add a grep:

[root@VM-24-6-centos ~]# rpm -qa | grep mariadb
mariadb-libs-5.5.68-1.el7.x86_64
mariadb-server-5.5.68-1.el7.x86_64
mariadb-5.5.68-1.el7.x86_64
mariadb-devel-5.5.68-1.el7.x86_64

You can see that there are four installation packages here. You can delete them manually one by one, but you can also use xargs to convert the command function parameters:

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

This uninstalls successfully:

Let’s take a look at the mariadb related configuration files, file: /etc/my.cnf, check with ls:

If there is no such file, there is no problem. If there is, you can make a backup (rename it).

Then check to see if there is any database you left behind, under the /var/lib/mysql/ path:

If there is, don’t worry, it won’t affect the use of re-downloading MySQL. If not, it’s no problem.

Download mysql

First, the most important step is to check the release version of your system. When you download it later, download it according to the version.

[root@VM-24-6-centos ~]# cat /etc/redhat-release
CentOS Linux release 7.9.2009 (Core)

You can see that mine is 7.9.

Then download a mysql yum source from this website: mysql official? yum source
It was very messy after I clicked on it, like this:

It doesn’t matter, put your mouse in the blank space on the right and right-click:

Click to view the page source code, it will look like this:

Compare the middle one:

Find your version and scroll down. The version starting with el is centos. There are two types:

One is mysql57:

One is mysql80:

The following el number – the number indicates your centos distribution version, find the one that best matches.

I download mysql57 here, you can also download 80, but I will explain mysql later. If you want to learn based on my blog, it is recommended to follow me and download 57, because the problems that may occur in different versions will be different. .

I also saw earlier that my centos version is 7.9, so this is what I downloaded:

If none of the above matches your version, you can download the one at the bottom:

Note: It is best to install the mysql version that is consistent with the system, otherwise there may be software compatibility issues.

After downloading, this is what it looks like:

Then open your xshell. If you don’t have rzsz, use yum to download the file directly from your Windows to your Linux:

Create a mysql directory and put this file in it:

You can see that it ends with .rpm.

Then use the following command:

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

It’s equivalent to decompressing.

running result:

[root@VM-24-6-centos MySql]# rpm -ivh mysql57-community-release-el7-9.noarch.rpm
Preparing... ################################# [100%]
Updating/installing...
   1:mysql57-community-release-el7-9 ################################ [100%]

after that:

[root@VM-24-6-centos MySql]# rpm -qa | grep mysql
mysql57-community-release-el7-9.noarch

It’s OK to have this.

Then check whether your yum source is related to mysql:

yum list | grep mysql

It may be slower, the effect is:

It’s ok if it has the above effects.

Then you can install mysql with the following command:

yum install -y mysql-community-server

If you encounter this problem when downloading:

Don’t worry, it will be solved with the following command:

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

After executing this command, just execute the yum install command again.

Good results when downloading correctly:

This completes the download.

Let’s take a look at the related configuration files of mysql:

There is.

Take another look at the mysqld server and mysql:

Here mysqld is in the sbin directory. Only super users can start the server. Ordinary users cannot start it. However, when we use it, we hand the sql statement to mysql, and then mysql hands our request to mysqld, so ordinary users can also Can use mysql.

Start mysqld at this time:

In this way, you can see that the server has been started. Generally, anything starting with d is a daemon process (I mentioned it in the previous blog on the Internet). Mysqld here is also a daemon process. You can also check it with netstat:

Log in to mysql

The server here has started mysql and I can log in, but I just downloaded it and I can’t log in, and I don’t know the password:

Login method? [If not, click next]

Get temporary root password

[root@VM-24-6-centos MySql]# grep 'temporary password' /var/log/mysqld.log

If you try it and it doesn’t work, that’s okay, mine didn’t either. Then the next method.

It’s not that there is no such file, but that this method is no longer supported in newer versions, but the log file is still there:

Login method? [If not, click next]

If you install the latest mysql, there is no so-called temporary password. Root (the root here refers to the root of mysql, which is not the same thing as the root of the Linux system, I will talk about this later in the blog) has no password by default.

Try to log in directly with the client? Next:

I can board it directly here, but I don’t know if you can. If you are logged in, type quit; to exit.

If you still can’t get on, try the next option.

Login method three

Open the configuration file:

After entering, this is what it looks like:

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 the skip-grant-tables option, save and exit:

After modifying the configuration file here, you need to restart mysqld, because it was started according to the previous configuration file:

When you log in again at this time, although you are still asked to enter your password, you can log in by entering whatever you want. You can log in by just pressing Enter without entering anything.

Or you can log in directly without adding the option -p when logging in:

Next, make some modifications to the configuration file, mainly to configure the encoding format of the database client and server by default. The modifications are as follows:

port is the default port. The default port modified here is 3306.
character-set-server is the encoding, here it is UTF-8.
default-storage-engine is the storage engine, here it is innodb.

Mysql is actually a network service, so it also requires a port number, but here it is a stand-alone access. I will talk about encoding and storage engines later in the blog, so I’ll just take a look at them here.

At this point, everything that needs to be done has been completed. In the early stage of the exercise, MySQL does not do any user management. First, use it as root. I will blog about it as soon as possible. After user management is discussed, I will consider creating a normal user and setting up root. Password login works.

It ends here. . .