Install a prelude to

1: Download the mysql tar.gz package 5.7 or later from the official website

Download: Link

2: Create mysql users and user groups in Linux as user root

2.1: Creating a Group [root@localhost]# groupadd mysql2.2: Creating a User and adding the user to a group [root@localhost]# useradd -r -g mysql mysql2.3: Disable mysql users from logging in to the system (optional prevent others from logging in to the host as mysql users) [root@localhost]# usermod -s /bin/false mysql
Copy the code

Mysql /opt/mysql/

3.1: Decompress files [root@localhost]# tar XVF mysql - 5.7.21 - Linux - glibc2.12 - x86_64. Tar. Gz3.2: Change the decompressed directory name [root@localhost]# mysql - 5.7.21 - Linux - mv glibc2.12 x86_64 mysql -- 5.7.213.3: Changing the Owning Users and Groups of a Directory [root@localhost]# chown -R mysql mysql/
    
    [root@localhost]# chgrp -R mysql mysql/
Copy the code

Mysql > install Mysql

  1. Go to /opt/mysql/mysql-5.7.21/support-files and check whether my_default. CNF exists.

1.1. Create the my_default. CNF file in the support-files directory

    [root@localhost]# mkdir my_default.cnf
Copy the code

1.2. Copy the following into the file

# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.6/en/server-configuration-defaults.html
# *** DO NOT EDIT THIS FILE. It's a template which will be copied to the
# *** default location during install, and will be replaced if you
# *** upgrade to a newer version of MySQL.

[client]

port = 3306
socket = /opt/mysql/mysql.sock

[mysqld]

# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
# innodb_buffer_pool_size = 128M

# Remove leading # to turn on a very important data integrity option: logging
# changes to the binary log between backups.
# log_bin

# These are commonly set, remove the # and set as required.
# basedir = .....
# datadir = .....
# port = .....
# server_id = .....
# socket = .....
#skip-grant-tables #skip login validation
#innodb_force_recovery=1Basedir = /opt/mysql/mysql-5.7.21/ datadir = /opt/mysql/data/ port = 3306 server_id = 1 socket = /opt/mysql/mysql.sock Language = / opt/mysql/mysql - 5.7.21 / share/English# the log - bin = / opt/mysql/mysql - 5.7.21 / mysql - bin
expire_logs_days = 10
max_binlog_size = 100M

#general_log = 1
# general_log_file = / opt/mysql/mysql - 5.7.21 / logs/query logSlow_query_log = 1 slow_query_log_file = /opt/mysql/mysql-5.7.21/logs/slow-query.log long-query_time = 2log- error = / opt/mysql/mysql - 5.7.21 / logs/error log# Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
# join_buffer_size = 128M
# sort_buffer_size = 2M
# read_rnd_buffer_size = 2M

sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES

Copy the code
  1. Move the file to the /etc/directory and rename it
1: mysql starts to read the configuration file /etc/my. CNF by default. Run the following command to move the file to this directory: [root@localhost support-files]# mv my_default.cnf /etc/my.cnf
Copy the code
  1. Move /opt/mysql/mysql-5.7.21/supprot-files/mysql.server to /etc/init.d/
[root@localhost]# mv/opt/mysql/mysql - 5.7.21 / supprot - files/mysql server/etc/init. D/mysqld
Copy the code

4. Create the mysql data storage directory and log directory

1: Create a data directory [root@localhost]# mkdir /opt/mysql/data2: Create log directory and log file, if not create start error [root@localhost]# mkdir/opt/mysql/mysql - 5.7.21 / logs

[root@localhost]# touch/opt/mysql/mysql - 5.7.21 / logs/error log

Copy the code
  1. Configure the my.cnf file
1: modify my.cnf [root@localhost etc]# vi /etc/my.cnfBasedir = /opt/mysql/mysql-5.7.21 (mysql installation directory) datadir = /opt/mysql/data (data path created in the previous step) socket = /opt/mysql/mysql.sock (The file will be automatically created in the location you specify.)log* configuration: just need to change somelogThe logs directory was created in the previous steplog/opt/mysql/mysql-5.7.21/logsCopy the code
  1. Everything is ready for installation service
1: Go to the Mysql bin directory and run the [root@localhost bin] command./mysqld --initialize -- insecure --user=mysql --basedir=/opt/mysql/mysql-5.7.21/ --datadir=/opt/mysql/data/If there is no ERROR, the installation is successfulCopy the code

7: Starts the service

Go to /etc/init.d/ and run the following command: [root@localhost init.d]./mysqld start

If Mysql Start SUCCESS is displayed, the database is successfully executed

8: Connects to the mysql server

1. Go to the mysql bin directory and run the [root@localhost bin]./mysql -uroot -p commandCopy the code

9: The root password is forgotten

1. Stop the started service [root@localhost init.d]./mysqld stop 2. CNF file [root@localhost etc] vi my.cnf add skip-grant-tables# skip login authentication/mysqld start 4. /mysql 5. Log in to the mysql server and change the root password. Because the password field is not displayed in version 5.7 or later, run the following SQL command to change the password: mysql> update mysql.userset authentication_string=password('root1234') where user='root' and Host = 'localhost';
mysql> flush privileges;
mysql> exit; 6: Delete my.cnf and restart mysql. The mysql installation is completeCopy the code