用了也算小半年的MySQL 还是觉得纯净版(单server)好
以下我来安排8.0MySQL的安装 算是我总结的小教程吧
点击下载

1
2
下载地址:http://download.ganxy03.cn/download/mysql-8.0.32-winx64.zip

解压完成后 在根目录新建my.ini配置文件夹
内容为下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
[mysqld]
# 设置3306端口
port=3306
# 设置mysql的安装目录 ----------是你的文件路径-------------
basedir=D:\APP\mysql-8.0.32-winx64\mysql-8.0.32-winx64
# 设置mysql数据库的数据的存放目录 ---------是你的文件路径data文件夹自行创建
#datadir=D:\APP\mysql-8.0.32-winx64\mysql-8.0.32-winx64\data
# 允许最大连接数
max_connections=200
# 允许连接失败的次数。
max_connect_errors=10
# 服务端使用的字符集默认为utf8mb4
character-set-server=utf8mb4
# 创建新表时将使用的默认存储引擎
default-storage-engine=INNODB
# 默认使用“mysql_native_password”插件认证
#mysql_native_password
default_authentication_plugin=mysql_native_password
[mysql]
# 设置mysql客户端默认字符集
default-character-set=utf8mb4
[client]
# 设置mysql客户端连接服务端时默认使用的端口
port=3306
default-character-set=utf8mb4

要改的是五七行 改成自己的安装目录 和设置自己数据库数据data的位置
完了打开命令提示符的管理员模式
建议是菜单搜索打开 启用管理员模式

1
2
3
4
5
6
7
8
9
10
11
12
13
C:\Windows\System32>d:

D:\>cd APP

D:\APP>cd mysql-8.0.32-winx64

D:\APP\mysql-8.0.32-winx64>cd mysql-8.0.32-winx64

D:\APP\mysql-8.0.32-winx64\mysql-8.0.32-winx64> cd bin

D:\APP\mysql-8.0.32-winx64\mysql-8.0.32-winx64\bin>
手动进入mysql bin文件夹

初始化mysql: mysqld --initialize --console

1
2
3
4
5
6
7
8
9
10
D:\APP\mysql-8.0.32-winx64\mysql-8.0.32-winx64\bin>mysqld --initialize --console
2023-05-19T10:19:10.565838Z 0 [Warning] [MY-010918] [Server] 'default_authentication_plugin' is deprecated and will be removed in a future release. Please use authentication_policy instead.
2023-05-19T10:19:10.565870Z 0 [System] [MY-013169] [Server] D:\APP\mysql-8.0.32-winx64\mysql-8.0.32-winx64\bin\mysqld.exe (mysqld 8.0.32) initializing of server in progress as process 22568
2023-05-19T10:19:10.589188Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2023-05-19T10:19:10.984526Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
2023-05-19T10:19:11.901049Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: 2HJ>dktjatZQ

D:\APP\mysql-8.0.32-winx64\mysql-8.0.32-winx64\bin>
其中最后一行的password is generated for root@localhost: 2HJ>dktjatZQ
2HJ>dktjatZQ 是初始化密码 得找个地方复制好 后面要用

然后安装Mysql mysqld --install mysql

1
2
3
4
5
D:\APP\mysql-8.0.32-winx64\mysql-8.0.32-winx64\bin>mysqld --install mysql
The service already exists!
The current server installed: D:\APP\mysql-8.0.32-winx64\mysql-8.0.32-winx64\bin\mysqld mysql

这里我装过了 所以显示文件已存在 如果你报error 看看是不是没有管理员的权限

启动mysql net start mysql

1
2
3
4
5
6
7
D:\APP\mysql-8.0.32-winx64\mysql-8.0.32-winx64\bin>net start mysql
mysql 服务正在启动 .
mysql 服务已经启动成功。

mysql好像是默认开机自启动的
所以不需要每次开机命令启动

关掉MySQL的命令(虽然不常用)``net stop mysql

1
2
3
4
D:\APP\mysql-8.0.32-winx64\mysql-8.0.32-winx64\bin>net stop mysql
mysql 服务正在停止.
mysql 服务已成功停止。

接下来登陆Mysql mysql -uroot -p

1
2
3
4
5
6
7
D:\APP\mysql-8.0.32-winx64\mysql-8.0.32-winx64\bin>mysql -uroot -p
Enter password:

-u用户名(后面不一定是root 可以自己换)
第一次登陆 输入刚才初始化的密码 2HJ>dktjatZQ


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
D:\APP\mysql-8.0.32-winx64\mysql-8.0.32-winx64\bin>mysql -uroot -p
Enter password: ***************
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 8.0.32 MySQL Community Server - GPL

Copyright (c) 2000, 2023, 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 "新密码";

1
2
3
4
5
6
7
例如:
mysql> ALTER USER "root"@"localhost" IDENTIFIED BY "abc123456";
Query OK, 0 rows affected (0.02 sec)

mysql>

那么你的root登陆密码就是abc123456

随便查询个数据库``show databases;

1
2
3
4
5
6
7
8
9
10
11
12
13
14
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
+--------------------+
4 rows in set (0.02 sec)

mysql>

就搞定了

ps: 如果输完一段命令 它换行又跳-> 是补充没结束的意思 末尾记得加 ;

1
2
3
4
5
6
7
8
9
10
11
12
13
mysql> show databases
-> ;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
+--------------------+
4 rows in set (0.02 sec)

mysql>

另外给MySQL配置环境变量会变得很方便

1
2
3
4
5
6
7
8
9
10
11
12
平时如果直接打开命令提示符 登陆mysql

Microsoft Windows [版本 10.0.22621.1702]
(c) Microsoft Corporation。保留所有权利。

C:\Users\Ganxy>mysql -root -p
'mysql' 不是内部或外部命令,也不是可运行的程序
或批处理文件。

C:\Users\Ganxy>

这是因为找不到mysql 的bin目录
1
2
3
4
5
此电脑->属性->高级系统设置->环境变量->编辑系统变量的Path
加一个你MySQL安装目录的bin文件夹目录就好了
然后一路点确定

就大功告成

然后再试试直接打开命令提示符 win+r mysql -root -p

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
C:\Users\Ganxy>mysql -uroot -p
Enter password:

输入你更改过的密码

C:\Users\Ganxy>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.32 MySQL Community Server - GPL

Copyright (c) 2000, 2023, 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>

看到mysql> 恭喜你登陆成功!
基本的安装你已经完成啦
更多的数据库小tips 等着你发现

另附MySQL常用操作命令 点击跳转