版权声明:本文为博主原创文章,转载注明出处,欢迎多多交流,乐在沟通,有需要请联系邮箱:[email protected] https://blog.csdn.net/weixin_42749765/article/details/88186370
1.官网下载zip包
2.放到本地某个盘中
解压到当前目录下
3.windows 中大部分没有 data 目录和 my-default.ini
自己建立一个my.ini
4.将下面的代码拷入自己建一个my.ini文件
[mysql]
# 设置mysql客户端默认字符集
default-character-set=utf8
[mysqld]
# 设置3306端口
port = 3306
# 设置mysql的安装目录
basedir=E:\mysql\mysql-8.0.15-winx64
datadir=E:\mysql\mysql-8.0.15-winx64\data
#允许最大连接数
max_connections=200
#服务端使用的字符集默认为8比特编码的latin1字符集
character-set-server=utf8
#创建新表时将使用的默认存储引擎
default-storage-engine=INNODB
#
default_authentication_plugin=mysql_native_password
- data 目录会自动生成
5.在bin目录下输入命令
E:\mysql\mysql-8.0.15-winx64\bin>mysqld install
Service successfully installed.
E:\mysql\mysql-8.0.15-winx64\bin>mysqld --initialize
E:\mysql\mysql-8.0.15-winx64\bin>
E:\mysql\mysql-8.0.15-winx64\bin>net start mysql
MySQL 服务正在启动 ....
MySQL 服务已经启动成功。
E:\mysql\mysql-8.0.15-winx64\bin>
- 如果发现data 目录出现了就说明安装成功了
6.用net start mysql 启动服务
7.重点
- 需要用管理员模式打开命令行cmd
8.登录 第一次无密码登录
- 8.0之前可以在my.ini 中设置 skip-grant-table
- 8.0之后 命令行输入 mysqld --console --skip-grant-tables --shared-memor
E:\mysql\mysql-8.0.15-winx64\bin>net start mysql
MySQL 服务正在启动 ...
MySQL 服务已经启动成功。
E:\mysql\mysql-8.0.15-winx64\bin>mysqld --console --skip-grant-tables --shared-memory
2019-03-05T10:13:48.237493Z 0 [System] [MY-010116] [Server] E:\mysql\mysql-8.0.15-winx64\bin\mysqld.exe (mysqld 8.0.15) starting as process 2244
2019-03-05T10:13:48.241066Z 0 [Warning] [MY-013242] [Server] --character-set-server: 'utf8' is currently an alias for the character set UTF8MB3, but will be an alias for UTF8MB4 in a future release. Please consider using UTF8MB4 in order to be unambiguous.
2019-03-05T10:13:48.371769Z 1 [ERROR] [MY-012271] [InnoDB] The innodb_system data file 'ibdata1' must be writable
2019-03-05T10:13:48.371796Z 1 [ERROR] [MY-012278] [InnoDB] The innodb_system data file 'ibdata1' must be writable
2019-03-05T10:13:48.371844Z 1 [ERROR] [MY-010334] [Server] Failed to initialize DD Storage Engine
2019-03-05T10:13:48.372336Z 0 [ERROR] [MY-010020] [Server] Data Dictionary initialization failed.
2019-03-05T10:13:48.397825Z 0 [ERROR] [MY-010119] [Server] Aborting
2019-03-05T10:13:48.398847Z 0 [System] [MY-010910] [Server] E:\mysql\mysql-8.0.15-winx64\bin\mysqld.exe: Shutdown complete (mysqld 8.0.15) MySQL Community Server - GPL.
E:\mysql\mysql-8.0.15-winx64\bin>
- 然后打开一个新的cmd 命令行界面输入 mysql -uroot -p 直接回车 回车 就进去了
E:\mysql\mysql-8.0.15-winx64\bin>mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 8.0.15 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>
获取密码还有一种方式:
- 将E:\mysql\mysql-8.0.15-winx64\data中的内容都删掉然后 mysqld --initialize --console 初始化一下
- 也可以在一开始 调用 mysqld --initialize 的时候就加上 --console
E:\mysql\mysql-8.0.15-winx64\bin>net stop mysql
MySQL 服务正在停止.
MySQL 服务已成功停止。
E:\mysql\mysql-8.0.15-winx64\bin>mysqld --initialize --console
2019-03-05T11:11:00.377576Z 0 [System] [MY-013169] [Server] E:\mysql\mysql-8.0.15-winx64\bin\mysqld.exe (mysqld 8.0.15) initializing of server in progress as process 5496
2019-03-05T11:11:00.379725Z 0 [Warning] [MY-013242] [Server] --character-set-server: 'utf8' is currently an alias for the character set UTF8MB3, but will be an alias for UTF8MB4 in a future release. Please consider using UTF8MB4 in order to be unambiguous.
2019-03-05T11:11:40.711827Z 5 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: hV!aqhEha8Vw
2019-03-05T11:11:51.321276Z 0 [System] [MY-013170] [Server] E:\mysql\mysql-8.0.15-winx64\bin\mysqld.exe (mysqld 8.0.15) initializing of server has completed
E:\mysql\mysql-8.0.15-winx64\bin>
- 在打印出来的倒数第二行 [Note] 最后有零时密码 for root@localhost: hV!aqhEha8Vw
- 2019-03-05T11:11:40.711827Z 5 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: hV!aqhEha8Vw
- 拿这个来登录然后再修改自己想要的密码
E:\mysql\mysql-8.0.15-winx64\bin>mysql -u root -p
Enter password: ************
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 10
Server version: 8.0.15
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> ALTER USER 'root'@'localhost' IDENTIFIED BY '123456';
Query OK, 0 rows affected (0.11 sec)
mysql>
- 密码就是上边那个
ok
文章会根据官方文档持续更新,转发带上文字出处方便更新!