環境:Linux centos7 3.10.0-957.el7.x86_64、Mysql8.0.12
1、MySQL二進位制檔案包下載
https://pan.baidu.com/s/1Z5AzEmpk-MYuA3rvKx768g 提取碼:wbtt
2、解除安裝之前安裝過的版本
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、安裝依賴的軟體包
yum -y install libaio yum -y install net-tools
4、建立mysql使用者及使用者組
groupadd mysql useradd -g mysql mysql id mysql //檢視使用者組及使用者
5、解壓MySQL二進位制檔案壓縮包
cd /usr/local/src/ //下載MySQL二進位制檔案包到此目錄
tar -zvxf mysql8.0.12_bin_centos7.tar.gz //解壓
mv mysql /usr/local/ //遷移目錄
chown -R mysql:mysql /usr/local/mysql //修改目錄所屬使用者及使用者組
6、配置環境變數
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、建立資料目錄
mkdir -p /data/mysql/{data,log,binlog,conf,tmp}
chown -R mysql:mysql /data/mysql
8、配置MySQL
vim /data/mysql/conf/my.cnf //新建配置檔案
[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、初始化
mysqld --defaults-file=/data/mysql/conf/my.cnf --initialize-insecure --user=mysql
10、啟動mysqld
mysqld_safe --defaults-file=/data/mysql/conf/my.cnf &
11、檢視mysqld啟動狀態
lsof -i:3306
ps -ef | grep mysql
12、登入mysql,重置密碼
mysql -S /data/mysql/tmp/mysqld.sock //本地首次使用sock檔案登入mysql是不需要密碼的
ALTER USER 'root'@'localhost' IDENTIFIED BY 'root'; //修改密碼
flush privileges; //重新整理許可權表
select host,user,authentication_string from mysql.user;
13、做軟連線
ln -s /data/mysql/tmp/mysqld.sock /tmp/mysql.sock //登入sock軟連線到tmp目錄
14、使用新密碼重新登入
mysql -uroot -p
本作品採用《CC 協議》,轉載必須註明作者和本文連結