查看ldd版本,后面需要根据ldd版本下载适配的MySQL
[root@localhost ~]# ldd --version
ldd (GNU libc) 2.28
Copyright (C) 2018 自由软件基金会。
这是一个自由软件;请见源代码的授权条款。本软件不含任何没有担保;甚至不保证适销性
或者适合某些特殊目的。
由 Roland McGrath 和 Ulrich Drepper 编写。
[root@localhost ~]#
MySQL下载地址:https://dev.mysql.com/downloads/mysql/
由于ldd版本为2.28,根据下面的筛选条件找到适配的MySQL即可。
筛选条件:8.4.3 LTS → Linux - Generic → Linux - Generic (glibc 2.28) (x86, 64-bit)
下载地址:https://dev.mysql.com/get/Downloads/MySQL-8.4/mysql-8.4.3-linux-glibc2.28-x86_64.tar.xz
将下载的*.tar.xz文件解压,并移动到合适的位置,这里我们移动到/program/mysql-8.4目录。到这里就相当于执行完“make install”操作了,后续操作和编译安装是差不多的。
创建相关目录和文件(不需要手动创建data目录,初始化数据库时会自动创建)
[root@localhost ~]# mkdir /program/mysql-8.4/ssl && \
mkdir /program/mysql-8.4/log && \
touch /program/mysql-8.4/log/error.log && \
touch /program/mysql-8.4/log/slow-query.log && \
touch /program/mysql-8.4/log/general.log && \
chown -R mysql:mysql /program/mysql-8.4
[root@localhost ~]#
删除无关的my.cnf文件
[root@localhost ~]# ln -s /usr/lib64/libncurses.so.5 /usr/lib64/libncurses.so.6
[root@localhost ~]# ln -s /usr/lib64/libtinfo.so.5 /usr/lib64/libtinfo.so.6
[root@localhost ~]# /program/mysql-8.4/bin/mysql --help | grep 'Default options' -A 1
Default options are read from the following files in the given order:
/etc/my.cnf /etc/mysql/my.cnf /usr/local/mysql/etc/my.cnf ~/.my.cnf
[root@localhost ~]# rm -rf /etc/my.cnf /etc/mysql/my.cnf /usr/local/mysql/etc/my.cnf ~/.my.cnf
创建my.cnf文件并进行配置
[root@localhost ~]# vim /program/mysql-8.4/my.cnf
……(此处请去看《my.cnf文件配置示例》文章)……
[root@localhost ~]#
初始化数据库(如果需要重新初始化数据库请先手动删除data目录)
[root@localhost ~]# /program/mysql-8.4/bin/mysqld --initialize --user=mysql
……(此处省略内容若干)……
[Server] A temporary password is generated for root@localhost: aiiqs#j0e8(D # 这是root初始密码,务必记住
……(此处省略内容若干)……
[root@localhost ~]#
把MySQL加入chkconfig方便管理
[root@localhost ~]# cp /program/mysql-8.4/support-files/mysql.server /etc/init.d/mysql-8.4
[root@localhost ~]# chmod +x /etc/init.d/mysql-8.4
[root@localhost ~]# vim /etc/init.d/mysql-8.4
……(此处省略内容若干)……
# If you change base dir, you must also change datadir. These may get
# overwritten by settings in the MySQL configuration files.
basedir=
datadir=
# Default value, in seconds, afterwhich the script should timeout waiting
# for server start.
# Value here is overriden by value in my.cnf.
# 0 means don't wait at all
# Negative numbers mean to wait indefinitely
service_startup_timeout=900
# Lock directory for RedHat / SuSE.
lockdir='/var/lock/subsys'
lock_file_path="$lockdir/mysql-8.4"
# The following variables are only set for letting mysql.server find things.
# Set some defaults
mysqld_pid_file_path=
if test -z "$basedir"
then
basedir=/program/mysql-8.4
bindir=/program/mysql-8.4/bin
if test -z "$datadir"
then
datadir=/program/mysql-8.4/data
fi
sbindir=/program/mysql-8.4/bin
libexecdir=/program/mysql-8.4/bin
else
bindir="$basedir/bin"
if test -z "$datadir"
then
datadir="$basedir/data"
fi
sbindir="$basedir/sbin"
libexecdir="$basedir/libexec"
fi
# datadir_set is used to determine if datadir was set (and so should be
# *not* set inside of the --basedir= handler.)
datadir_set=
……(此处省略内容若干)……
[root@localhost ~]# chkconfig --add mysql-8.4
常用管理命令
[root@localhost ~]# chkconfig mysql-8.4 on # 设置开机自动启动MySQL
[root@localhost ~]# chkconfig mysql-8.4 off # 取消开机自动启动MySQL
[root@localhost ~]# service mysql-8.4 status # 查看MySQL运行状态
[root@localhost ~]# service mysql-8.4 start # 启动MySQL
[root@localhost ~]# service mysql-8.4 stop # 停止MySQL
[root@localhost ~]# service mysql-8.4 restart # 重启MySQL
启动数据库并修改root用户初始密码
[root@localhost ~]# service mysql-8.4 status
[root@localhost ~]# service mysql-8.4 start
[root@localhost ~]# /program/mysql-8.4/bin/mysql --socket=/program/_pid/mysql-8.4.sock -u root -p # 由于旧版本MySQL也在运行,为了避免进入旧版本的命令行所以指定socket
Enter password: aiiqs#j0e8(D # 这里输入root用户初始密码
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 8.4.3 # 注意版本号,别改了旧版本的root用户密码
Copyright (c) 2000, 2024, 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> ALTER USER 'root'@'localhost' IDENTIFIED WITH 'caching_sha2_password' BY '密码'; -- 修改root密码
Query OK, 0 rows affected (0.01 sec)
mysql> EXIT;
Bye
[root@localhost ~]#