Debian11 TAR包安装MySQL8.0

MySQL8 下载地址

访问 https://downloads.mysql.com/archives/community/

版本选择8.0.32, 操作系统选择Linux-Generic, 操作系统版本选择 Linux-Generic(glibc2.17)(x86,64-bit);

选择Compressed TAR Archive, Minimal Install 点击下载,或者使用下面的URL直接下载

https://cdn.mysql.com/archives/mysql-8.0/mysql-8.0.32-linux-glibc2.17-x86_64-minimal.tar.xz

环境约定

组件版本

OS: Debian11.7

MySQL: 8.0.32

安装路径

应用目录: /app/mysql

数据目录: /var/lib/mysql

日志目录: /var/log/mysql

PID目录: /var/run/mysql

系统初始化以及优化的过程请浏览 debian11系统初始化

安装MySQL8

上传安装包或者在服务器上直接下载

cd /tmp
wget -c https://cdn.mysql.com/archives/mysql-8.0/mysql-8.0.32-linux-glibc2.17-x86_64-minimal.tar.xz
xz -d mysql-8.0.32-linux-glibc2.17-x86_64-minimal.tar.xz
tar -xf mysql-8.0.32-linux-glibc2.17-x86_64-minimal.tar
mv mysql-8.0.32-linux-glibc2.17-x86_64-minimal mysql

准备环境

我们需要做以下工作,手动创建MySQL服务用户和所需要的目录并设置正确的权限,安装需要的lib

apt update
apt install -y vim wget xz tar libsuma1 psmisc libaio1 libnuma1 libatomic1 libmecab2 libncurses5
groupadd -r mysql
useradd -r -g mysql -c 'MySQL Server Account' -s /sbin/nologin -d /var/lib/mysql -M mysql
mkdir -p /app
mkdir -p /var/lib/mysql
mkdir -p /var/log/mysql 
mkdir -p /var/run/mysql
mv /tmp/mysql /app
chown -Rf mysql:mysql /app/mysql /var/lib/mysql  /var/log/mysql /var/run/mysql

配置my.cnf

vim /etc/my.cnf, 增加如下内容,其中注释的内容根据自己的需求进行调整

[mysqld]
basedir=/app/mysql
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
default_password_lifetime = 0
max_allowed_packet = 128M
max_connections = 5000
default-storage-engine=INNODB
character-set-server=utf8mb4
collation-server=utf8mb4_bin
bind-address=0.0.0.0
port=3306
federated
#skip-log-bin
#skip-mysqlx
#skip-ssl
skip-name-resolve
innodb_buffer_pool_size = 4G
innodb_log_buffer_size=16M
innodb_log_file_size = 256M
innodb_log_files_in_group=2
innodb_max_dirty_pages_pct=75
innodb_flush_method=O_DIRECT
innodb_read_io_threads=8
innodb_write_io_threads=10
innodb_thread_concurrency=32
innodb_io_capacity=5000
read_buffer_size=8M
read_rnd_buffer_size=8M
sort_buffer_size=8M
join_buffer_size=4M
tmp_table_size=16M
thread_cache_size = 16
open_files_limit = 65535
innodb_flush_log_at_trx_commit = 2
skip-external-locking
key_buffer_size = 16M
table_open_cache = 64
net_buffer_length = 8K
myisam_sort_buffer_size = 8M
lower_case_table_names=1
bulk_insert_buffer_size = 1M
group_concat_max_len = 204800
symbolic-links=0
log_timestamps=SYSTEM
log-error=/var/log/mysql/mysql.log
pid-file=/var/run/mysql/mysql.pid
slow-query-log=On
slow_query_log_file=/var/log/mysql/slow-query.log

[mysql]
auto-rehash
socket=/var/lib/mysql/mysql.sock

[client]
default-character-set=utf8mb4
socket=/var/lib/mysql/mysql.sock

[myisamchk]
key_buffer_size = 20M
sort_buffer_size = 20M
read_buffer = 2M
write_buffer = 2M

[mysqlhotcopy]
interactive-timeout

初始化MySQL

/app/mysql/bin/mysqld --user=mysql --basedir=/app/mysql --datadir=/var/lib/mysql --pid-file=/var/run/mysql/mysql.pid --initialize

配置服务启动文件

我们使用systemd管理mysql服务启动与停止

vim /usr/lib/systemd/system/mysqld.service,添加服务启动文件,写入以下内容

[Unit]
Description=MySQL Server
After=network.target networking.service syslog.target

[Service]
User=mysql
Group=mysql
Type=forking
ExecStartPre=/usr/bin/mkdir -p /var/run/mysql
ExecStartPre=/usr/bin/chown mysql:mysql /var/run/mysql
ExecStart=/app/mysql/bin/mysqld --daemonize --pid-file=/var/run/mysql/mysql.pid
PIDFile=/var/run/mysql/mysql.pid
TimeoutSec=0
PermissionsStartOnly=true
LimitNOFILE = 5000
Restart=on-failure
RestartPreventExitStatus=1
PrivateTmp=false

[Install]
WantedBy=multi-user.target

执行 systemctl enable --now mysqld.service 启动服务同时可以将服务添加到开机自启

查看默认root用户的密码

grep 'temporary password' /var/log/mysql/mysql.log
posted @ 2023-07-26 23:23  银河系派件员  阅读(375)  评论(0编辑  收藏  举报