In centos6.8 offline, tar custom installation of mysql5.7 and above versions

1. Check whether mysql has been installed, execute the command, if it exists, delete it first and then install it.

rpm -qa | grep mysql
rpm -e --nodeps file name

2. Query all folders corresponding to Mysql and delete related directories or files

whereis mysql and find / -name mysql
rm -rf absolute path to the file

3. Download the binary installation file, i.e. .tar.gz file

The download address is: https://downloads.mysql.com/archives/community/
Insert image description here

4. Create a mysql user, first create a mysql group, then create a mysql user and add it to the mysql group

groupadd mysql
useradd mysql -r -g mysql
#Verify user group and user id mysql

5. Create program and data storage directories

mkdir /home/mysql/{program,data,conf} -p
mkdir /home/mysql/data/mysqldata1/{mydata,sock,tmpdir,log,innodb_ts,innodb_log,undo,slowlog,binlog,relaylog} -p
#View Create the directory result tree /home/mysql.
If there is no such command, use yum install tree -y

6. Unzip the binary installation file and set directory permissions

Unzip the binary installation file to the /home/mysql/program directory, and modify the program, data storage path host, and group to mysql so that the MySQL user has full access to these directories and files.

tar -zxvf mysql.tar.gz file -C /home/mysql/program
chown mysql.mysql /home/mysql -R
#Check whether the permissions of the datadir key directory are correct
ll /home/mysql/data/mysqldata1/

7. Softly connect the program path and set the mysql command environment variable

Soft link the /home/mysql/program/mysql-5.6.35-linux-glibc2.5-x86_64 path to MySQL's default program access path /usr/local/mysql, and /usr/local/mysql/bin/ Add it to the system environment variables so that you do not need to enter the absolute path when using mysql related commands.

ln -s /home/mysql/program/mysql program/usr/local/mysql
#Check whether the key program directory basedir is available ll /usr/local/mysql
vim /etc/profile
followed by export PATH=$PATH:/usr/ local/mysql/bin/

8. Configure my.cnf file parameters

You need to create a new my-default.cnf in the /usr/local/mysql/support-files path,
cp -ar /usr/local/mysql/support-files/my-default.cnf /home/mysql/conf/my. cnf

ln -s /home/mysql/conf/my.cnf /etc/my.cnf

The content of my-default.cnf is as follows:
[client]
default-character-set=utf8
#password = your_password
port = 3306
socket = /home/mysql/data/mysqldata1/sock/mysql.sock #The path to the sock file

[mysqld]
explicit_defaults_for_timestamp=true
user=mysql
character-set-server=utf8
port = 3306
socket = /home/mysql/data/mysqldata1/sock/mysql.sock #sock file path
basedir = /usr/local/mysql
datadir = /home/mysql/data/mysqldata1/mydata #Data file path
pid-file = /home/mysql/data/mysqldata1/sock/mysql.pid #Pid file path
tmpdir = /home/mysql/data/mysqldata1/tmpdir # The path to store temporary files
log-error = /home/mysql/data/mysqldata1/log/error.log
#The last sentence added is to make the installed mysql library insensitive to table cases:
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
lower_case_table_names=1
default- storage-engine=INNODB

slow_query_log
slow_query_log_file = /home/mysql/data/mysqldata1/slowlog/slow_query.log
skip-external-locking
key_buffer_size = 16M
max_allowed_packet = 1M
table_open_cache = 64
sort_buffer_size = 512K
net_buffer_length = 8K
read_buffer_size = 256K
read_rnd_buffer_size = 512K
myisam_sort_buffer_size = 8M
character-set-server=utf8
init_connect=‘SET NAMES utf8’
log-bin = /home/mysql/data/mysqldata1/binlog/mysql-bin
relay-log = /home/mysql/data/mysqldata1/relaylog/mysql-relay-bin
binlog_format=mixed
server-id = 1
innodb_data_home_dir = /home/mysql/data/mysqldata1/innodb_ts
innodb_log_group_home_dir = /home/mysql/data/mysqldata1/innodb_log
innodb_undo_directory = /home/mysql/data/mysqldata1/undo

[mysqldump]
quick
max_allowed_packet = 16M

[mysql]
no-auto-rehash
default-character-set=utf8

[myisamchk]
key_buffer_size = 20M
sort_buffer_size = 20M
read_buffer = 2M
write_buffer = 2M
[mysqlhotcopy]
interactive-timeout

9. Initialize mysql configuration information

Executing this statement will generate a random password. Go to error.log to find
mysqld --defaults-file=/etc/my.cnf --initialize
. Execute this command to initialize the first login database using the empty root password
mysqld - -defaults-file=/etc/my.cnf --initialize-insecure

10. Start the mysql service

Copy the mysql.server file to the /etc/init.d/ directory, name it the mysqld program, and use this script to start and stop MySQL.
cp -ar /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
Grant permission
chmod +x /etc/init.d/mysqld
Check whether execution permission is successfully granted
ll /etc/init .d/mysqld
Start the mysql service
service mysqld start
View the process and port
ps aux|grep mysqld
netstat -ntupl |grep mysqld

11. Enter the database

mysql
Check the current logged in user
select user();
Check whether the current version is correct
select version();

12. Delete non-root or non-localhost users and change the root password

By default, after MySQL initialization is completed, some default users are created: anonymous users, non-root users who are allowed to log in to 127.0.0.1 and localhost. It is recommended to delete these users who are useless and may bring security risks to the database.

select user,host from mysql.user;
If it is version 5.7 and above, you need to exclude several system users.
Delete from mysql.user where user not in ('mysql.sys','mysql.version','mysqlxsys',' root','mysql.infoschema') or host not in ('localhost');
Change user password
Method one: alter user root@localhost identified by '123456';
Method two: update mysql.user set authentication_string=password('123456 ') where user='root' and host='localhost';
refresh privileges: flush privileges;

13. Create users, libraries, tables, and data

Do not directly use DML statements to operate the mysql.user table, but use grant, revoke or create user or drop user statements. If you must use DML statements to operate the mysql.user table, please note that the password field name is changed to authentication_string in MySQL 5.7.x.

Create an administrative user and authorize it.
Create an administrative user and grant this administrative user all permissions to access from any address (including with
grant option permissions).
Create an administrative user
create user 'admin'@'%' identified by '123456';
create user 'admin '@'localhost' identified by '123456';
grant all on . to 'admin'@'localhost' with grant option;

The content of this article refers to the "MySQL Performance Optimization Pyramid Rules".
If there is any infringement, please contact us to delete it.

Guess you like

Origin blog.csdn.net/qq798867485/article/details/108605231