tar -xf mysql-8.0.25-linux-glibc2.12-x86_64.tar.xz -C /usr/local/
mv /usr/local/mysql-8.0.25-linux-glibc2.12-x86_64 /usr/local/mysql-8.0.25
2、创建用户与目录
groupadd mysql
useradd mysql -g mysql
mkdir -p /data/mysql/{data,log}
chown -R mysql.mysql /data/mysql/
3、初始化数据库
/usr/local/mysql-8.0.25/bin/mysqld --initialize-insecure --user=mysql --basedir=/usr/local/mysql-8.0.25 --datadir=/data/mysql/data
#输出如下
2022-09-08T06:48:31.860364Z 0 [System] [MY-013169] [Server] /usr/local/mysql-8.0.25/bin/mysqld (mysqld 8.0.25) initializing of server in progress as process 11562
2022-09-08T06:48:31.867586Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2022-09-08T06:48:33.123966Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
2022-09-08T06:48:35.183683Z 6 [Warning] [MY-010453] [Server] root@localhost is created with an empty password ! Please consider switching off the --initialize-insecure option.
#由于初始化的时候没有设置密码,这里直接进入
root@michael ~]# mysql
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 8.0.25 MySQL Community Server - GPL
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 root@localhost identified by 'ljl123!@#';
Query OK, 0 rows affected (0.01 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.01 sec)
mysql> \q
Bye
#再次输入密码登录
mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 9
Server version: 8.0.25 MySQL Community Server - GPL
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>
9、配置navicat连接
mysql> use mysql;
mysql> update user set host='%' where user='root';
mysql> alter user 'root'@'%' identified with mysql_native_password by 'ljl123!@#';
mysql> flush privileges;
#使用Navicat连接即可