MySQL

如何在Windows 2016上安装MySQL 5.7.39数据库

1 下载并解压MySQL安装文件

到MySQL官网下载5.7.39版本的Windows安装文件,是一个zip压缩包文件mysql-5.7.39-winx64.zip。解压到E:\mysql-5.7.39-winx64路径下。

C:\Users\Administrator>e:
​
E:\>dir
 驱动器 E 中的卷是 新加卷
 卷的序列号是 D080-C622
​
 E:\ 的目录
​
2022/11/14  16:37    <DIR>          databases
2023/03/16  15:35    <DIR>          mysql-5.7.39-winx64
2023/03/16  15:33       322,968,175 mysql-5.7.39-winx64.zip
2022/10/13  18:07    <DIR>          Navicat Premium
               1 个文件    322,968,175 字节
               3 个目录 205,588,385,792 可用字节
​
E:\>

2 执行MySQL数据库初始化

必须以管理员身份运行cmd,进入E:\mysql-5.7.39-winx64\mysql-5.7.39-winx64\bin,然后,执行mysqld.exe –initialize-insecure命令。可以通过mysqld.exe –help查看具体帮助信息。

E:\mysql-5.7.39-winx64>cd mysql-5.7.39-winx64
​
E:\mysql-5.7.39-winx64\mysql-5.7.39-winx64>cd bin
​
E:\mysql-5.7.39-winx64\mysql-5.7.39-winx64\bin>mysqld.exe --initialize-insecure
​
E:\mysql-5.7.39-winx64\mysql-5.7.39-winx64\bin>

注意📢📢📢:命令执行之后,相当于初始化了MySQL内部的默认名为mysql的数据库,创建了root用户,且其默认口令是空。将来登录时,等待输入root用户的密码时,可以直接回车。并且该命令执行结束后,命令行上没有任何提示信息。

3 创建并安装MySQL数据库服务

E:\mysql-5.7.39-winx64\mysql-5.7.39-winx64\bin>mysqld.exe -install
Service successfully installed.
​
E:\mysql-5.7.39-winx64\mysql-5.7.39-winx64\bin>

命令执行成功之后,会提示Service successfully installed.同时,在操作系统层面的服务管理项里,可以看到名为MySQL的服务项。

4 启动MySQL数据库

E:\mysql-5.7.39-winx64\mysql-5.7.39-winx64\bin>net start mysql
MySQL 服务正在启动 .
MySQL 服务已经启动成功。
E:\mysql-5.7.39-winx64\mysql-5.7.39-winx64\bin>

通过net start mysql启动MySQL数据库服务。

5 登录数据库并修改root口令

E:\mysql-5.7.39-winx64\mysql-5.7.39-winx64\bin>mysql -uroot -p
Enter password:    #默认密码为空,直接回车即可
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.39 MySQL Community Server (GPL)
​
Copyright (c) 2000, 2022, 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> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sys                |
+--------------------+
4 rows in set (0.00 sec)
​
mysql> alter user 'root'@'%' identified by 'your_root_password';
ERROR 1396 (HY000): Operation ALTER USER failed for 'root'@'%'
mysql> alter user 'root'@'localhost' identified by 'your_root_password';
Query OK, 0 rows affected (0.00 sec)
​
mysql>

至此,完成了在Windows 2016服务器上安装配置了MySQL 5.7.39数据库。之前一直在Linux服务器上使用MySQL数据库,这是第一次在Windows环境安装配置MySQL数据库,做个记录。

留言