Install MySQL 5.7 under CentOS 7.3

Posted by cdwhalley.com on Thu, 09 Jul 2020 18:16:54 +0200

1. Download

Download address:
https://dev.mysql.com/downloads/mysql/

Select the version you need to install, where my computer is CentOS7.3 64 bit

Then download RPM Bundle, a collection of several programs.

Then start downloading...

2. Unzip the installation package

Unzip mysql-5.7.20-1.el7.x86_64.rpm-bundle.tar

 #tar -xvf mysql-5.7.20-1.el7.x86_64.rpm-bundle.tar

mysql-community-client-5.7.20-1.el7.x86_64.rpm
mysql-community-common-5.7.20-1.el7.x86_64.rpm
mysql-community-devel-5.7.20-1.el7.x86_64.rpm
mysql-community-embedded-5.7.20-1.el7.x86_64.rpm
mysql-community-embedded-compat-5.7.20-1.el7.x86_64.rpm
mysql-community-embedded-devel-5.7.20-1.el7.x86_64.rpm
mysql-community-libs-5.7.20-1.el7.x86_64.rpm
mysql-community-libs-compat-5.7.20-1.el7.x86_64.rpm
mysql-community-minimal-debuginfo-5.7.20-1.el7.x86_64.rpm
mysql-community-server-5.7.20-1.el7.x86_64.rpm
mysql-community-server-minimal-5.7.20-1.el7.x86_64.rpm
mysql-community-test-5.7.20-1.el7.x86_64.rpm
#ls

-rw-r--r-- 1 7155 31415  25090196 Sep 14 23:44 mysql-community-client-5.7.20-1.el7.x86_64.rpm
-rw-r--r-- 1 7155 31415    278300 Sep 14 23:44 mysql-community-common-5.7.20-1.el7.x86_64.rpm
-rw-r--r-- 1 7155 31415   3778120 Sep 14 23:44 mysql-community-devel-5.7.20-1.el7.x86_64.rpm
-rw-r--r-- 1 7155 31415  46238924 Sep 14 23:44 mysql-community-embedded-5.7.20-1.el7.x86_64.rpm
-rw-r--r-- 1 7155 31415  24077232 Sep 14 23:44 mysql-community-embedded-compat-5.7.20-1.el7.x86_64.rpm
-rw-r--r-- 1 7155 31415 128440800 Sep 14 23:44 mysql-community-embedded-devel-5.7.20-1.el7.x86_64.rpm
-rw-r--r-- 1 7155 31415   2238604 Sep 14 23:44 mysql-community-libs-5.7.20-1.el7.x86_64.rpm
-rw-r--r-- 1 7155 31415   2115892 Sep 14 23:44 mysql-community-libs-compat-5.7.20-1.el7.x86_64.rpm
-rw-r--r-- 1 7155 31415  55538708 Sep 14 23:44 mysql-community-minimal-debuginfo-5.7.20-1.el7.x86_64.rpm
-rw-r--r-- 1 7155 31415 171597916 Sep 14 23:45 mysql-community-server-5.7.20-1.el7.x86_64.rpm
-rw-r--r-- 1 7155 31415  15256460 Sep 14 23:45 mysql-community-server-minimal-5.7.20-1.el7.x86_64.rpm
-rw-r--r-- 1 7155 31415 118609776 Sep 14 23:45 mysql-community-test-5.7.20-1.el7.x86_64.rpm

3. Installation

Uninstall installed mysql-libs

# rpm -qa | grep -i mysql
mysql-libs-5.1.73-8.el6_8.x86_64

#yum remove mysql-libs

install

 rpm -ivh  mysql-community-common-5.7.20-1.el7.x86_64.rpm
 rpm -ivh  mysql-community-libs-5.7.20-1.el7.x86_64.rpm
 rpm -ivh  mysql-community-libs-compat-5.7.20-1.el7.x86_64.rpm
 rpm -ivh  mysql-community-client-5.7.20-1.el7.x86_64.rpm
 rpm -ivh  mysql-community-server-5.7.20-1.el7.x86_64.rpm
 rpm -ivh  mysql-community-devel-5.7.20-1.el7.x86_64.rpm 

The configuration file for MySQL is located at: /etc/my.cnf, modify the configuration to suit your needs
Default datadir=/var/lib/mysql

mysql start

# systemctl start mysqld

4. Initialization

Once installed this way, theMysqld.logA password is automatically generated in the file. Take a look at it:

# cat /var/log/mysqld.log | grep password
 2017-05-13T05:39:44.497086Z 1 [Note] A temporary password is generated for root@localhost: pKsO:Jin<4f%

Passwords are so complex. Copy them, or you can easily make mistakes if you lose them.

Land:

#mysql -u root -p
Enter password:pKsO:Jin<4f%

mysql>

After entering the initial password, you can log in.
You need to reset your password after login. If you do not reset your password, you will not be allowed to operate

mysql> show databases;
ERROR 1820 (HY000): You must SET PASSWORD before executing this statement 

Here you can change the root user password directly using the command

SET PASSWORD = PASSWORD('passwd');

5. Create Users

Sign in

# mysql -u root -p 
Enter password: 
mysql>

Create a database specifying the encoding utf-8:

mysql> CREATE DATABASE db182915 DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;

Add user test:

mysql> GRANT ALL PRIVILEGES ON db182915.* TO 'test'@'192.168.%' IDENTIFIED BY 'test123#' WITH GRANT OPTION;
mysql> flush privileges;

Topics: MySQL RPM Database yum