How to install MySQL in Centos7 environment: a simple guide

Table of contents

foreword

1. Uninstall unnecessary environments

1. Check if the local MySQL is running

2. Stop the running MySQL

2. Check the system installation package

3. Uninstall these default installation packages

1. Manually uninstall one by one

2. Automatically uninstall all

4. Obtain the official yum source of mysql

Five, install the mysql yum source, compare the yum source before and after

1. Before installation

2. Installing

3. After installation

6. Check whether the yum source can work normally

Seven, install mysql service

1. Install

2. Check whether the installation is successful

8. Start the service

1. Start the mysql server

2. Check whether the startup is successful

9. Login method

10. Exit mysql

Eleven, configure my.cnf

12. Set the boot to start [can not be set]

Thirteen, a brief introduction to the my.cnf file

14. Common problems during installation:

1. The installation encounters the problem that the secret key expires


foreword

Master the way of data, starting from MySQL! Unlock the secret of installing MySQL on CentOS 7, let your data management upgrade rapidly! Come and explore how to easily build an efficient and reliable database environment and harness the unlimited potential of data! Immediately step into the world of MySQL and start a data journey!


1. Uninstall unnecessary environments

1. Check if the local MySQL is running

ps ajx |grep mariadb # 检查是否有mariadb存在
ps ajx |grep mysqld  # 检查是否有mysqld存在


2. Stop the running MySQL

systemctl stop mariadb.service # 停⽌mariadb服务
systemctl stop mysqld          # 停⽌mysqld服务

2. Check the system installation package

rpm -qa | grep mariadb # 查看mariadb安装包
rpm -qa | grep mysql   # 查看mysql安装包


3. Uninstall these default installation packages

1. Manually uninstall one by one

sudo yum remove [上面查到的安装包名]

2. Automatically uninstall all

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

4. Obtain the official yum source of mysql

Click to get the official yum source of mysql
Note: It is best to install the mysql version that is consistent with your own system, otherwise there may be software compatibility issues

  • Check your system version
cat /etc/redhat-release

  • Enter the official yum source of mysql, and find resources that match your own version
  • Download to your local, then upload to your Linux server

Five, install the mysql yum source, compare the yum source before and after

1. Before installation

ls /etc/yum.repos.d/ -l


2. Installing

  • Because my Linux version is CentOS Linux release 7.6.1810, I downloaded the following version of mysql yum source (el means CentOS)


  • After downloading, upload the local installation package to the Linux server
rz  #远程上传文件命令


  • Now there is an installation package 


  • Install mysql yum source 
rpm -ivh [mysql yum源安装包的名字]


3. After installation

  • If you are like me and have the following two files, then you have successfully installed
ls /etc/yum.repos.d/ -l


6. Check whether the yum source can work normally

  • If you are like me then your yum sources will work fine
yum list | grep mysql


7. Install mysql service and development kit

1. Install

  • Automatically install everything needed for the mysql service according to the yum source just now.
  • Install the mysql service.
sudo yum install -y mysql-community-server

  • If the following problems occur, please see "Fourteen, Frequently Asked Questions"

  • Install mysql development package
sudo yum install mysql-devel
  • After installing the mysql service and development kit, these two directories will appear.
ls /usr/include/mysql/
ls /var/lib/mysql/


2. Check whether the installation is successful

  • Check whether these three files exist, if they exist, it proves that the installation is successful
which mysql      # mysql的客户端
which mysqld     # mysql的服务端
ls /etc/my.cnf   # mysql的配置文件


8. Start the service

1. Start the mysql server

systemctl start mysqld    # 启动mysql的服务端

2. Check whether the startup is successful

ps ajx | grep mysqld

netstat -nltp


9. Login method

  • Open the mysql configuration file (configure the mysql server)
vim /etc/my.cnf # 打开mysql配置⽂件


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


  • Restart the mysql service (the configuration file will only take effect after restarting)
systemctl restart mysqld
  •  Log in
mysql -uroot -p

  • login successful


10. Exit mysql

quit


Eleven, configure my.cnf

  • Open the mysql configuration file (configure the mysql server)
  • Configure in the last column of [mysqld] (I don’t know what it is, just put it at the end of the configuration file), add the following options, save and exit

character-set-server=utf8 # The encoding format of the server, the default setting is utf8
default-storage-engine=innodb # The default storage engine of mysql is set to innodb

vim /etc/my.cnf # 打开mysql配置⽂件

  • Restart the mysql service (the configuration file will only take effect after restarting)
systemctl restart mysqld

12. Set the boot to start [can not be set]

  • Turn on autostart
systemctl enable mysqld
systemctl daemon-reload

Thirteen, a brief introduction to the my.cnf file


  • View the /var/lib/mysql directory


14. Common problems during installation:

1. The installation encounters the problem that the secret key expires

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

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


Summarize

Now, you have mastered the key steps to install MySQL on CentOS 7, just one step away, you will enter a new realm of database! Whether it's a business or an individual, the powerful features of MySQL will help you stand out in the data field. Let us harness the vast ocean of data together and create infinite possibilities! Take action, MySQL is waiting for your exploration!

Guess you like

Origin blog.csdn.net/qq_64042727/article/details/131338082