Linux 安装 MySQL 最新版本 8.0.25

admin 2024-05-15 102 阅读 0评论
计划在未来几天发一篇 MySQL 数据恢复的文章,大概方式是:误操作后,把原实例的最近一次全量备份在目标实例恢复,而增量数据通过把原实例的 Binlog 传到目标实例,然后修改成 Relay Log,再通过
start slave sql_thread until sql_before_gtids='xxx' 恢复到误操作之前的位点。
因为这个实验需要使用到 MySQL 基础环境,这篇文章就先来水一篇 MySQL 最新小版本 8.0.25 的安装。

1 下载 MySQL

cd /usr/src
wget https://mirrors.cloud.tencent.com/mysql/downloads/MySQL-8.0/mysql-8.0.25-linux-glibc2.12-x86_64.tar.xz

2 解压 MySQL 压缩包

xz -d mysql-8.0.25-linux-glibc2.12-x86_64.tar.xz
tar xvf mysql-8.0.25-linux-glibc2.12-x86_64.tar
mv mysql-8.0.25-linux-glibc2.12-x86_64 /usr/local/mysql

3 创建 MySQL 相关目录

mkdir /data/mysql/ -p
mkdir /data/mysql/{binlog,data,log,tmpdir,conf} -p

4 创建 MySQL 用户

groupadd mysql
useradd -r -g mysql -s /bin/false mysql

5 修改权限

chown -R mysql:mysql /data/mysql/
chown -R mysql:mysql /usr/local/mysql

6 增加配置文件

vim /data/mysql/conf/my.cnf
加入如下内容:
[client]
port        = 3306
socket      = /tmp/mysql.sock
[mysqld]
port    = 3306
socket  = /tmp/mysql.sock
##  dir set
datadir           = /data/mysql/data
innodb_data_home_dir   = /data/mysql/data
innodb_log_group_home_dir = /data/mysql/data
log-bin           = /data/mysql/binlog/mysql-bin
log_bin_index             = /data/mysql/binlog/mysql-bin.index
relay-log         = /data/mysql/binlog/mysql-relay-bin
tmpdir            = /data/mysql/tmpdir
slow_query_log_file   = /data/mysql/log/mysql-slow.log
general_log_file   = /data/mysql/log/mysql-general.log
log-error         = /data/mysql/log/mysql.err
## slave and binlog
server-id = 6666            #  
skip-slave-start = 0        #
read_only = 0           #
binlog_format = row
log-slave-updates = 1
master_info_repository = table
relay_log_info_repository = table
relay_log_purge = 1
relay_log_recovery = 1
sync_binlog = 100                   # !!!
binlog_cache_size = 1M
expire_logs_days = 30
log_bin_trust_function_creators = 1
slave_net_timeout=60
#binlog_error_action="IGNORE_ERROR"    
innodb_autoinc_lock_mode=1          
## back_log = 200
bulk_insert_buffer_size = 8M
#character-set-server = utf8
lower_case_table_names = 1              #  1:不区分
## 基线
local-infile = off
skip-networking = off
skip-name-resolve = on
## connect
max_allowed_packet = 32M
max_connect_errors = 1000
max_connections = 3000
wait_timeout = 3600             # 关闭 非交互 连接之前等待活动的秒数 default:8h
interactive_timeout = 3600          # 关闭 交互式 连接之前等待活动的秒数 default:8h
table_open_cache = 4096
thread_cache_size =  64
thread_stack = 192K
transaction-isolation = REPEATABLE-READ     #
pid-file = mysql.pid
## slowslow_query_log = 1
long_query_time = 1
log-slow-admin-statements
log_queries_not_using_indexes = 0
slow_launch_time = 1read_buffer_size = 4M
read_rnd_buffer_size = 8M
sort_buffer_size = 8M
join_buffer_size = 32M
tmp_table_size = 128M
max_heap_table_size = 128M
default-storage-engine = innodb
explicit_defaults_for_timestamp = on          
## innodbinnodb_buffer_pool_size = 1G
innodb_max_dirty_pages_pct = 80
innodb_thread_concurrency = 8
innodb_buffer_pool_instances = 1
innodb_flush_log_at_trx_commit = 2
innodb_read_io_threads = 8
innodb_write_io_threads = 4
innodb_io_capacity = 1000
innodb_io_capacity_max = 2000
innodb_lru_scan_depth = 1024
innodb_use_native_aio = 1
innodb_flush_neighbors = 1
innodb_buffer_pool_load_at_startup = 1
innodb_buffer_pool_dump_at_shutdown = 1
innodb_data_file_path=ibdata:1G:autoextend
innodb_log_files_in_group = 3
innodb_log_file_size = 2G
innodb_file_per_table = 1
innodb_flush_method = O_DIRECT
innodb_strict_mode = 1
innodb_lock_wait_timeout = 30
innodb_log_buffer_size = 16M
innodb_adaptive_flushing = 1
innodb_change_buffering = all
innodb_purge_threads = 4
innodb_purge_batch_size = 300
innodb_old_blocks_time = 1
innodb_fast_shutdown = 0
performance_schema = 1
innodb_print_all_deadlocks = 1
innodb_sort_buffer_size = 4M
innodb_page_size = 16k
gtid_mode=on
enforce_gtid_consistency=on    
table_open_cache_instances=16
binlog_rows_query_log_events=1      
slave_parallel_workers = 0          # 多线程复制线程数
#slave_parallel_type=LOGICAL_CLOCK      
#binlog_group_commit_sync_delay = 500000
#binlog_group_commit_sync_no_delay_count =12  
## pasworddefault_password_lifetime=0                     # 0密码永不过期,N n天过期
[mysqldump]
quick
max_allowed_packet = 32M
[mysql]
no-auto-rehash
prompt=\p@\d>\_
[mysqld_safe]
open-files-limit = 28192
[mysqlhotcopy]
interactive-timeout

7 初始化

/usr/local/mysql/bin/mysqld --defaults-file=/data/mysql/conf/my.cnf --user=mysql --initialize

8 获取临时密码

grep "password" /data/mysql/log/mysql.err
如下图

注意:
如果这里获取不到密码行,请检查 /data/mysql/log/mysql.err,确认是否是初始化异常。

9 启动 MySQL

nohup /usr/local/mysql/bin/mysqld --defaults-file=/data/mysql/conf/my.cnf --user=mysql &

10 增加环境变量

编辑 /etc/profile 文件,加入如下内容:
MYSQL_HOME=/usr/local/mysql
PATH=$PATH:$MYSQL_HOME/bin
export PATH MYSQL_HOME
重新加载配置
source /etc/profile

11 登录 MySQL

通过临时密码进入MySQL 中:
mysql -uroot -p'j#D_tdy.p0tT'

12 修改密码

alter user user() identified by 'martin';

13 再次登录 MySQL

使用修改后的密码登录 MySQL,则可以正常使用 MySQL 了:
mysql -uroot -p'martin'

14 关闭 MySQL

如果需要关闭 MySQL,可执行:
mysqladmin -S /tmp/mysql.sock -p shutdown


发表评论

快捷回复: 表情:
Addoil Applause Badlaugh Bomb Coffee Fabulous Facepalm Feces Frown Heyha Insidious KeepFighting NoProb PigHead Shocked Sinistersmile Slap Social Sweat Tolaugh Watermelon Witty Wow Yeah Yellowdog
提交
评论列表 (有 0 条评论, 102人围观)