百度云盘: https://pan.baidu.com/s/1Bob80HghfLtKJ2l8FEiB4Q 密码:spvf
官网下载: https://dev.mysql.com/downloads/mysql/5.7.html#downloads
选择自己的版本下载
选这里跳过登录
如图路径: D:\Tools\mysql-5.7.27-winx64
创建一个空的文件 my.ini 内容如下 . 自行更改安装目录以及数据存放目录.
数据存放目录需要自己手动创建 : D:\Tools\mysql-5.7.27-winx64\data
[mysql]
# 设置mysql客户端默认字符集
default-character-set=utf8
[mysqld]
skip-name-resolve
skip-grant-tables
#设置3306端口
port = 3306
# 设置mysql的安装目录
basedir=D:\Tools\mysql-5.7.27-winx64
# 设置mysql数据库的数据的存放目录
datadir=D:\Tools\mysql-5.7.27-winx64\data
# 允许最大连接数
max_connections=200
# 服务端使用的字符集默认为8比特编码的latin1字符集
character-set-server=utf8
# 创建新表时将使用的默认存储引擎
default-storage-engine=INNODB
MYSQL_HOME
D:\Tools\mysql-5.7.27-winx64
Path
%MYSQL_HOME%\bin;
在“命令提示符”中,执行net stop mysql
关闭 MySQL Server。
再执行mysqld --skip-grant-tables
开启无密码的 MySQL Server。
打开一个新的“命令提示符”,执行mysql -u root
登陆 MySQL Server。
执行flush privileges;
刷新权限。
执行grant all privileges on *.* to 'root'@'localhost' identified by '你想设置的密码' with grant option;
。
执行flush privileges;
刷新新的 root 用户密码。
执行exit
退出 MySQL。
mysqld --skip-grant-tables 命令窗口 按 contral+C 取消,
或者
在任务管理器里面 杀掉 mysqld.exe
在“命令提示符”下执行net start mysql
重新开启MySQL Server,再次使用mysql -u root -p 你设置的密码
即可安全登陆 MySQL。
更改 mysql 数据库中的user 表, 使得 name 为 root 的账户对应的 host 为'%'
D:\Tools\mysql-5.7.27-winx64\bin>mysql -u root -proot
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.27 MySQL Community Server (GPL)
Copyright (c) 2000, 2019, 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>
mysql>
mysql>
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
+--------------------+
4 rows in set (0.00 sec)
mysql>
mysql>
mysql>
mysql> use mysql
Database changed
mysql>
mysql>
mysql> select user, host from user ;
+---------------+-----------+
| user | host |
+---------------+-----------+
| mysql.session | localhost |
| mysql.sys | localhost |
| root | localhost |
+---------------+-----------+
3 rows in set (0.00 sec)
mysql>
mysql>
mysql>
mysql> update user set host = '%' where user = 'root' ;
Query OK, 1 row affected (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 0
mysql>
mysql>
mysql>
mysql> select user, host from user ;
+---------------+-----------+
| user | host |
+---------------+-----------+
| root | % |
| mysql.session | localhost |
| mysql.sys | localhost |
+---------------+-----------+
3 rows in set (0.00 sec)
mysql>
mysql>
mysql>
mysql> exit
Bye