Install MySQL 8.0 (binary) in centos7

Time:2021-4-27

Environment: Linux centos7 3.10.0-957.el7.x86_ 64、Mysql8.0.12

1. MySQL binary package download

https://pan.baidu.com/s/1Z5AzEmpk-MYuA3rvKx768g
Extraction code: wbtt

2. Uninstall previously installed versions

for i in $(rpm -qa|grep mysql);do rpm -e $i --nodeps;done
rm -rf /var/lib/mysql && rm -rf /etc/my.cnf && rm -rf /usr/share/mysql && rm -rf /etc/my.cnf.d

3. Install dependent packages

yum -y install libaio
yum -y install net-tools

4. Creating MySQL users and user groups

groupadd mysql
useradd -g mysql mysql
ID MySQL // view user groups and users

Install MySQL 8.0 (binary) in centos7

5. Decompress the MySQL binary package

CD / usr / local / SRC // download the MySQL binary package to this directory
tar -zvxf mysql8.0.12_ bin_ Centos7.tar.gz // decompress
MV MySQL / usr / local // migrate directory
chown -R  mysql:mysql /usr/local/mysql  //Modify the user and user group of the directory

6. Configure environment variables

vim /home/mysql/.bash_profile
export PATH=/usr/local/mysql/bin:/usr/local/mysql/lib:$PATH
source /home/mysql/.bash_profile
echo "PATH=$PATH:/usr/local/mysql/bin" >> /etc/profile
source /etc/profile

7. Create data directory

mkdir -p /data/mysql/{data,log,binlog,conf,tmp}
chown -R mysql:mysql /data/mysql

8. Configure MySQL

VIM / data / MySQL / conf / my.cnf // new configuration file
[mysqld]
lower_case_table_names =  1 
user = mysql 
server_id =  1 
port =  3306 
default-time-zone =  '+08:00' 
enforce_gtid_consistency = ON 
gtid_mode = ON
binlog_checksum = none 
default_authentication_plugin = mysql_native_password 
datadir =  /data/mysql/data 
pid-file =  /data/mysql/tmp/mysqld.pid 
socket =  /data/mysql/tmp/mysqld.sock 
tmpdir =  /data/mysql/tmp/ 
skip-name-resolve = ON 
open_files_limit =  65535 
table_open_cache =  2000
#################innodb######################## 
innodb_data_home_dir =  /data/mysql/data 
innodb_data_file_path = ibdata1:512M;ibdata2:512M:autoextend 
innodb_buffer_pool_size = 12000M 
innodb_flush_log_at_trx_commit =  1 
innodb_io_capacity =  600 
innodb_lock_wait_timeout =  120 
innodb_log_buffer_size = 8M 
innodb_log_file_size = 200M 
innodb_log_files_in_group =  3 
innodb_max_dirty_pages_pct =  85 
innodb_read_io_threads =  8 
innodb_write_io_threads =  8 
innodb_thread_concurrency =  32 
innodb_file_per_table 
innodb_rollback_on_timeout 
innodb_undo_directory =  /data/mysql/data 
innodb_log_group_home_dir =  /data/mysql/data 
###################session########################### 
join_buffer_size = 8M 
key_buffer_size = 256M 
bulk_insert_buffer_size = 8M 
max_heap_table_size = 96M 
tmp_table_size = 96M 
read_buffer_size = 8M 
sort_buffer_size = 2M 
max_allowed_packet = 64M 
read_rnd_buffer_size = 32M 
############log set################### 
log-error =  /data/mysql/log/mysqld.err 
log-bin =  /data/mysql/binlog/binlog 
log_bin_index =  /data/mysql/binlog/binlog.index 
max_binlog_size = 500M 
slow_query_log_file =  /data/mysql/log/slow.log 
slow_query_log =  1 
long_query_time =  10 
log_queries_not_using_indexes = ON 
log_throttle_queries_not_using_indexes =  10 
log_slow_admin_statements = ON 
log_output = FILE,TABLE 
master_info_file =  /data/mysql/binlog/master.info

9. Initialization

mysqld --defaults-file=/data/mysql/conf/my.cnf  --initialize-insecure  --user=mysql

10. Start mysqld

mysqld_safe --defaults-file=/data/mysql/conf/my.cnf &

11. View mysqld startup status

lsof -i:3306
ps -ef | grep mysql

Install MySQL 8.0 (binary) in centos7

Install MySQL 8.0 (binary) in centos7

12. Log in to MySQL and reset the password

MySQL - S / data / MySQL / TMP / mysqld.sock // no password is required to log in to MySQL using the sock file for the first time
ALTER USER 'root'@'localhost' IDENTIFIED BY 'root'; // Change Password
flush privileges; // Refresh permission table
select host,user,authentication_string from mysql.user;

Install MySQL 8.0 (binary) in centos7

Install MySQL 8.0 (binary) in centos7

13. Make a soft connection

Ln - S / data / MySQL / TMP / mysqld.sock / TMP / mysql.sock // log in to the sock and connect to the TMP directory

Install MySQL 8.0 (binary) in centos7

14. Log in again with the new password

mysql -uroot -p

Install MySQL 8.0 (binary) in centos7

reference resources:Install mysql8.0 for centos7 – operation manual

This work adoptsCC agreementReprint must indicate the author and the link of this article

Aduh