#官网下载:https://dev.mysql.com/downloads/mysql/
C:\Users\kk\software\mysql-8.0.25-winx64\bin>
#解压下载好的压缩包放到你想要放的目录:
#用管理员打开CMD,切换到MySql的解压目录下的bin目录:
C:\Users\kk\software\mysql-8.0.25-winx64>cd bin
#再输入命令mysqld --initialize --console来初始化数据库,并记录红色标注的字符,这是随机生成的密码:
C:\Users\kk\software\mysql-8.0.25-winx64\bin>mysqld --initialize --console
2021-06-27T07:47:53.732691Z 0 [System] [MY-013169] [Server] C:\Users\kk\software\mysql-8.0.25-winx64\bin\mysqld.exe (mysqld 8.0.25) initializing of server in progress as process 13432
2021-06-27T07:47:53.742982Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2021-06-27T07:47:54.302059Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
2021-06-27T07:47:55.757145Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: *(il5t;cmB9M
#输入mysqld -install将mysql安装为Windows的服务:
C:\Users\kk\software\mysql-8.0.25-winx64\bin>mysqld -install
Service successfully installed.
#输入命令net start mysql或sc start mysql启动mysql服务
C:\Users\kk\software\mysql-8.0.25-winx64\bin>net start mysql
The MySQL service is starting.
The MySQL service was started successfully.
#输入mysql -u root -p来登陆数据库,并输入前面记录的临时密码:
C:\Users\kk\software\mysql-8.0.25-winx64\bin>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.25
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.
#登陆成功后输入命令alter user ‘root’@‘localhost’ identified by ‘想要设置的密码’;将原来复杂的密码修改为自己的密码,并输入commit;提交:
mysql> alter user 'root'@'localhost' identified by '123456';
Query OK, 0 rows affected (0.01 sec)
mysql> commit;
Query OK, 0 rows affected (0.00 sec)
#输入quit or exit退出数据库,再次登陆数据库,这时我们用的是我们修改后的密码登陆的:
mysql> exit;
Bye
C:\Users\kk\software\mysql-8.0.25-winx64\bin>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>
#最后我们将Mysql的bin目录配置到环境变量中,方便我们下次启动,而不用切换路径:
#停止MySQL服务:
net stop mysqld或sc stop mysqld
#删除MySQL服务:
sc delete mysqld或mysqld -remove(需先停止服务)