说明
-
本教程只是MySQL手动版的安装与配置。这往往是喜欢从CMD中执行MySQL代码或者是希望需要下载的文件尽可能小的使用者的偏爱。如果您和他们与众不同,比起钻木取火,更喜欢打火机,您可以选择集成的IDE来避免进行本教程中讲述的烦琐操作。关于这方面的内容,可见笔者的另一篇博客: MySQL Community 安装教程:https://blog.csdn.net/wangpaiblog/article/details/112000033
-
阅读本教程之前,需要在网上下载MySQL的压缩包,这其中包含 my.ini 等文件。笔者很愿意将这些资源免费发布,但由于版权的问题,读者需要在网上自行下载。如果实在找不到,也可在下方留言联系。笔者在看到这些消息之后将免费提供,希望读者收到后不要自由传播。
自行下载的方法如下:(如果选择下面的到官网下载,还需要在下载完成之后在MySQL目录下创建一个 my.ini 文件)- 打开MySQL官网,找到Community版的下载。选择Community是因为该版本免费而且是一般使用的版本。具体的流程如下面的图片所示。
MySQL的官网是:https://www.mysql.com/
MySQL下载处的最终网址:https://dev.mysql.com/downloads/mysql/
- 打开MySQL官网,找到Community版的下载。选择Community是因为该版本免费而且是一般使用的版本。具体的流程如下面的图片所示。
步骤
-
将得到的MySQL解压文件夹放置在某个你喜欢的磁盘目录(目录不能出现中文字符,这里以E盘为例),且可将该文件夹重命名为你喜欢的名称(同样的,该名称不能出现中文字符,这里以MySQL为例)。
-
用文本文档打开MySQL文件夹中的 my.ini 文件,将“
# 设置MySQL的安装目录 basedir=E:\MySQL
# 设置MySQL数据库的数据的存放目录 datadir=E:\MySQL\data ”
这几行中所提到的文件路径分别改为与当前MySQL文件夹有关的正确的路径。 -
修改系统变量:
我的电脑/计算机‐>属性‐>高级系统设置‐>环境变量‐>(系统变量)path‐>编辑, 将MySQL文件夹下的bin放到里面。最后在那个目录的路径后面加个英文的分号“;”,然后保存。如我的配置“ E:\MySQL\bin; ”。

- 以管理员身份运行cmd.exe 。
-
在CMD中输入以下命令:
A)安装服务:输入“ mysqld install ”回车运行;B) 再输入“ mysqld --initialize ”初始化data 目录;(注意:mysqld 后面一定要有空格和两条“-”)
C.启动服务:接着就是输入“ net start mysql ”启动服务;
D. 输入“ mysql -u root -p ”回车(mysql、root后面都要有空格,u、p前面都是一条“-”),提示你输入密码。这个随机密码可在 E:\mysql\data 文件夹里文件名后缀为 err 的 文件里找。具体方法是用记事本打开该文件,找到带password的一行(“ A temporary password is generated for root@localhost: ”)后面的随机密码,认证通过后进入mysql 后台;
E.输入“ use mysql; ”打开系统数据库;
F.配置自己的新密码:“ mysql> set password for root@localhost =password(‘helloworld’); ” (注意:密码请记住,否则以后无法进入后台管理系统。);
G.输入“exit”回车退出mysql;输入“ net stop mysql ”停止mysql服务;
H.输入“ show variables like ‘character%’; ”如果都是utf8和binary字符,没有lartin1字符,则表示配置成功;输入“ show databases; ”显示所有的数据库;
以上步骤如果有哪一步失败,可以重启电脑重来。下面是一个输出窗口的事例,仅供参考:
Microsoft Windows [版本 10.0.14393]
(c) 2016 Microsoft Corporation。保留所有权利。
C:\windows\system32>e:
E:\>cd mysql
E:\mysql>cd bin
E:\mysql\bin>mysqld install
Service successfully installed.
E:\mysql\bin>mysqld --initialize
E:\mysql\bin>net start mysql
MySQL 服务正在启动 .
MySQL 服务已经启动成功。
E:\mysql\bin>mysql -u root -p
Enter password: ************
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.7.17 MySQL Community Server (GPL)
Copyright (c) 2000, 2016, 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> use mysql
Database changed
mysql> exit
Bye
E:\mysql\bin>net stop mysql
MySQL 服务正在停止.
MySQL 服务已成功停止。
E:\mysql\bin>net start mysql
MySQL 服务正在启动 .
MySQL 服务已经启动成功。
E:\mysql\bin>mysql -u root -p
Enter password: ************
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.7.17
Copyright (c) 2000, 2016, 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> set password for root@localhost =password('helloworld');
Query OK, 0 rows affected, 1 warning (0.00 sec)
mysql> show variables like 'character%';
+--------------------------+--------------------------+
| Variable_name | Value |
+--------------------------+--------------------------+
| character_set_client | utf8 |
| character_set_connection | utf8 |
| character_set_database | utf8 |
| character_set_filesystem | binary |
| character_set_results | utf8 |
| character_set_server | utf8 |
| character_set_system | utf8 |
| character_sets_dir | E:\mysql\share\charsets\ |
+--------------------------+--------------------------+
8 rows in set, 1 warning (0.01 sec)
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
+--------------------+
4 rows in set (0.00 sec)
mysql> exit
Bye
E:\mysql\bin>net stop mysql
MySQL 服务正在停止.
MySQL 服务已成功停止。
E:\mysql\bin>net start mysql
MySQL 服务正在启动 .
MySQL 服务已经启动成功。
E:\mysql\bin>mysql -u root -p
Enter password: *
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
E:\mysql\bin>mysql -u root -p
Enter password: ********
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.7.17 MySQL Community Server (GPL)
Copyright (c) 2000, 2016, 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> exit
Bye
E:\mysql\bin>net stop mysql
MySQL 服务正在停止.
MySQL 服务已成功停止。