Detailed installation process of MySQL5.7.26 under Linux

Preface
Compared with the MySQL installation under Windows, the installation in the Linux environment will be more cumbersome. My virtual machine is CentOS7.4, and the decompressed version tar.gz package is installed, the version is 5.7.26 (5.7 and above are recommended)

Step 1: Download, upload, unzip

1. Address : https://dev.mysql.com/downloads/mysql/5.7.html#downloads
download link
download page
2. Upload and decompress

(1) Enter the /usr/local directory and upload the downloaded compressed package (I use the rz command to upload local files)

[root@localhost /]# cd /usr/local/
[root@localhost local]# rz

upload
(2) Then decompress

[root@localhost local]# tar -zxvf mysql-5.7.26-linux-glibc2.12-x86_64.tar.gz

(3) After decompression, because the folder name is too long, it is renamed to mysql for convenience (so the directory structure is /usr/local/mysql)

[root@localhost local]# mv mysql-5.7.26-linux-glibc2.12-x86_64 mysql

(4) Delete the original compressed package (after all, it is hundreds of megabytes, there is no need to keep it to occupy space, or move it to other places)

[root@localhost local]# rm -f mysql-5.7.26-linux-glibc2.12-x86_64.tar.gz

Table of contents

Step Two: Install

1. Check whether there is mysql related (generally the first installation will not have it)

[root@localhost local]# rpm -qa | grep mysql

If it shows mysql-xx or something, delete it, the command is: rpm -e --nodeps shows the file name, and then check mariadb

[root@localhost local]# rpm -qa | grep mariadb

Similarly, if mariadb-xx is displayed, delete it, and the instruction is the same as above

2. Add mysql user group and mysql user (meaning add the created mysql user to the mysql group)

[root@localhost local]# groupadd mysql
[root@localhost local]# useradd -r -g mysql mysql

3. Grant permissions (meaning that the mysql user group and mysql user have the permission to operate the directory)

[root@localhost local]# chown -R mysql mysql
[root@localhost local]# chgrp -R mysql mysql

4. Create a configuration file (create it directly through vi, paste the following content, save and exit with wq, pay attention to the paths such as basedir and datadir)

[root@localhost local]# cd mysql/
[root@localhost mysql]# vi /etc/my.cnf
[mysqld]
port=3306
basedir=/usr/local/mysql
datadir=/usr/local/mysql/data
socket=/tmp/mysql.sock
user=mysql
tmpdir=/tmp
bind-address = 0.0.0.0
max_connections=200
character-set-server=utf8mb4
collation-server=utf8mb4_general_ci
default-storage-engine=INNODB
innodb_buffer_pool_size=64MB
max_allowed_packet=16M
skip-name-resolve

[mysqld_safe]
log-error=/usr/local/mysql/data/error.log
pid-file=/usr/local/mysql/data/mysql.pid

[mysql]
default-character-set=utf8mb4

[client]
socket=/tmp/mysql.sock
default-character-set=utf8mb4

5. Initialization

(1) Install a libaio first (some virtual machines may already have this, anyway, it is not a loss to execute it once)

[root@localhost mysql]# yum -y install libaio

(2) Create a data directory (according to the configuration directory above)

[root@localhost mysql]# mkdir data

(3) Initialization (mysql directory /usr/local/mysql, the focus is to copy and remember the password generated by initialization, which will be used later)

[root@localhost mysql]# ./bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data

initialization

Step 3: Start Configuration

1. Set the boot to start automatically

(1) Copy mysql.server to init.d/mysql (it doesn’t matter if there is no mysql folder under init.d, just execute the following sentence directly)

[root@localhost mysql]# cp support-files/mysql.server /etc/init.d/mysql

(2) Add executable permissions (this step can not be executed, go directly to the third part)

[root@localhost mysql]# chmod +x /etc/init.d/mysql

(3) Add mysql service

[root@localhost mysql]# chkconfig --add mysql

(4) View the service list (if 3 4 5 is off, execute: chkconfig --level 345 mysql on)

[root@localhost mysql]# chkconfig --list

insert image description here
(5) Add mysql system commands

[root@localhost mysql]# vi /etc/profile

After adding the following two sentences, execute source /etc/profile to make the configuration take effect immediately

export MYSQL_HOME=/usr/local/mysql
export PATH=$MYSQL_HOME/bin:$PATH
[root@localhost mysql]# source /etc/profile

2. Start the mysql service

(1) command start

[root@localhost mysql]# service mysql start

start up
(2) Log in (press Enter after entering -p, and then paste the password generated by the above initialization, if you cannot see it after pasting, it will not affect it, just press Enter)

[root@localhost mysql]# ./bin/mysql -u root -p

log in
(3) Change the password (a semicolon should be added at the end of the command entered after mysql>; my password here is set to mysql, which is optional; the second sentence should correspond to the set password)

set password=password('mysql');
grant all privileges on *.* to root@'%' identified by 'mysql';
flush privileges;

change Password
(4) Set remote access permissions (after execution, enter quit to exit, exit without a semicolon)

use mysql;
update user set user.Host='%' where user.User='root';
select host from user where user = 'root';
flush privileges;

insert image description here
3. Restart the mysql service

[root@localhost mysql]# service mysql restart

main command

Start: service mysql start
Shut down: service mysql stop
Status: service mysql status

Test the connection with the SQLyog tool
connection test
successfully, mysql is installed in the Linux environment, and you can go to eat.

Guess you like

Origin blog.csdn.net/qq_36737803/article/details/93997497