- 下载地址
https://downloads.mysql.com/archives/community/
- 解压tar包
tar -xvf mysql-8.0.25-linux-glibc2.12-x86_64.tar.xz -C /usr/local/
cd /usr/local/
mv mysql-8.0.25-linux-glibc2.12-x86_64/ mysql
- 修改环境变量
tail -n 1 /etc/profile
PATH=/usr/local/mysql/bin:$PATH
source /etc/profile
mysql -V
mysql Ver 8.0.25 for Linux on x86_64 (MySQL Community Server - GPL)
- 创建运行MySQL服务的用户并授权
useradd -r -s /sbin/nologin -d /usr/local/mysql -c 'MySQL DataBase Server User' mysql
# -r 这个选项表示创建的是一个系统用户。系统用户通常是用来运行服务或者守护进程,而不是给人类使用的。这类用户的UID通常小于1000。
# -d /usr/local/mysql 指定家目录为/usr/local/mysql
chown -R mysql:mysql /usr/local/mysql/
- 删除遗留的其它MySQL分支
yum remove mariadb-libs -y
rm -rf /etc/my.cnf*
- 初始化数据库
yum -y install autoconf # 初始化的时候需要用到
yum -y install libaio # 初始化的时候需要用到
mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data
2024-09-23T15:34:26.588356Z 0 [System] [MY-013169] [Server] /usr/local/mysql/bin/mysqld (mysqld 8.0.25) initializing of server in progress as process 2258
2024-09-23T15:34:26.610053Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2024-09-23T15:34:28.029290Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
2024-09-23T15:34:29.953951Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: royt:4jWjRdd
#上面的初始密码要记住。
- MySQL的启动脚本
cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
chkconfig --add mysqld # 设置开机自启
vim /etc/init.d/mysqld
basedir=/usr/local/mysql
datadir=/usr/local/mysql/data
# 补全这两行
systemctl daemon-reload
systemctl restart mysqld
systemctl status mysqld
- 修改初始密码
mysql -uroot -proyt:4jWjRdd
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.0.25
Copyright (c) 2000, 2021, 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 user() identified by "1qaz@WSX";
Query OK, 0 rows affected (0.00 sec)