Install MySQL8.0.16 at RPM in CentOS7.

First, preparation

1. Download the installation package required by MySQL

You can also use the wget command to download the MySQL version 8.0.16.

# The version you wantThe Product Version: 8.0.16CentOS Select Red Hat Enterprise Linux/Oracle Linux
Operating System:OS Version: Red Hat Enterprise Linux / Oracle Linux
# CentOS7 64-bit option
OS Version: Red Hat Enterprise Linux 7 / Oracle Linux 7 (x86, 64-bit)
Copy the code

Then download the RPM Bundle.

2. Check whether the mariadb is built-in

CentOS7 does not come with MySQL at first, but mariadb is replaced. However, when we install MySQL, there will be a conflict, so we need to uninstall Mariadb first.

# Check to see if mariadb comes with it
rpm -qa | grep mariadb

Mariadb-libs-5.5.60-1.el7_5.x86_64 = mariadb-libs-5.5.60-1.el7_5.x86_64The RPM -e mariadb - libs - 5.5.60-1. El7_5. X86_64 -- nodepsCopy the code

3. Check whether MySQL has been installed

# check whether mysql is installed
rpm -qa | grep mysql

Mysql > uninstall mysql-libs-5.1.52.x86_64The RPM -e mysql - libs - 5.1.52. X86_64 -- nodepsCopy the code

4. Check whether the mysql group and users exist. If no, create the mysql group

# check
cat /etc/group | grep mysql
cat /etc/passwd | grep mysql

# to create
groupadd mysql
useradd -r -g mysql mysql
Copy the code

5. Check whether the MySQL port is enabled

The default port I use is 3306.

FirewallD = FirewallD = FirewallD = FirewallD = FirewallD = FirewallD = FirewallD = FirewallD = FirewallD = FirewallD
firewall-cmd --query-port=3306/tcp

# Enable the port. Success indicates success
firewall-cmd --add-port=3306/tcp --permanent
# Refresh the configuration for the configuration to take effect
firewall-cmd --reload
Copy the code

Install and configure MySQL

1. Unpack the

cd /usr/local/mysql

# decompressionTar XVF mysql - 8.0.16-2. El7. X86_64. RPM - bundle. The tarTake a look at the decompressed files
ll
# the results-rw-r--r--. 1 7155 31415 33432660 5月 3 2019 mysql-community-client-8.0.16-2.el7.x86_64. RPM -rw-r--r--. 1 7155 31415 588520 5月 3 2019 mysql-community-common-8.0.16-2.el7.x86_64. RPM -rw-r--r-- 1 7155 31415 5712552 5月 3 2019 Mysql -community-devel-8.0.16-2.el7.x86_64. RPM -rw-r--r-- 1 7155 31415 24493344 5月 3 2019 RPM -rw-r--r-- 1 7155 31415 3127296 5月 3 2019 RPM -rw-r--r-- 1 7155 31415 2177156 5月 3 2019 RPM -rw-r--r-- 1 7155 31415 422672748 5月 3 2019 RPM -rw-r--r-- 1 7155 31415 114848996 5月 3 2019 Mysql - community - test - 8.0.16-2. El7. X86_64. RPMCopy the code

2. Run the RPM command to install common

# commandThe RPM - the ivh mysql - community - common - 8.0.16-2. El7. X86_64. RPM# Print contentWarning: mysql-community-common-8.0.16-2.el7.x86_64. RPM: header V3 DSA/SHA1 Signature, key ID 5072e1F5: NOKEY Preparing...# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # [100%]Upgrading/installing... 1: mysql - community - common - 8.0.16-2. E# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # [100%]
Copy the code

3. Run the RPM command to install the LIbs

# commandThe RPM - the ivh mysql - community - libs - 8.0.16-2. El7. X86_64. RPM# Print contentWarning: mysql-community-libs-8.0.16-2.el7.x86_64. RPM: header V3 DSA/SHA1 Signature, key ID 5072e1F5: NOKEY Preparing...# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # [100%]Upgrading/installing... 1: mysql - community - libs - 8.0.16-2. El7# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # [100%]
Copy the code

4. Run the RPM command to install client

