1. 下载解压到指定文件
- 我的是D:\MySQL\mysql-8.0.13
- 对应下面my.ini配置文件路径和环境变量
2. 配置环境变量
- 在path下增加D:\MySQL\mysql-8.0.13\bin;
- 注意分号
3. 在MySQL目录下新建一个my.ini文件
- 内容为下
[mysqld]
# 设置3306端口
port = 3306
# 设置MySQL的安装目录,改成自己的安装目录
basedir = C:\Develop\Software\mysql-8.0.14
# 设置MySQL数据库的数据存放目录,一般在安装目录下创建data文件
datadir = C:\Develop\Software\mysql-8.0.14\data
# 允许最大连接数
max_connections=200
# 允许连接失败的次数。
max_connect_errors=10
# 服务端使用的字符集默认为UTF8
character-set-server=UTF8MB4
# 创建新表时将使用的默认存储引擎
default-storage-engine=INNODB
[mysql]
# 设置mysql客户端默认字符集
default-character-set=UTF8MB4
[client]
# 设置mysql客户端连接服务端时默认使用的端口
port=3306
default-character-set=UTF8MB4
5. 初始化MySQL
- mysqld --initialize-insecure
- 注意事项
- 如果不加insecure则是会生成密码
- 注意事项
- 生成data数据文件
6. 安装MySQL服务
- mysqld --install
7. 开启MySQL服务
- net start mysql
- 开启成功代表MySQL安装成功了
mysql修改密码
- 在cmd中输入mysql -u root -p
- 先进入mysql:输入命令 user mysql
- 如果当前root用户authentication_string字段下有内容,先将其设置为空,否则直接进行下一步骤
- update user set authentication_string='' where user='root';
mysqld -nt-remove
删除服务,用于重装
-
下面直接演示正确修改root密码的步骤:
- 使用ALTER修改root用户密码,方法为 ALTER user 'root'@'localhost' IDENTIFIED BY '新密码'。如下:
ALTER user 'root'@'localhost' IDENTIFIED BY 'Cliu123#'
- 此处有两点需要注意:
- 不需要flush privileges来刷新权限。
- 密码要包含大写字母,小写字母,数字,特殊符号。
- 修改成功; 重新使用用户名密码登录即可;
- 使用ALTER修改root用户密码,方法为 ALTER user 'root'@'localhost' IDENTIFIED BY '新密码'。如下:
注意: 一定不要采取如下形式该密码:
- use mysql;
- update user set authentication_string="newpassword" where user="root";
- 这样会给user表中root用户的authentication_string字段下设置了newpassword值;
- 当再使用ALTER USER 'root'@'localhost' IDENTIFITED BY 'newpassword'时会报错的;
- 因为authentication_string字段下只能是mysql加密后的41位字符串密码;其他的会报格式错误;
ALTER USER 'root'@'localhost' IDENTIFITED BY '123'
C:\Users\hp>mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 8.0.13 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> use mysql;
Database changed
mysql> update user set authentication_string='' where user='root';
Query OK, 0 rows affected (0.00 sec)
Rows matched: 1 Changed: 0 Warnings: 0
mysql> ALTER user 'root'@'localhost' IDENTIFIED BY '123';
Query OK, 0 rows affected (0.09 sec)
=特别注意=
注意这里保存时编码为ansi
否则会报如下错误:error: Found option without preceding group in config file: D:\Program Files\mysql-5.6.25-winx64\my.ini at line: 1 Fatal error in defaults handling. Program aborted。
特别说明.ini文件是window里面的配置文件。保存里面各种默认的数据。安装版的是在安装的时候让你自己选然后系统给你保存进来,zip archive是自己写,都一样。