
使用命令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=mysql2025-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 118982025-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 -pEnter password:Welcome to the MySQL monitor. Commands end with ; or \g.Your MySQL connection id is 8Server version: 8.4.4-commercialCopyright (c) 2000, 2025, Oracle and/or its affiliates.Oracle is a registered trademark of Oracle Corporation and/or itsaffiliates. Other names may be trademarks of their respectiveowners.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 -p123456mysql: [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 10Server version: 8.4.4-commercial MySQL Enterprise Server - CommercialCopyright (c) 2000, 2025, Oracle and/or its affiliates.Oracle is a registered trademark of Oracle Corporation and/or itsaffiliates. Other names may be trademarks of their respectiveowners.Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.mysql> exitBye添加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/basedatadir=/u01/mysql3308/data测试mysql启动脚本
[root@mysql8_3 mysql3308]# /etc/init.d/mysql.server startStarting 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 -p123456mysql: [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 8Server version: 8.4.4-commercial MySQL Enterprise Server - CommercialCopyright (c) 2000, 2025, Oracle and/or its affiliates.Oracle is a registered trademark of Oracle Corporation and/or itsaffiliates. Other names may be trademarks of their respectiveowners.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=mysqlport=3308mysqlx_port=33080basedir=/u01/mysql3308/basedatadir=/u01/mysql3308/datasocket = /u01/mysql3308/data/mysql.sockpid-file = /u01/mysql3308/data/mysql.pidlog_error = /u01/mysql3308/data/mysql-error.loglog_timestamps=SYSTEMcharacter_set_server=utf8mb4skip_name_resolve=1binlog_format=rowlog-bin = /u01/mysql3308/data/binlogserver-id = 03533308skip_slave_start=1open_files_limit=65535innodb_buffer_pool_size=3Ginnodb_log_buffer_size=16Minnodb_log_file_size=256Msort_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# This service is actually a systemd target,# but we are using a service since targets cannot be reloaded.[Unit]Description=MySQL ServerDocumentation=mysqld.serviceAfter=network.targetAfter=syslog.target[Install]WantedBy=multi-user.target[Service]User=mysqlGroup=mysqlExecStart=/u01/mysql3308/base/bin/mysqld --defaults-file=/u01/mysql3308/my.cnfLimitNOFILE = 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.sockmysql: [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 8Server version: 8.4.4-commercial MySQL Enterprise Server - CommercialCopyright (c) 2000, 2025, Oracle and/or its affiliates.Oracle is a registered trademark of Oracle Corporation and/or itsaffiliates. Other names may be trademarks of their respectiveowners.Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.mysql>
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。