# commandThe RPM - the ivh mysql - community - the client - 8.0.16-2. El7. X86_64. RPM# Print contentWarning: mysql-community-client-8.0.16-2.el7.x86_64. RPM: header V3 DSA/SHA1 Signature, key ID 5072e1F5: NOKEY Preparing...# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # [100%]Upgrading/installing... 1: mysql - community - the client - 8.0.16-2. E# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # [100%]
Copy the code

5. Run RPM to install the server

Yum -y install net-tools* install net-tools*

# commandRPM - the ivh mysql - community - server - 8.0.16-2. El7. X86_64. RPM# Print contentWarning: mysql-community-server-8.0.16-2.el7.x86_64. RPM: header V3 DSA/SHA1 Signature, key ID 5072e1F5: NOKEY Preparing...# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # [100%]Upgrading/installing... 1: mysql - community - server - 8.0.16-2. E# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # [100%]
Copy the code

6. View the MySQL installation package

# command
rpm -qa | grep mysql

# Print contentMysql - community - libs - 8.0.16-2. El7. X86_64 mysql - community - common - 8.0.16-2. El7. X86_64 Mysql - community - the client - 8.0.16-2. El7. X86_64 mysql - community - server - 8.0.16-2. El7. X86_64Copy the code

7. Initialize the MySQL database

This command generates a random password in /var/log/mysqld.log.

mysqld --initialize
Copy the code

8. Configure user groups

The default MySQL configuration file path is /etc/my.cnf. You can modify the configuration file if necessary.

chown mysql:mysql /var/lib/mysql -R
Copy the code

9. Start the MySQL database

# start mysqld. Service
systemctl start mysqld

If running is displayed, the startup is successful
systemctl status mysqld
Copy the code

10. Change the database password

Check the database password
cat /var/log/mysqld.log | grep password

4M4pSDfcr=9o is the database password
2020-04-03T14:34:28.837144Z 5 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: 4M4pSDfcr=9o
Copy the code
Log in to the MySQL database using the obtained password-u root -p'4M4pSDfcr=9o'# change password to custom password after logging in to MySQL123456), this setting is fine5.7What about the different versionsALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '123456'; # use ` exit; 'Exit MySQL and log in again using a custom passwordCopy the code

11. Create a user and authorize remote login

Do not use version 5.7, or an error will be reported.

mysql> GRANT ALL PRIVILEGES ON *.* TO 'SunnyBear'@'%' IDENTIFIED BY '123456'; ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'IDENTIFIED BY '123456''  at line 1Copy the code

In version 8.0, you need to create a user and then grant permission to the user.

Since the normal root user is not allowed to log in remotely under normal development, we created a SunnyBear user with permission to use the Sunny database (already created using the command).

Create a user named mysql> CREATE USER 'SunnyBear'@The '%' IDENTIFIED BY '123456';
Query OK, 0 rows affected (0.00SEC) # authorized # therein Sunny.*Indicates grant all operation rights to sunny database. If you want to grant all operation rights to Sunny database, set this parameter to*.*# which'SunnyBear'@The '%'Represents allows SunnyBear users to log in at any IP, although IP can also be specified, for example'User name'@'IP address'
mysql> GRANT ALL PRIVILEGES ON sunny.* TO 'SunnyBear'@The '%' WITH GRANT OPTION;
Query OK, 0 rows affected (0.00SEC) # FLUSH PRIVILEGES;Copy the code

After the configuration is successful, you can use the connection tool to try to connect. I used Navicat here, so far, the standalone version of MySQL installation and configuration is complete.

12. Some commands

Start the mysql service
systemctl start mysqld.service

# stop mysql service
systemctl stop mysqld.service

Restart the mysql service
systemctl restart mysqld.service

Check the current status of the mysql server
systemctl status mysqld.service

Mysql server startup
systemctl enable mysqld.service

# stop mysql service startup after startup
systemctl disable mysqld.service
Copy the code

Now that you’ve read this, please like, comment, follow and bookmark it!

Author: IT wang2 xiao3 er4 starting address: www.itwxe.com/posts/79382… Copyright notice: The content of this article is licensed by authorship – non-commercial use – No Interpretation 4.0 international.