MySQL5.7免安装版

下载对应版本的压缩包:https://dev.mysql.com/downloads/mysql/

解压到想要的目录中,如D盘根目录:

《MySQL5.7免安装版》 image.png

配置环境变量:在Path添加D:\mysql-5.7.21-winx64\bin

在D:\mysql-5.7.21-winx64目录下新建my.ini

[mysqld]
basedir=D:\mysql-5.7.21-winx64
datadir=D:\mysql-5.7.21-winx64\data\
port=3306
skip-grant-tables
#更加的配置项可根据自己的需要添加

安装mysqld服务,在管理员模式下的CMD:

mysqld –install

启动mysql服务和初始化数据文件,之前按照网上的做法,网上一些文章是先net start mysql,再mysqld --initialize,但这样做在这两步时会遇到一些问题

D:\mysql-5.7.21-winx64\bin>net start mysql
MySQL 服务正在启动 .
MySQL 服务无法启动。

服务没有报告任何错误。

请键入 NET HELPMSG 3534 以获得更多的帮助。

启动mysql服务时,遇到上面的问题,这个时候是因为还没有创建D:\mysql-5.7.21-winx64\data\目录,创建了这个目录后就启动正常,但又会遇到一个问题,就是初始化数据文件时会遇到:

D:\mysql-5.7.21-winx64\bin>mysqld  --initialize
2018-03-31T01:39:56.838258Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2018-03-31T01:39:56.842010Z 0 [ERROR] --initialize specified but the data directory has files in it. Aborting.
2018-03-31T01:39:56.843229Z 0 [ERROR] Aborting

这个问题是D:\mysql-5.7.21-winx64\data\目录不为空。

所以要停掉服务,删掉D:\mysql-5.7.21-winx64\data\目录,先初始化数据文件,再启动mysql服务

net stop mysql

mysqld  --initialize

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

使用mysqld --initialize初始化数据文件时,没有初始密码,需要为root设置密码:

D:\mysql-5.7.21-winx64\bin>mysql -u root -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.21 MySQL Community Server (GPL)

Copyright (c) 2000, 2018, 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 for 'root'@'localhost' password=password('这里填写密码');

    原文作者:钱铜
    原文地址: https://www.jianshu.com/p/e35327c61072
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