MySQL 8(压缩包版)安装遇到的坑

版本:mysql-8.0.31-winx64
先上my.ini (注意这里需要两个反斜杠\\,否则会报错)

[mysqld]
# 设置3306端口
port=3306
# 设置mysql的安装目录
basedir=E:\\mysql
# 设置mysql数据库的数据的存放目录
datadir=E:\\mysql\\data  
# 允许最大连接数
max_connections=200
# 允许连接失败的次数。这是为了防止有人从该主机试图攻击数据库系统
max_connect_errors=10
# 服务端使用的字符集默认为UTF8
character-set-server=utf8
# 创建新表时将使用的默认存储引擎
default-storage-engine=INNODB
# 默认使用“mysql_native_password”插件认证
default_authentication_plugin=mysql_native_password
[mysql]
# 设置mysql客户端默认字符集
default-character-set=utf8
[client]
# 设置mysql客户端连接服务端时默认使用的端口
port=3306
default-character-set=utf8

1.下载zip压缩包
https://downloads.mysql.com/archives/community/
2.放在E:\mysql目录下

把E:\mysql\bin目录添加到环境变量Path中

3.在安装目录下新建一个my.ini配置文件,内容如上所示。
如果你的mysql安装在其他目录,就修改basedir和datadir

4.打开“命令提示符”以管理员身份运行(点击win键搜索cmd)
输入命令:cd E:\mysql\bin
进入mysql的bin目录

5.初始化数据库
mysqld   –initialize   –console

此时执行两个操作:
5.1生成data文件,存放数据库文件。
5.2生成一个临时密码。在root@localhost:后面

6.安装mysql服务
mysqld  –install  

7.启动服务器
net  start  mysql

8.进入mysql
mysql -u root -p
Enter password: ***********(输入之前生成的临时密码)
登录成功后,光标处变为mysql>

9.修改密码
命令:ALTER USER ‘root’@’localhost’ IDENTIFIED WITH mysql_native_password BY ‘新密码’;  (此命令将临时密码修改为新密码)

10.查看数据库
show databases;

11.退出mysql
quit

12.关闭服务
net  stop  mysql

13.删除mysql
sc delete mysql

你可能会遇到的坑:

1.my.ini中basedir和datadir路径没有双斜杠

2.没有把E:\mysql\bin添加到环境变量中。

3.没有进到bin目录执行命令

4.先执行 mysqld   –initialize   –console
再执行 mysqld  –install  

5.哪些命令是在mysql>状态下,
哪些是退出mysql>执行的。

E:\mysql\bin>mysql -uroot -p
Enter password: ********
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 11
Server version: 8.0.31 MySQL Community Server - GPL

Copyright (c) 2000, 2022, 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> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sys                |
+--------------------+
4 rows in set (0.01 sec)

我遇到过的错误提示:

mysql -uroot -p
Enter password: ********
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)

mysql -uroot
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)

ERROR 2003 (HY000): Can't connect to MySQL server on 'localhost:3306' (10061)

E:\mysql\bin>mysqld --initialize --console
2022-10-25T15:55:27.755826Z 0 [System] [MY-013169] [Server] E:\mysql\bin\mysqld.exe (mysqld 8.0.31) initializing of server in progress as process 1588
2022-10-25T15:55:27.756652Z 0 [Warning] [MY-013242] [Server] --character-set-server: 'utf8' is currently an alias for the character set UTF8MB3, but will be an alias for UTF8MB4 in a future release. Please consider using UTF8MB4 in order to be unambiguous.
2022-10-25T15:55:27.781562Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2022-10-25T15:55:27.981989Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
2022-10-25T15:55:28.527283Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: qQsy)pm+A4Pp