Mysql 5.7版本安装(win10)

1. 下载:

https://downloads.mysql.com/archives/community/

安装在 D 盘

2. 环境变量配置:

 

 

 

 

 3. 初始化

直接双击运行 bin/mysql.exe 安装报错?

(1)以管理员身份运行 cmd

 

 (2)在 mysql 的 bin 目录下执行以下命令

//cd bin目录
C:\Windows\system32>d:

D:\>cd mysql-5.7.24-winx64\bin

//安装文件

D:\JavaWebSoftware\mysql-5.7.23-winx64\bin>mysqld --install MySQL

Service successfully installed.

4. 启动服务

//启动服务

D:\JavaWebSoftware\mysql-5.7.23-winx64\bin>net start mysql

报错:ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)

解决办法:在 my.ini 文件中任意地方加入一句话(skip-grant-tables)

问题:没有 my.ini 文件怎么办?

解决:配置 my.ini 文件

(1)暂停 mysql 服务:

单击右键,暂停服务

 (2)新建 my.ini 配置文件:

在mysql程序的根目录下,新建一个my.ini空白文件,用记事本打开,将以下内容复制进去

# http://dev.mysql.com/doc/refman/5.6/en/server-configuration-defaults.html
[client]
default-character-set = utf8
[mysql]
default-character-set = utf8
[mysqld]
character-set-client-handshake = FALSE
character-set-server = utf8
init_connect='SET NAMES utf8'
# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
innodb_buffer_pool_size = 128M
# Remove leading # to turn on a very important data integrity option: logging
# changes to the binary log between backups.
# log_bin
# These are commonly set, remove the # and set as required.
basedir = C:\Program Files\MySQL\MySQL Server 5.7
datadir = C:\Program Files\MySQL\MySQL Server 5.7\data
port = 3306
# server_id = .....
# Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
join_buffer_size = 128M
sort_buffer_size = 16M
read_rnd_buffer_size = 16M 
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
#skip-grant-tables

其中basedir 和 datadir 根据自己电脑上实际MySql安装的位置进行修改

(3)重新生成data文件

在原来打开的cmd窗口继续执行如下命令:

mysqld --initialize-insecure --user=mysql

(4)重新安装mysql服务,同时绑定 my.ini 配置文件
在cmd窗口执行命令:

mysqld --install "MySql57" --defaults-file="D:/MySQL/MySQL Server 5.7/my.ini"

注意:MySql57是自己可以重新命名的MySQL服务名称

如果出现:**The service already exists!**就说明MySQL服务已经安装成功

(5)启动MySQL服务

net start MySql

6:重新设置密码
(1)登录密码
mysql -u root -p
这时密码为空,不需要填写,直接回车:
密码为空需要在my.ini文件的任何位置加入如下代码:

skip-grant-tables

(2)修改root用户密码
选择MySQL数据库后才能修改密码

use mysql;
update mysql.user set authentication_string=password("你的密码") where user="root";

(3)刷新权限并退出

flush privileges;
quit

猜你喜欢

转载自blog.csdn.net/weixin_57092157/article/details/120185908