MySQL5.7 installation tutorial under Centos7 (full diagram)

I. Introduction

 MySQL is a portable database that can run on almost all current operating systems. This article focuses on how to install MySQL on Centos7. During the installation process, it is recommended to always run as root user to reduce the cost of operation.

2. Uninstall unnecessary environments

 In your Centos7 system, MySQL or mariadb (a branch of MySQL) may have been pre-installed and run as a daemon process in the background. We must first stop these services before we can delete the original installation package.

  • Use to ps ajxdisplay whether mysqld exists (the same is true for mariada, and I won’t repeat it later)
    insert image description here
  • Use systemctl stopthe command to stop the mysql service
    insert image description here

If the system does not have mysql, this step is skipped

3. Delete the default installation package

  • Use rpm -qa | grep mysqlthe command to display whether the mysql package is installed in the system
    insert image description here
  • If there is, use rpm -qa | grep mysql | xargs yum -y removethe command to delete all installation packages. The function of the xargs instruction is to "feed" the previous data to the following instructions one by one, so as to achieve the purpose of batch operation. Note -yCannot be omitted, otherwise errors will occur during batch processing
  • After deleting, check again to confirm that it has been completely deleted.
    insert image description here

If the mysql installation package cannot be found in the system, skip this step directly

4. Obtain the official source of mysql

[Purpose] : Finally, you can use yum installthe command to install with one click
[Problem] : There may be no mysql source in the default yum source in the cloud server
insert image description here
[Solution] : First, manually pull the mysql yumsource from the official website (note that it is not to download mysql)

  • First get the official yum source of mysql > yum source link
    insert image description here
  • Right-click to view the source code of the web page to see more file details
    insert image description here
  • Pay attention to version issues when installing
    1. Choose elthe version with the words in the name. elRefers to Enterprise Linux , which is the abbreviation of centos
      insert image description here

    2. Select the version with 57 in the name , 57 means the version of mysql is 5.7, otherwise the download is the latest version of mysql
      insert image description here

    3. It is best to install the mysql version that is consistent with your own system , otherwise there may be software compatibility issues. If there is no suitable version, our principle is to choose a mysql version newer than the system version , which is generally forward compatible

    4. Use cat /etc/redhat-releasethe command to view the current centos version
      insert image description here

    5. Select the version mysql that matches the operating system. Everything in the picture below will do
      insert image description here

  • Use rzthe command to upload the locally downloaded mysql source to the cloud server environment
    insert image description here
  • Use rpm -ivhthe command to install the rpm package
    insert image description here
    . So far we have completed the installation of the official source. Check the yum source again and find two more items. The essence of installation under Linux is to copy files to a specific path.
    insert image description here

Use the following command to check whether the yum source of mysql is working properly: yum list | grep mysql . If you can filter out mysql-related packages, it means that the yum source is working properly

Five, install mysql service

 We have solved the problem of the mysql yum source before, and now we can use the yum command to install it with one click yum install -y mysql-community-server. Although we seem to have only installed mysql-community-server, yum will automatically handle dependencies, and mysql clients, components, libraries, etc. will be automatically installed.

  1. Common Mistakes: Key Expiration Problems
    insert image description here
    Use the following command to reactivate the key:rpm --import https://repo.mysql.com/RPM-GPG-KEY-mysql-2022
  2. Verify that the installation was successful
    insert image description here

6. Set password-free login

  • You can log in without password by adding this sentence in the mysql configuration file: skip-grant-tables. At this point we do not need a password to log in to mysql. If the service has been started before, then use the command systemctl restart mysqldto restart mysql, and the configuration information will take effect.
  • Use the command systemctl start mysqldcommand to start the mysql server (note that it is not mysql)
  • Use the command to log in mysql -uroot -pas the root user
    insert image description here

Guess you like

Origin blog.csdn.net/whc18858/article/details/130003385