1:下载: wget https://dev.mysql.com/get/Downloads/MySQL-8.0/mysql-8.0.21-linux-glibc2.12-x86_64.tar.xz

2:解压:tar xvJf mysql-8.0.21-linux-glibc2.12-x86_64.tar.xz

3:重命名:mv mysql-8.0.21-linux-glibc2.12-x86_64 mysql-8.0

4:创建data文件储存数据:mkdir data

5:创建用户与用户组:groupadd mysql useradd -g mysql mysql

6:授权用户:chown -R mysql.mysql /usr/local/mysql-8.0

7:切换到bin目录:cd bin

8:初始化信息:./mysqld --user=mysql --basedir=/usr/local/mysql-8.0 --datadir=/usr/local/mysql-8.0/data/ --initialize

9:备注:初始化时会生成密码。 编辑my.cnf文件:vi /etc/my.cnf 添加如下信息:

【mysqld】

basedir=/usr/local/mysql-8.0/

datadir=/usr/local/mysql-8.0/data/

socket=/tmp/mysql.sock character-set-server=UTF8MB4

10:添加mysql至systemd:sudo vi /etc/systemd/system/mysqld.service

增加如下内容: [Unit] Description=MySQL Community Server After=network.target

[Service] User=mysql Group=mysql ExecStart=/path/to/mysql/support-files/mysql.server start ExecStop=/path/to/mysql/support-files/mysql.server stop LimitNOFILE=5000

[Install] WantedBy=multi-user.target

#注意:

将 /path/to/mysql/ 替换为实际的 MySQL 安装路径。
确保 User 和 Group 字段中的用户和组是你希望运行 MySQL 的用户(通常是 mysql)。

11:重新加载systemd:sudo systemctl daemon-reload

12:启动:service mysql start

13:查看状态:service mysql status

14:将mysql命令添加到服务:ln -s /usr/local/mysql-8.0/bin/mysql /usr/bin

15:登录mysql mysql -uroot -p 密码使用之前随机生成的密码:在初始化时的密码.

16:若报错:mysql: error while loading shared libraries: libtinfo.so.5: cannot open shared object file: No such file or directory

17:安装:sudo yum install ncurses-compat-libs

18:修改密码:ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '123456'; 刷新权限使密码生效:flush privileges;

19:选择mysql数据库:use mysql;

10:修改远程登陆并生效: update user set host='%' where user='root';
flush privileges;