Tutorial on installing the unpacked version of mysql5.7 on CentOS 7

Tutorial on installing the unpacked version of mysql5.7 on CentOS 7

1. Unzip the mysql compressed package to the /usr/local folder and rename it to mysql

#Unzip

tar -zxf mysql-5.7.27-el7-x86_64.tar.gz -C /usr/local/ 

#Rename

cd /usr/local/
mv mysql-5.7.27-el7-x86_64/mysql 

2.

Enter mysql. Since 5.7 does not have a data directory, create one yourself.

cd mysql/
mkdir data 

3.

Create mysql user and user group

[root@airflow mysql]# groupadd mysql

[root@airflow mysql]# useradd -r -s /sbin/nologin -g mysql mysql -d /usr/local/mysql/

#The useradd -r parameter indicates that the mysql user is a system user and cannot be used to log in to the system. 4. Change the mysql directory permissions. Previously it was root permissions, now set it to mysql permissions

chown -R mysql:mysql /usr/local/mysql/ 

5.

Initialize the database

./bin/mysql_install_db --user=mysql --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data/ 

6.

Put mysql into the local system service

cp -a ./support-files/mysql.server /etc/init.d/mysqld

7. Since there is no my-default.cnf file in MySQL, edit the /etc/my.cnf file directly (you can also upload my-default.cnf)

vi my.cnf

[mysqld]

basedir=/usr/local/mysql

datadir=/usr/local/mysql/data

socket=/tmp/mysql.sock

user=mysql

port=3306

character-set-server = utf8mb4

collation-server = utf8mb4_unicode_ci

init_connect = 'SET NAMES utf8mb4'

symbolic-links=0

max_connections=200

default-storage-engine=INNODB

lower_case_table_names=1

max_allowed_packet=32M

explicit_defaults_for_timestamp=true

[mysqld_safe]

log-error=/var/log/mysql/mysql.log

pid-file=/var/run/mysql/mysql.pid

Note: mysql connects to localhost usually through a Unix domain socket file, usually /tmp/mysql.sock. Do not modify the socket path, otherwise you will get an error when connecting to the local mysql: ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock'

Because the log-error and pid-file paths are configured in my.cnf, you need to create mysql directories in /var/log/ and /var/run/ and give the mysql user full permissions (chmod)

chmod -R 777 /var/log/mysql/
chmod -R 777 /var/run/mysql/

Otherwise, an error will be reported when starting, as shown below

8.

Start mysql service

service mysqld start

9.

View the initial password and try to log in to MySQL

cat /root/.mysql_secret

10.

Login successful, change password

SET PASSWORD FOR 'root'@localhost=PASSWORD('123456'); 

11.

Configure mysql environment variables, modify the /etc/profile file, add configuration at the bottom, and add it to start automatically at boot.

vi /etc/profile

Add the following configuration:

export PATH=$PATH:/usr/local/mysql/bin

Effective immediately

source /etc/profile

12. Automatic startup configuration

chmod +x /etc/init.d/mysqld
chkconfig --add mysqld
chkconfig --list 

If you see the mysql service and 3, 4, and 5 are all on, then it is successful. If they are off, type

chkconfig --level 345 mysqld on

Then restart your computer

reboot

Check the running status of MySQL

service mysqld status

13.

Allow root account IP login

mysql -u root -p
use mysql;
update user set host = '%' where user = 'root';
FLUSH PRIVILEGES;

Configuration file example

[mysqld]
socket=/var/lib/mysql/mysql.sock
port = 3306
basedir=/softwares/mysql_5727
datadir=/softwares/mysql_5727/data
max_connections=200
character-set-server=utf8mb4
default-storage-engine=INNODB
lower_case_table_names=1
max_allowed_packet=32M
explicit_defaults_for_timestamp=true

You may also be interested in:
  • Detailed tutorial on installing MySQL 8.0 from source code on CentOS 7.4
  • Installation tutorial of mysql8.0rpm on centos7
  • Tutorial on installing lnmp using yum on centos7 (linux+nginx+php7.1+mysql5.7)
  • A concise tutorial on how to install mysql5.7 decompressed version on CentOS7
  • How to install and modify the initial password of mysql5.7.18 under Centos7.3
  • Detailed tutorial for installing mysql5.7.18 on centos7.3
  • CentOS7 uses rpm package to install mysql 5.7.18
  • How to install mysql5.6 on centos7

<<:  How to view files in Docker image

>>:  Play and save WeChat public account recording files (convert amr files to mp3)

Recommend

Introduction to document.activeELement focus element in JavaScript

Table of contents 1. The default focus is on the ...

Steps to enable MySQL database monitoring binlog

Preface We often need to do something based on so...

Create a custom system tray indicator for your tasks on Linux

System tray icons are still a magical feature tod...

Summary of seven MySQL JOIN types

Before we begin, we create two tables to demonstr...

Analysis of the HTML writing style and reasons of experienced people

1. Navigation: Unordered List vs. Other Label Ele...

MySQL SQL Optimization Tutorial: IN and RANGE Queries

First, let's talk about the in() query. It is...

Native JS to implement login box email prompt

This article shares a native JS implementation of...

Example code for making the pre tag automatically wrap

The pre element defines preformatted text. Text en...

How to implement Nginx configuration detection service status

1. Check whether the check status module is insta...

Computed properties and listeners details

Table of contents 1. Calculated properties 1.1 Ba...