1.配置环境变量:
我的电脑->属性->高级->环境变量
选择PATH,在其后面添加: 你的mysql bin文件夹的路径 :D:\Program Files\JavaTool\MySQL\mysql-5.6.39-winx64\bin配置环境变量
2.在MySQL安装路径下建立一个my.ini文件
创建位置
在其中修改或添加配置 :[mysqld]
basedir=F:\JAVAWord\mysql-5.7.19-winx64\
datadir=F:\JAVAWord\mysql-5.7.19-winx64\data
# 设置3306端口
port = 3306
skip-grant-tables
3.以管理员身份运行cmd(一定要用管理员身份运行,不然权限不够),
输入命令:cd D:\Program Files\JavaTool\MySQL\mysql-5.6.39-winx64\bin 进入mysql的bin文件夹(不管有没有配置过环境变量,也要进入bin文件夹,否则之后启动服务仍然会报错误2)
输入mysqld -install(如果不用管理员身份运行,将会因为权限不够而出现错误:Install/Remove of the Service Denied!)F:\JAVAWord\mysql-5.7.19-winx64\bin>mysqld -install
Service successfully installed.
4.进入bin目录执行mysqld --initialize-insecure --user=mysqlF:\JAVAWord\mysql-5.7.19-winx64\bin>mysqld --initialize-insecure --user=mysql
5.输入命令:net start mysql,启动MYSQL服务。F:\JAVAWord\mysql-5.7.19-winx64\bin>net start mysql
MySQL 服务正在启动 .
MySQL 服务已经启动成功。
6.服务启动成功之后,输入命令:mysql -u root -p(第一次登录没有密码,直接按回车过)!F:\JAVAWord\mysql-5.7.19-winx64\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.19 MySQL Community Server (GPL)
Copyright (c) 2000, 2017, 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>
7.输入:update mysql.user set authentication_string=password('123456') where user='root' and Host = 'localhost';设置密码mysql> update mysql.user set authentication_string=password('123456') where user='root' and Host = 'localhost' ;
Query OK, 1 row affected, 1 warning (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 1