Windows下安装MySQL8.0
1.下载安装包
mysql-8.0.20-winx64.zip
2.解压缩,配置环境变量
将mysql加入到系统path中(不多说)
E:\work\mysql-8.0.20\bin
3.新建配置文件
在安装目录下新建my.ini配置文件(E:\work\mysql-8.0.20\my.ini)
[mysqld]
#安装目录
basedir=E:\work\mysql-8.0.20
#data不要手动创建,初始化时 会自动创建
datadir=E:\work\mysql-8.0.20\data\
#端口
port=3306
#跳过密码验证,8.0以上版本开启会报错,所以不需要加下面命令
#skip-grant-tables
4.管理员模式下打开cmd,运行所有的命令
进入mysql安装目录下的bin目录:
C:\Users\Administrator>cd /d E:\work\mysql-8.0.20\bin
输入mysqld -install
E:\work\mysql-8.0.20\bin>mysqld -install
Service successfully installed.
#只有出现Service successfully installed. 才算注册服务成功
5.输入 mysqld --initialize-insecure --user=mysql 初始化数据文件
E:\work\mysql-8.0.20\bin>mysqld --initialize-insecure --user=mysql --console
#执行完毕后,mysql安装目录下自动生成data文件夹
#执行完毕后,会给个临时密码,密码不一样相同(fkVQUk/ei7n,)
#A temporary password is generated for root@localhost: fkVQUk/ei7n,
6.启动mysql
E:\work\mysql-8.0.20\bin>net start mysql
MySQL 服务正在启动 ...
MySQL 服务已经启动成功。
#上述命令执行后,可在系统服务里看到MySql服务已经启动,正在运行
7.进入mysql
E:\work\mysql-8.0.20\bin>mysql -u root -p # p后面一定不要加空格
Enter password: ************ #这个密码就是尚明生成的临时密码 fkVQUk/ei7n,
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 8.0.20
Copyright (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.
8.修改密码
# 8.0以上版本修改密码 不能使用 update语句,必须使用alter user ....
mysql> ALTER USER 'root'@'localhost' identified by '123456';
Query OK, 0 rows affected (0.10 sec)
#刷新权限缓存
mysql> flush privileges;
Query OK, 0 rows affected (0.06 sec)
#退出
mysql> exit;
Bye
-
重启mysql
E:\work\mysql-8.0.20\bin>net stop mysql MySQL 服务正在停止. MySQL 服务已成功停止。 E:\work\mysql-8.0.20\bin>net start mysql MySQL 服务正在启动 ... MySQL 服务已经启动成功。
10.登陆测试
E:\work\mysql-8.0.20\bin>mysql -u root -p # -p后面一定不要加空格 Enter password: ****** # 输入新的密码 Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 9 Server version: 8.0.20 MySQL Community Server - GPL Copyright (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.