Windows安装MySQL8.0.16

1、安装包下载:

链接:https://pan.baidu.com/s/1UvhqVWTDcG_a8MdOM-aHDQ 
提取码:wg01 

2、解压

将MySQL安装包解压到指定文件夹下,我在这里默认安装到了这个目录下
D:\mysql8\mysql-8.0.16-winx64
Windows安装MySQL8.0.16_第1张图片

3、配置环境变量

在windows里面配置环境变量(和配置JAVA_HOME的流程一样)
右键点击我的电脑->属性->高级系统设置–>环境变量
在系统变量中新增属性:MYSQL_HOME,值为:D:\mysql8\mysql-8.0.16-winx64

Windows安装MySQL8.0.16_第2张图片
然后修改PATH变量,把%MYSQL_HOME%\bin添加到PATH变量中
注意:最好将此变量移动到最前面,这样可以保证在使用mysql命令的时候优先使用此路径下的mysql。

Windows安装MySQL8.0.16_第3张图片

4、创建my.ini配置文件

进入D:\mysql8\mysql-8.0.16-winx64目录,创建my.ini配置文件

Windows安装MySQL8.0.16_第4张图片
my.ini文件内容如下:

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

5、初始化

通过cmd命令行,cd到mysql的bin目录中

C:\Users\lenovo>d:
D:\>cd D:\mysql8\mysql-8.0.16-winx64
D:\mysql8\mysql-8.0.16-winx64>cd bin
D:\mysql8\mysql-8.0.16-winx64\bin>

执行mysql的初始化命令

D:\mysql8\mysql-8.0.16-winx64\bin>mysqld --initialize --console
2020-11-12T07:29:28.608365Z 0 [System] [MY-013169] [Server] D:\mysql8\mysql-8.0.16-winx64\bin\mysqld.exe (mysqld 8.0.16) initializing of server in progress as process 4540
2020-11-12T07:29:28.613122Z 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.
2020-11-12T07:29:32.894507Z 5 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: g>y.P9=q<86%
2020-11-12T07:29:34.260847Z 0 [System] [MY-013170] [Server] D:\mysql8\mysql-8.0.16-winx64\bin\mysqld.exe (mysqld 8.0.16) initializing of server has completed

注意:执行mysql的初始化命令之后,在下面的第三行日志中会显示mysql的临时密码,后面登录的时候会使用到。

在这个日志里面,第三行内容是这样的:

2020-11-12T07:29:32.894507Z 5 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: g>y.P9=q<86%

这行日志中root@localhost:后面的g>y.P9=q<86%就是临时密码。

6、安装mysql服务

安装mysql服务,添加到开机启动项中

D:\mysql8\mysql-8.0.16-winx64\bin>mysqld install mysql8
Service successfully installed.

注意:如果执行install之后,日志显示的不是successfully,而是Install/Remove of the Service Denied!,则需要以管理员身份打开cmd命令行,重新执行install命令即可

7、启动mysql

注意:第一次需要手工启动mysql,以后重启电脑之后mysql就可以自动启动了。

D:\mysql8\mysql-8.0.16-winx64\bin>net start mysql8
mysql8 服务正在启动 .
mysql8 服务已经启动成功。

8、 进行登录mysql

接下来就可以登录mysql了
注意:密码区分大小写,默认生成的临时密码比较复杂,建议直接复制,手动输入容易出错。

D:\mysql8\mysql-8.0.16-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.16
Copyright (c) 2000, 2019, 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>

9、修改密码

修改mysql密码,建议将密码设置为admin,和课程中保持一致,不容易忘。

mysql> alter user root@localhost identified by 'admin';
Query OK, 0 rows affected (0.01 sec)
mysql> exit
Bye

10、重新使用新密码登录mysql

D:\mysql8\mysql-8.0.16-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.16 MySQL Community Server - GPL
Copyright (c) 2000, 2019, 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>

11、开启mysql远程访问权限

默认情况下,此mysql数据库只能在本地访问,其它机器访问不了,所以需要开启远程访问权限。

mysql> select host,user from mysql.user;
+-----------+------------------+
| host      | user             |
+-----------+------------------+
| localhost | mysql.infoschema |
| localhost | mysql.session    |
| localhost | mysql.sys        |
| localhost | root             |
+-----------+------------------+
4 rows in set (0.00 sec)

在这里可看到root用户对应的host地址为localhost,所以此时想要使用root用户访问mysql,只能在本地访问。
想要开启远程访问,只需要修改user表中root用户对应的host字段的值即可,将host字段的值改为%,表示允许任意ip访问。

mysql> update mysql.user set host='%' where user = 'root';
Query OK, 1 row affected (0.01 sec)
Rows matched: 1  Changed: 1  Warnings: 0
mysql> flush privileges;
Query OK, 0 rows affected (0.01 sec)

注意:flush privileges;这条命令一定要执行,它会刷新最新的权限信息。

此时再查询user表中的数据:

mysql> select host,user from mysql.user;
+-----------+------------------+
| host      | user             |
+-----------+------------------+
| %         | root             |
| localhost | mysql.infoschema |
| localhost | mysql.session    |
| localhost | mysql.sys        |
+-----------+------------------+
4 rows in set (0.00 sec)

12、验证mysql远程访问权限是否成功开启

可以在windows本地直接验证mysql远程访问权限是否成功开启
首先查询当前windows机器的ip信息【使用VMnet8网卡中的ip信息即可】

D:\mysql8\mysql-8.0.16-winx64\bin>ipconfig
Windows IP 配置
以太网适配器 VMware Network Adapter VMnet8:
   连接特定的 DNS 后缀 . . . . . . . :
   本地链接 IPv6 地址. . . . . . . . : fe80::f822:404f:e21c:262f%15
   IPv4 地址 . . . . . . . . . . . . : 192.168.182.1
   子网掩码  . . . . . . . . . . . . : 255.255.255.0
   默认网关. . . . . . . . . . . . . :

通过内网192开头的ip进行访问mysql,如果能正常访问,就说明mysql的远程访问权限成功开启了,到时候我们在bigdata04机器上就可以访问这个数据库

D:\mysql8\mysql-8.0.16-winx64\bin>mysql -h 192.168.182.1 -uroot -p
Enter password: *****
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 14
Server version: 8.0.16 MySQL Community Server - GPL
Copyright (c) 2000, 2019, 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>

数据库连接工具进行连接

或者通过mysql数据库连接工具HediSQL进行连接
HediSQL下载地址:

链接:https://pan.baidu.com/s/141MukxxO34iTDtHN6svgeA 
提取码:dix2 

Windows安装MySQL8.0.16_第5张图片
Windows安装MySQL8.0.16_第6张图片

你可能感兴趣的:(MySQL,mysql)