使用命令ldd --version ldd 检查,确定MySQL 8二进制包版本
[root@mysql8_3 ~]# ldd --version ldd
安装libaio
[root@mysql8_3 ~]#yum install libaio
安装ncurses-compat-libs
[root@mysql8_3 ~]#yum install ncurses-compat-libs
创建安装目录
[root@mysql8_3 ]#mkdir /u01
创建用户
[root@mysql8_3 ]# useradd -r -g mysql -s /bin/false mysql
进入安装目录
[root@mysql8_3 u01]# cd /u01
解压安装包
[root@mysql8_3 u01]# tar xvf mysql-commercial-8.4.4-linux-glibc2.28-x86_64.tar.xz
修改安装目录名字
[root@mysql8_3 u01]# mv mysql-commercial-8.4.4-linux-glibc2.28-x86_64 mysql3308
创建程序目录
[root@mysql8_3 mysql3308]# mkdir base
把解压包的文件及文件夹移动到base目录
[root@mysql8_3 mysql3308]# mv * base/
创建数据目录
[root@mysql8_3 mysql3308]# mkdir data
给整个数据库目录赋予mysql用户及组
[root@mysql8_3 mysql3308]# cd ..
[root@mysql8_3 u01]# chown -R mysql.mysql mysql3308
对数据库进行初始化,记住初始root密码
[root@mysql8_3 mysql3308]# base/bin/mysqld --initialize --datadir=/u01/mysql3308/data/ --user=mysql
2025-04-09T06:10:07.862792Z 0 [System] [MY-015017] [Server] MySQL Server Initialization - start.
2025-04-09T06:10:07.866074Z 0 [System] [MY-013169] [Server] /u01/mysql-commercial-8.4.4-linux-glibc2.28-x86_64/base/bin/mysqld (mysqld 8.4.4-commercial) initializing of server in progress as process 11898
2025-04-09T06:10:08.040918Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2025-04-09T06:10:11.812516Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
2025-04-09T06:10:25.552364Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: fc9%Xt<E5eF/
2025-04-09T06:10:38.228926Z 0 [System] [MY-015018] [Server] MySQL Server Initialization - end.
测试数据库启动
[root@mysql8_3 mysql3308]# ./base/bin/mysqld_safe --datadir=/u01/mysql3308/data/ --user=mysql &
[1] 12586
[root@mysql8_3 mysql3308]# 2025-04-09T06:15:10.255451Z mysqld_safe Logging to '/u01/mysql3308/data/mysql8_3.52.err'.
2025-04-09T06:15:10.330480Z mysqld_safe Starting mysqld daemon with databases from /u01/mysql3308/data
查看启动端口
[root@mysql8_3 mysql3308]# netstat -antupl
修改root 密码
[root@mysql8_3 mysql3308]# ./base/bin/mysql -uroot -p
Enter password:
Welcome to the MySQL monitor.
Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 8.4.4-commercial
Copyright (c) 2000, 2025, Oracle and/or its affiliates.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql>
mysql> set password='123456';
测试修改后root密码登陆
[root@mysql8_3 mysql3308]# ./base/bin/mysql -uroot -p123456
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.
Commands end with ; or \g.
Your MySQL connection id is 10
Server version: 8.4.4-commercial MySQL Enterprise Server - Commercial
Copyright (c) 2000, 2025, Oracle and/or its affiliates.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> exit
Bye
添加mysql启动脚本
[root@mysql8_3 mysql3308]# cp base/support-files/mysql.server /etc/init.d/mysql.server
修改mysql启动脚本,并添加程序目录和数据目录
[root@mysql8_3 mysql3308]# vim /etc/init.d/mysql.server
If you change base dir, you must also change datadir. These may get
overwritten by settings in the MySQL configuration files.
basedir=/u01/mysql3308/base
datadir=/u01/mysql3308/data
测试mysql启动脚本
[root@mysql8_3 mysql3308]# /etc/init.d/mysql.server start
Starting MySQL.... SUCCESS!
[root@mysql8_3 mysql3308]# netstat -antupl
添加mysql环境变量
[root@mysql8_3 mysql3308]# echo "export PATH=$PATH:/u01/mysql3308/base/bin" >> /etc/profile
[root@mysql8_3 mysql3308]# source /etc/profile
[root@mysql8_3 mysql3308]# mysql -uroot -p123456
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.
Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 8.4.4-commercial MySQL Enterprise Server - Commercial
Copyright (c) 2000, 2025, Oracle and/or its affiliates.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql>
添加mysql配置文件
[root@mysql8_3 mysql3308]# vim my.cnf
[mysqld]
user=mysql
port=3308
mysqlx_port=33080
basedir=/u01/mysql3308/base
datadir=/u01/mysql3308/data
socket = /u01/mysql3308/data/mysql.sock
pid-file = /u01/mysql3308/data/mysql.pid
log_error = /u01/mysql3308/data/mysql-error.log
log_timestamps=SYSTEM
character_set_server=utf8mb4
skip_name_resolve=1
binlog_format=row
log-bin = /u01/mysql3308/data/binlog
server-id = 03533308
skip_slave_start=1
open_files_limit=65535
innodb_buffer_pool_size=3G
innodb_log_buffer_size=16M
innodb_log_file_size=256M
sort_buffer_size = 6M
修改my.cnf文件属主
[root@mysql8_3 mysql3308]# chown mysql:mysql my.cnf
增加mysql系统自启动脚本
[root@mysql8_3 mysql3308]#
vim /usr/lib/systemd/system/mysqld83308.service
[Unit]
Description=MySQL Server
Documentation=mysqld.service
After=network.target
After=syslog.target
[Install]
WantedBy=multi-user.target
[Service]
User=mysql
Group=mysql
ExecStart=/u01/mysql3308/base/bin/mysqld --defaults-file=/u01/mysql3308/my.cnf
LimitNOFILE = 5000
测试mysql自启动脚本
[root@mysql8_3 mysql3308]# systemctl restart mysqld83308.service
[root@mysql8_3 mysql3308]# netstat -antupl
测试mysql自启动脚本后,root登陆,由于改了sock的路径不是默认的/tmp/mysql.sock,所以登录root需要手动指定sock路径
[root@mysql8_3 mysql3308]# mysql -uroot -p123456 -S /u01/mysql3308/data/mysql.sock
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.
Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 8.4.4-commercial MySQL Enterprise Server - Commercial
Copyright (c) 2000, 2025, Oracle and/or its affiliates.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql>
图片