1、下载二进制包
https://dev.mysql.com/downloads/mysql/
选择 mysql-8.0.40-linux-glibc2.28-x86_64.tar.xz
2、部署
cd /opt
tar xf mysql-8.0.40-linux-glibc2.28-x86_64.tar.xz
groupadd mysql
useradd -g mysql -s /sbin/nologin -M mysql
mkdir /data/mysql-8.0.40/{data,tmp,logs} -p
chown -R mysql.mysql /opt/mysql-8.0.40-linux-glibc2.28-x86_64
chown -R mysql.mysql /data/mysql-8.0.40
chmod -R 750 /data/mysql-8.0.40/data
ln -s mysql-8.0.40-linux-glibc2.28-x86_64 mysql
ln -s /opt/mysql/bin/* /usr/local/sbin/
3、vim /opt/mysql/my-8.0.40.cnf
[mysql]
# CLIENT #
port = 3306
prompt='(product)\u@\h [\d]>'
default-character-set=utf8mb4
no-auto-rehash
[mysqld]
lower_case_table_names = 1
character_set_server = utf8mb4
collation-server = utf8mb4_unicode_ci
character-set-client-handshake = 0
init_connect = 'SET NAMES utf8mb4'
server-id = 723306
explicit_defaults_for_timestamp = 1
default_time_zone = '+8:00'
log_timestamps = SYSTEM
skip-name-resolve
# DATA STORAGE #
datadir = /data/mysql-8.0.40/data
tmpdir = /data/mysql-8.0.40/tmp
# GENERAL #
port = 3306
basedir = /opt/mysql
user = mysql
default-storage-engine = InnoDB
socket = /tmp/mysql.sock
pid-file = mysql.pid
performance_schema = 1
# SAFETY #
max-allowed-packet = 64M
max-connect-errors = 1000000
# BINARY LOGGING #
log-bin = /data/mysql-8.0.40/logs/mysql-bin
binlog_format = row
binlog-cache-size = 4M
max-binlog-size = 1G
binlog-rows-query-log-events = ON
expire-logs-days = 3
sync-binlog = 1
log_bin_trust_function_creators= 1
# SLAVE BINLOGUPDATE#
log-slave-updates
# RELAY LOGS #
relay-log = /data/mysql-8.0.40/logs/relay-log
max-relay-log-size = 1G
relay_log_purge = 1
relay_log_recovery = 1
# CACHES AND LIMITS #
tmp-table-size = 96M
max-heap-table-size = 96M
max-connections = 1000
thread-cache-size = 64
open-files-limit = 65535
innodb_open_files = 65535
table-definition-cache = 4096
table-open-cache = 4096
key-buffer-size = 32M
read-buffer-size = 2M
read_rnd_buffer_size = 16M
bulk_insert_buffer_size = 32M
sort_buffer_size = 2M
join_buffer_size = 8M
secure-file-priv = ''
open-files-limit = 65535
innodb_open_files = 65535
# LOGGING #
long_query_time = 0.2
log-error = /data/mysql-8.0.40/logs/error.log
slow-query-log = 1
slow-query-log-file = slow-query.log
#log-queries-not-using-indexes = 1
eq-range-index-dive-limit = 1000
#log-slow-slave-statements = 1
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
# SQL MODE #
sql-mode="NO_ENGINE_SUBSTITUTION"
## 8.0 ##
default_authentication_plugin = mysql_native_password
skip_ssl
[mysqld_safe]
nice = -19
[mysqldump]
quick
quote-names
max_allowed_packet = 64M
[client]
port = 3306
socket = /tmp/mysql.sock
4、初始化数据库
/opt/mysql/bin/mysqld --defaults-file=/opt/mysql/my-8.0.40.cnf --initialize --user=mysql --datadir=/data/mysql-8.0.40/data
5、启动实例
/opt/mysql/bin/mysqld_safe --defaults-file=/opt/mysql/my-8.0.40.cnf &
6、登录实例,需要使用初始化过程中生成的随机密码
grep password /data/mysql-8.0.40/logs/error.log
2025-01-16T15:42:06.420055+08:00 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: xE+4wr#Wl-.&
/opt/mysql/bin/mysql -uroot -S /tmp/mysql.sock -p
// 修改密码
mysql> ALTER USER user() IDENTIFIED BY 'mysql';
Query OK, 0 rows affected (0.00 sec)
7、开机自启动
cp /opt/mysql/mysql/support-files/mysql.server /etc/rc.d/init.d/mysql
chmod +x /etc/init.d/mysql
chkconfig --list
chkconfig --add mysql
chkconfig --list
------------------------------- THE END -------------------------------
标签:8.0,log,40,mysql,data,size From: https://www.cnblogs.com/ordinaryRoadX/p/18676399