Linux安装mysql8压缩包版本

Linux安装mysql8压缩包版本

下载mysql8

1
2
3
https://dev.mysql.com/downloads/mysql/

wget https://dev.mysql.com/get/Downloads/MySQL-8.0/mysql-8.0.39-linux-glibc2.28-x86_64.tar.xz

安装依赖工具

1
apt install xz-utils -y

解压缩

1
2
3
4
xz -dk mysql-8.0.39-linux-glibc2.28-x86_64.tar.xz
tar -xvf mysql-8.0.39-linux-glibc2.28-x86_64.tar
mv mysql-8.0.39-linux-glibc2.28-x86_64 mysql
mv mysql /usr/local/mysql

创建mysql数据目录

1
2
3
4
mkdir /usr/local/mysql/data
mkdir /usr/local/mysql/mysqld
mkdir /usr/local/mysql/mysql-files
mkdir /usr/local/mysql/conf.d/

编写配置文件

vim /etc/my.cnf

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/8.0/en/server-configuration-defaults.html

[mysqld]
#
# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
# innodb_buffer_pool_size = 128M
#
# Remove leading # to turn on a very important data integrity option: logging
# changes to the binary log between backups.
# log_bin
#
# Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
# join_buffer_size = 128M
# sort_buffer_size = 2M
# read_rnd_buffer_size = 2M

# Remove leading # to revert to previous value for default_authentication_plugin,
# this will increase compatibility with older clients. For background, see:
# https://dev.mysql.com/doc/refman/8.0/en/server-system-variables.html#sysvar_default_authentication_plugin
# default-authentication-plugin=mysql_native_password
skip-host-cache
skip-name-resolve
datadir=/usr/local/mysql/data
socket=/usr/local/mysql/mysqld/mysqld.sock
secure-file-priv=/usr/local/mysql/mysql-files
user=mysql

pid-file=/usr/local/mysql/mysqld/mysqld.pid
[client]
socket=/usr/local/mysql/mysqld/mysqld.sock

!includedir /usr/local/mysql/conf.d/

vim /usr/local/mysql/conf.d/mysqld.conf

1
2
3
4
5
6
7
8
[mysqld]
bind-address = 0.0.0.0
max_connections=2000
#binlog_format=ROW
#binlog_row_image=full
#binlog_expire_logs_seconds=15552000
#expire_logs_days=180
#server_id=1

创建启动用户与授权

1
2
3
groupadd mysql
useradd -r -g mysql -s /bin/false mysql
chown -R mysql:mysql /usr/local/mysql

初始化mysql

1
2
3
/usr/local/mysql/bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data/

记录输出的密码 A temporary password is generated for root@localhost: xxxxxxxx

设置开机启动

1
2
3
4
ln -s /usr/local/mysql/  /usr/bin/

cp -a support-files/mysql.server /etc/init.d/mysqld
chmod +x /etc/init.d/mysqld

编写服务配置

vim /etc/systemd/system/mysqld.service

1
2
3
4
5
6
7
8
9
10
11
12
13
14
[Unit]
Description=MySQL Community Server
After=network.target

[Service]
Type=forking
ExecStart=/usr/local/mysql/support-files/mysql.server start
ExecStop=/usr/local/mysql/support-files/mysql.server stop
User=mysql
Group=mysql
Restart=always

[Install]
WantedBy=multi-user.target

重新加载配置

1
systemctl daemon-reload

启动mysql

1
systemctl start mysqld

设置开启服务

1
systemctl enable mysqld

停止mysql [可选]

1
systemctl stop mysqld