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

11 ways to remove duplicates from js arrays

In actual work or interviews, we often encounter ...

Python3.6-MySql insert file path, the solution to lose the backslash

As shown below: As shown above, just replace it. ...

MYSQL stored procedures, that is, a summary of common logical knowledge points

Mysql stored procedure 1. Create stored procedure...

Vue handwriting loading animation project

When the page is not responding, displaying the l...

The unreasonable MaxIdleConns of MySQL will cause short connections

1 Background Recently, some performance issues ha...

What is Software 404 and 404 Error and what is the difference between them

First of all, what is 404 and soft 404? 404: Simpl...

How Web Designers Create Images for Retina Display Devices

Special statement: This article is translated bas...

How to create a swap partition file in Linux

Introduction to Swap Swap (i.e. swap partition) i...

Html sample code for reading and displaying pictures in a local folder

One purpose Select a local folder on the Html pag...

Webpack file packaging error exception

Before webpack packaging, we must ensure that the...

Docker dynamically exposes ports to containers

View the IP address of the Container docker inspe...

MySQL index principle and usage example analysis

This article uses examples to illustrate the prin...

Tomcat parses XML and creates objects through reflection

The following example code introduces the princip...

How to quickly install tensorflow environment in Docker

Quickly install the tensorflow environment in Doc...