CentOS7 安装 MySQL8.0(二进制)

环境: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 //查看用户组及用户

CentOS8 安装 MySQL8.0(二进制)

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

CentOS8 安装 MySQL8.0(二进制)

CentOS8 安装 MySQL8.0(二进制)

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;

CentOS8 安装 MySQL8.0(二进制)

CentOS8 安装 MySQL8.0(二进制)

13、做软连接

ln -s /data/mysql/tmp/mysqld.sock /tmp/mysql.sock //登录sock软连接到tmp目录

CentOS8 安装 MySQL8.0(二进制)

14、使用新密码重新登录

mysql -uroot -p

CentOS8 安装 MySQL8.0(二进制)

参考:Centos7安装MySQL8.0 - 操作手册

本作品采用《CC 协议》,转载必须注明作者和本文链接

阿德

zhangdeTalk
讨论数量: 0
(= ̄ω ̄=)··· 暂无内容!

请勿发布不友善或者负能量的内容。与人为善,比聪明更重要!