下载地址:https://cdn.mysql.com/archives/mysql-8.0/mysql-8.0.22-winx64.zip
配置环境变量:系统变量path新添加一个如下mysql解压路径,路径最好别带中文
E:\*****\mysql-8.0.22-winx64\bin
配置好之后
打开Windows PowerShell(管理员)
安装服务:mysqld --install
PS C:\WINDOWS\system32> mysqld --install
Service successfully installed.
初始化数据库:mysqld --initialize --console
PS C:\WINDOWS\system32> mysqld --initialize --console
2021-04-16T12:09:17.565631Z 0 [System] [MY-013169] [Server] E:\Program Software\mysql-8.0.22-winx64\bin\mysqld.exe (mysqld 8.0.22) initializing of server in progress as process 7360
2021-04-16T12:09:17.639761Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2021-04-16T12:09:18.211446Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
2021-04-16T12:09:19.477914Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: esyelF,d:0id
上方初始化完成之后会出现一个随机密码,记住这个密码,用于后面访问数据库服务。
启动服务:net start mysql
PS C:\WINDOWS\system32> net start mysql
MySQL 服务正在启动 .
MySQL 服务已经启动成功。
登录数据库:mysql -u root -p
PS C:\WINDOWS\system32> mysql -u root -p
Enter password: ************
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 8.0.22Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.
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>
修改那个随机密码为root
mysql> alter user 'root'@'localhost' identified by 'root';
Query OK, 0 rows affected (0.23 sec)
退出数据库:exit
mysql> exit
Bye
PS C:\WINDOWS\system32>
使用新密码重新登录:mysql -u root -p
PS C:\WINDOWS\system32> mysql -u root -p
Enter password: ****
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 9
Server version: 8.0.22 MySQL Community Server - GPLCopyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.
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>
ok,基本完成。可以改用CMD执行,也可以继续用Windows PowerShell(管理员)进入mysql使用。
最后关闭mysql服务,平时不用的话,关闭其后台服务,节省电脑资源开销:net stop mysql
PS C:\WINDOWS\system32> net stop mysql
MySQL 服务正在停止.
MySQL 服务已成功停止。
在mysql-8.0.22-winx64的主文件夹下,创建my.ini配置文件。填入如下内容:
[mysqld]
character-set-server=utf8mb4
bind-address=0.0.0.0
port=3306
default-storage-engine=INNODB
[mysql]
default-character-set=utf8mb4
[client]
default-character-set=utf8mb4
保存,启动mysql服务时会自动使用该配置。解释一下参数:
[mysqld]设置数据库本身,[mysql]设置数据库服务,[client]设置数据库客户端
卸载这个数据库的方法:先停止服务,然后移除服务
PS C:\WINDOWS\system32>net stop mysql
MySQL 服务正在停止.
MySQL 服务已成功停止。PS C:\WINDOWS\system32>mysqld --remove
服务移除成功
最后删除文件夹。