Table of Contents
0.Description
1. Check the environment (systemctl start/stop/restart)
2. Check the system installation package (rpm -qa)
3. Uninstall these default installation packages (yum remove, xargs)
4. Get the official yum source of mysql
5. Install the mysql yum source and compare the yum sources before and after (rpm -ivh)
6. Can it work normally?
7. Install mysql service
8. View configuration files and data storage locations
9. Start the service (systemctl start)
10. Check the startup service
11. Login method one
12. Login method two
13. Login method three
14. Set up startup
15. Configure my.cnf
16. FAQ
0.Description
- During installation and uninstallation, switch all computers to root. Once installed, ordinary computers can use it.
- Mysql does not enter the database management, all use root to enter the database, master mysql statements, and learn database management, then consider creating a new ordinary database.
1. Check the environment (systemctl start/stop/restart)
1. Check whether MySQL or mariadb exists in the system
(mariadb is an open source branch of MySQL), and MySQL can be used directly
[root@VM-4-10-centos /]# ps axj | grep mysql 8577 10898 10897 17609 pts/2 10897 S + 0 0:00 grep --color=auto mysql 1 20559 20558 20558 ? -1 Sl 27 25:33 /usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid [root@VM-4-10-centos /]# ps axj | grep mariadb 8577 10978 10977 17609 pts/2 10977 S + 0 0:00 grep --color=auto mariadb2. Determine the MySQL version
[root@VM-4-10-centos /]# which mysql /usr/bin/mysql [root@VM-4-10-centos /]# mysql --version mysql Ver 14.14 Distrib 5.7.43, for Linux (x86_64) using EditLine wrapper3. Use Linux script program to terminate the MySQL service, systemctl stop/restart/start, which is equivalent to suspending the daemon process.
[root@VM-4-10-centos /]# systemctl stop mysqld [root@VM-4-10-centos /]# [root@VM-4-10-centos /]# ps axj | grep mariadb 8577 12824 12823 17609 pts/2 12823 S + 0 0:00 grep --color=auto mariadb
2. Check the system installation package (rpm -qa)
Use the system command rpm to check the MySQL installation package installed on the system
[root@VM-4-10-centos /]# rpm -qa | grep mysql mysql57-community-release-el7-9.noarch mysql-community-libs-5.7.43-1.el7.x86_64 mysql-community-common-5.7.43-1.el7.x86_64 mysql-community-libs-compat-5.7.43-1.el7.x86_64 mysql-community-server-5.7.43-1.el7.x86_64 mysql-community-client-5.7.43-1.el7.x86_64
3. Uninstall these default installation packages (yum remove, xargs)
Use the system tool xargs to convert the content read from the standard output into the parameter argv line by line, pass it to yum, and uninstall line by line. You need to add the parameter -y. The yum uninstallation will ask, so the batch uninstallation will be interrupted.
[root@VM-4-10-centos /]# rpm -qa | grep mysql | xargs yum -y remove Loaded plugins: fastestmirror, langpacks Repository epel is listed more than once in the configuration Resolving Dependencies
4. Get mysql official yum source
Get the mysql official yum source http://repo.mysql.com/
View the Linux local yum source:
[root@VM-4-10-centos /]# ls /etc/yum.repos.d/ -l total 52 -rw-r--r-- 1 root root 615 Jul 20 18:00 CentOS-Base.repo -rw-r--r-- 1 root root 1309 Nov 23 2020 CentOS-CR.repo -rw-r--r-- 1 root root 649 Nov 23 2020 CentOS-Debuginfo.repo -rw-r--r-- 1 root root 230 Mar 21 2023 CentOS-Epel.repo -rw-r--r-- 1 root root 314 Nov 23 2020 CentOS-fasttrack.repo -rw-r--r-- 1 root root 630 Nov 23 2020 CentOS-Media.repo -rw-r--r-- 1 root root 1331 Nov 23 2020 CentOS-Sources.repo -rw-r--r-- 1 root root 8515 Nov 23 2020 CentOS-Vault.repo -rw-r--r-- 1 root root 616 Nov 23 2020 CentOS-x86_64-kernel.repo -rw-r--r-- 1 root root 1358 Sep 5 2021 epel.repo -rw-r--r-- 1 root root 1457 Sep 5 2021 epel-testing.repoRegarding installation version selection:
1. Determine your own system version. Centos should install el, Ubuntu should install Ubuntu, and SUSE should install sles.
[root@VM-4-10-centos /]# cat /etc/redhat-release CentOS Linux release 7.9.2009 (Core)2. It is best to install a mysql version that is consistent with the system, otherwise there may be software compatibility issues. The number after mysql in the yum source corresponds to the version. This example installs version 5.7 mysql157
3. Select the corresponding mysql157-release-el7.9.noarch.rpm according to the system version 7.9
5. Install the mysql yum source, compare the before and after yum sources (rpm -ivh)
1. Use the system command rz to upload the yum source
[root@VM-4-10-centos 1Lesson]# ls mysql57-community-release-el7-9.noarch.rpm [root@VM-4-10-centos 1Lesson]# rz2. Using the system command rpm -ivh is equivalent to unpacking and decompressing the yum source.
[root@VM-4-10-centos 1Lesson]# ls mysql57-community-release-el7-9.noarch.rpm [root@VM-4-10-centos 1Lesson]# ls /etc/yum.repos.d/ -l total 52 -rw-r--r-- 1 root root 615 Jul 20 18:00 CentOS-Base.repo -rw-r--r-- 1 root root 1309 Nov 23 2020 CentOS-CR.repo -rw-r--r-- 1 root root 649 Nov 23 2020 CentOS-Debuginfo.repo -rw-r--r-- 1 root root 230 Mar 21 2023 CentOS-Epel.repo -rw-r--r-- 1 root root 314 Nov 23 2020 CentOS-fasttrack.repo -rw-r--r-- 1 root root 630 Nov 23 2020 CentOS-Media.repo -rw-r--r-- 1 root root 1331 Nov 23 2020 CentOS-Sources.repo -rw-r--r-- 1 root root 8515 Nov 23 2020 CentOS-Vault.repo -rw-r--r-- 1 root root 616 Nov 23 2020 CentOS-x86_64-kernel.repo -rw-r--r-- 1 root root 1358 Sep 5 2021 epel.repo -rw-r--r-- 1 root root 1457 Sep 5 2021 epel-testing.repo [root@VM-4-10-centos 1Lesson]# rpm -ivh mysql57-community-release-el7-9.noarch.rpm Preparing... ################################# [100%] Updating/installing... 1:mysql57-community-release-el7-9 ################################ [100%] [root@VM-4-10-centos 1Lesson]# ls /etc/yum.repos.d/ -l total 60 -rw-r--r-- 1 root root 615 Jul 20 18:00 CentOS-Base.repo -rw-r--r-- 1 root root 1309 Nov 23 2020 CentOS-CR.repo -rw-r--r-- 1 root root 649 Nov 23 2020 CentOS-Debuginfo.repo -rw-r--r-- 1 root root 230 Mar 21 2023 CentOS-Epel.repo -rw-r--r-- 1 root root 314 Nov 23 2020 CentOS-fasttrack.repo -rw-r--r-- 1 root root 630 Nov 23 2020 CentOS-Media.repo -rw-r--r-- 1 root root 1331 Nov 23 2020 CentOS-Sources.repo -rw-r--r-- 1 root root 8515 Nov 23 2020 CentOS-Vault.repo -rw-r--r-- 1 root root 616 Nov 23 2020 CentOS-x86_64-kernel.repo -rw-r--r-- 1 root root 1358 Sep 5 2021 epel.repo -rw-r--r-- 1 root root 1457 Sep 5 2021 epel-testing.repo -rw-r--r-- 1 root root 1416 Sep 12 2016 mysql-community.repo -rw-r--r-- 1 root root 1440 Sep 12 2016 mysql-community-source.repo3. Observe mysql-community.repo, which has various versions of MySQL, yum links and client servers. yum will find the most suitable yum source according to the system.
1 [mysql-connectors-community] 2 name=MySQL Connectors Community 3 baseurl=http://repo.mysql.com/yum/mysql-connectors-community/el/7/$basearch/ 4 enabled=1 5 gpgcheck=1 6 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql 7 8 [mysql-tools-community] 9 name=MySQL Tools Community 10 baseurl=http://repo.mysql.com/yum/mysql-tools-community/el/7/$basearch/ 11 enabled=1 12 gpgcheck=1 13 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql 14 15 # Enable to use MySQL 5.5 16 [mysql55-community] 17 name=MySQL 5.5 Community Server 18 baseurl=http://repo.mysql.com/yum/mysql-5.5-community/el/7/$basearch/ 19 enabled=0 20 gpgcheck=1 21 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql twenty two 23 # Enable to use MySQL 5.6 24 [mysql56-community] 25 name=MySQL 5.6 Community Server 26 baseurl=http://repo.mysql.com/yum/mysql-5.6-community/el/7/$basearch/ 27 enabled=0 28 gpgcheck=1 29 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
6. Can it work normally
Use yum to search for mysql to see if it can work successfully. Obtain the mysql image or installation package from the corresponding website according to the yum source.
[root@VM-4-10-centos 1Lesson]# yum list | grep mysql Repository epel is listed more than once in the configuration mysql57-community-release.noarch el7-9 installed akonadi-mysql.x86_64 1.9.2-4.el7 os anope-mysql.x86_64 2.0.14-1.el7 epel apr-util-mysql.x86_64 1.5.2-6.el7_9.1 updates calligra-kexi-driver-mysql.x86_64 2.9.10-2.el7 epel collectd-mysql.x86_64 5.8.1-1.el7 epel dmlite-plugins-mysql.x86_64 1.15.2-15.el7 epel dovecot-mysql.x86_64 1:2.2.36-8.el7 os dpm-copy-server-mysql.x86_64 1.13.0-1.el7 epel dpm-name-server-mysql.x86_64 1.13.0-1.el7 epel
7. Install mysql service
1. There is no mysql service, client, or configuration file before installation.
[root@VM-4-10-centos 1Lesson]# which mysql /usr/bin/which: no mysql in (/usr/local/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/home/customer/.local/bin:/home/customer/ bin) [root@VM-4-10-centos 1Lesson]# which mysqld /usr/bin/which: no mysqld in (/usr/local/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/home/customer/.local/bin:/home/customer/ bin) [root@VM-4-10-centos 1Lesson]# ls /etc/my.cf ls: cannot access /etc/my.cf: No such file or directory2. Use yum install to install mysql-community-server, which will install all server, client, development libraries, public components, etc.
[root@VM-4-10-centos 1Lesson]# yum install -y mysql-community-server Loaded plugins: fastestmirror, langpacks Repository epel is listed more than once in the configuration Loading mirror speeds from cached hostfile3. Installation successful
[root@VM-4-10-centos 1Lesson]# which mysql /usr/bin/mysql [root@VM-4-10-centos 1Lesson]# which mysqld /usr/sbin/mysqld [root@VM-4-10-centos 1Lesson]# ls /etc/my.cnf /etc/my.cnf4. If the installation fails, jump to step 16
8. View the configuration file and data storage location
View the configuration file /etc/my.cnf
# For advice on how to change settings please see # http://dev.mysql.com/doc/refman/5.7/en/server-configuration-defaults.html [mysqld] # # Remove leading # and set to the amount of RAM for the most important data # cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%. # innodb_buffer_pool_size = 128M # # Remove leading # to turn on a very important data integrity option: logging # changes to the binary log between backups. # log_bin # # Remove leading # to set options mainly useful for reporting servers. # The server defaults are faster for transactions and fast SELECTs. # Adjust sizes as needed, experiment to find the optimal values. # join_buffer_size = 128M # sort_buffer_size = 2M # read_rnd_buffer_size = 2M datadir=/var/lib/mysql socket=/var/lib/mysql/mysql.sock # Disabling symbolic-links is recommended to prevent assorted security risks symbolic-links=0 log-error=/var/log/mysqld.log pid-file=/var/run/mysqld/mysqld.pid
9. Start the service (systemctl start)
Start the mysql server mysqld
[root@VM-4-10-centos 1Lesson]# systemctl start mysqld [root@VM-4-10-centos 1Lesson]# ps axj | grep mysqld 1 3696 3695 3695 ? -1 Sl 27 0:00 /usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid 8577 3806 3805 17609 pts/2 3805 S + 0 0:00 grep --color=auto mysqld
10. View the startup service
Check the mysqld service port number, TCP protocol, and application layer services (network services: have their own protocols)
[root@VM-4-10-centos 1Lesson]# netstat -nltp Active Internet connections (only servers) Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 1164/sshd tcp6 0 0 :::22 :::* LISTEN 1164/sshd tcp6 0 0 :::3306 :::* LISTEN 3696/mysqld
11. Login method one
#Get temporary root password
[root@VM-4-10-centos 1Lesson]# grep 'temporary password' /var/log/mysqld.log 2022-10-17T08:56:20.292348Z 1 [Note] A temporary password is generated for root@localhost: 5xk/,!/t)5Pl#Use temporary password to log in
#Determine whether the new password complies with the current policy when changing the password. If you are not satisfied? Report an error, do not allow modification, and close it. #Security strength, the default is medium, that is, 1. It is required to contain numbers, symbols, “writing”, and “less”. for 8 bits
mysql> set global validate_password_policy=0;
Query OK, 0 rows affected (0.00 sec)
#Set password minimum
mysql> set global validate_password_length=1;
Query OK, 0 rows affected (0.00 sec)
#Modify the local login password and disable remote login for the time being.
mysql> ALTER USER ‘root’@’localhost’ IDENTIFIED BY ‘root.888’;
Query OK, 0 rows affected (0.00 sec)
mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.00 sec)
#If you install the latest mysql, there is no so-called temporary password, and root has no password by default.
12. Login method two
# If you install the latest mysql, there is no so-called temporary password, and root has no password by default.
# Try to log in directly with the client? Next
13. Login method three
1. Open the mysql configuration file
[root@VM-4-10-centos 1Lesson]# vim /etc/my.cnfConfigure 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.
2. Restart the service systemctl restart
3. Log in again
[root@VM-4-10-centos 1Lesson]# mysql -u root -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 2 Server version: 5.7.44 MySQL Community Server (GPL)
14. Set up startup
#Turn on boot?Start
systemctl enable mysqld
systemctl daemon-reload
15. Configure my.cnf
#Configure my.conf, mainly the encoding format of the database client and server
#default-character-set=utf8, do not set it yet, mysql has a bug, Chinese characters are not echoed
character-set-server=utf8
default-storage-engine=innodb
# After the configuration is completed, restart mysql.
16. Frequently Asked Questions
1. The installation encounters the problem of expired keys (the server is a unified environment, and some keys are expired during packaging):
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
Solution: Execute this command to update the secret key (mainly used for MySQL secure communication to prevent handshake failure):
rpm –import https://repo.mysql.com/RPM-GPG-KEY-mysql-2022
2. Mysql has been configured with client server utf8 encoding, but the input fails.
Make sure you can type in the terminal command?
[root@VM-0-3-centos ~]$ env | grep LANG LANG=en_US.utf8