前提条件:

在mysql官网下载,比如mysql-5.6.26-winx64.zip,解压mysql-5.6.26-winx64,尽量不要去其他网站下载。

wKiom1dTEPaDlqbmAACKL3-lhUk695.png-wh_50


1、win10下,win+x键选择“命令提示符(管理员)”。

(注意:一定要用管理员运行CMD进入DOS!


2、在环境变量PATH中添加:

;D:\Program\MySql\mysql-5.6.26-winx64\bin


3、进入到mysql-5.6.26-winx64的bin目录下

C:\WINDOWS\system32>d:

D:\>cd D:\Program\MySql\mysql-5.6.26-winx64

D:\Program\MySql\mysql-5.6.26-winx64>cd bin


4、输入服务安装命令

D:\Program\MySql\mysql-5.6.26-winx64\bin>mysqld install MySQL --defaults-file="D:\Program\MySql\mysql-5.6.26-winx64\my-default.ini"

Service successfully installed.


(下载的压缩包里如果没有my-default.ini,那么可以手工创建

my-default.ini原始内容为:

# For advice on how to change settings please see

# http://dev.mysql.com/doc/refman/5.6/en/server-configuration-defaults.html

# *** DO NOT EDIT THIS FILE. It's a template which will be copied to the

# *** default location during install, and will be replaced if you

# *** upgrade to a newer version of MySQL.


[mysqld]


# 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 = .....

# datadir = .....

# port = .....

# 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 = 2M

# read_rnd_buffer_size = 2M 


sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES 


5、启动MYSQL服务

D:\Program\MySql\mysql-5.6.26-winx64\bin>net start mysql

MySQL 服务正在启动 .

MySQL 服务已经启动成功。


6、修改MYSQL密码

D:\Program\MySql\mysql-5.6.26-winx64\bin>mysql -uroot

Welcome to the MySQL monitor.  Commands end with ; or \g.

Your MySQL connection id is 1

Server version: 5.6.26 MySQL Community Server (GPL)


Copyright (c) 2000, 2015, 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> show databases;

+--------------------+

| Database           |

+--------------------+

| information_schema |

| mysql              |

| performance_schema |

| test               |

+--------------------+

4 rows in set (0.00 sec)


mysql> use mysql;

Database changed

mysql> UPDATE user SET password=PASSWORD("root") WHERE user='root';

Query OK, 3 rows affected (0.00 sec)

Rows matched: 3  Changed: 3  Warnings: 0


mysql> FLUSH PRIVILEGES;

Query OK, 0 rows affected (0.00 sec)


mysql> QUIT

Bye


7、测试密码是否修改成功

D:\Program\MySql\mysql-5.6.26-winx64\bin>mysql -uroot -proot

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.6.26 MySQL Community Server (GPL)


Copyright (c) 2000, 2015, 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.