1 版本及下载 MySQL数据库存在多种版本,按照实际需求下载:
官网地址:MySQL :: Download MySQL Community Server
#查看glibc版本信息,选择对应的版本
选择如图:
2 下载完成,可通过xftp等方式上传到服务器
tar xvf mysql-8.3.0-linux-glibc2.28-x86_64.tar.xz
mv mysql-8.3.0-linux-glibc2.28-x86_64/ /data/mysql
groupadd mysql
useradd -r -g mysql -s /bin/false mysql
cd /data/mysql/
mkdir logs
mkdir etc
mkdir mysql-files
touch logs/log_error.log
chown mysql.mysql -R /data/mysql/
chmod 750 mysql-files/
#进行初始化
./bin/mysqld --defaults-file=/data/mysql/etc/my.cnf --initialize --user=mysql --basedir=/data/mysql --datadir=/data/mysql/data --log-error=/data/mysql/logs/log_error.log --pid-file=/data/mysql/
#启动mysql
./bin/mysqld_safe --defaults-file=/data/mysql/etc/my.cnf --user=mysql --basedir=/data/mysql --datadir=/data/mysql/data --log-error=/data/mysql/logs/log_error.log --pid-file=/data/mysql/mysql.pid --socket=/data/mysql/mysql.sock --port=3306 &
#root密码修改
cat logs/log_error.log | grep root@localhost
2024-04-26T06:01:00.897795Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: rfo8qh1rdP&I
/data/mysql/bin/mysql -uroot -P3306 -S /data/mysql/mysql.sock -p
ALTER USER 'root'@'localhost' IDENTIFIED BY '密码';
FLUSH PRIVILEGES;
3配置启动 服务
cd /data/mysql/support-files/
cp -a mysql.server /etc/init.d/
vim /etc/init.d/mysql.server
修改basedir,datadir 等为实际目录
basedir=/data/mysql
datadir=/data/mysql/data
basedir=/data/mysql/mysql
bindir=/data/mysql/bin
then
datadir=/data/mysql/data
fi
sbindir=/data/mysql/bin
libexecdir=/data/mysql/bin
systemctl daemon-reload
systemctl start mysql