一、下载
官网下载地下:https://dev.mysql.com/downloads/mysql/
二、安装
1、解压zip包到安装目录
例:D:\soft\tools\mysql-8
2、配置文件
在D:\soft\tools\mysql-8目录下新建my.ini的文件,my.ini文件配置
[mysqld]
# 设置3306端口
port=3306
# 设置mysql的安装目录
basedir=D:\soft\tools\mysql-8
# 设置mysql数据库的数据的存放目录
datadir=D:\soft\tools\mysql-8\data
# 允许最大连接数
max_connections=200
# 允许连接失败的次数。这是为了防止有人从该主机试图攻击数据库系统
max_connect_errors=10
# 服务端使用的字符集默认为UTF8
character-set-server=utf8
# 创建新表时将使用的默认存储引擎
default-storage-engine=INNODB
# 默认使用“mysql_native_password”插件认证
default_authentication_plugin=mysql_native_password
[mysql]
# 设置mysql客户端默认字符集
default-character-set=utf8
[client]
# 设置mysql客户端连接服务端时默认使用的端口
port=3306
default-character-set=utf8
3、初始化数据
在mysql安装目录的bin目录下执行命令
mysqld --initialize --console
执行完成后,会打印出root用户的初始密码:
C:\soft\tools\mysql-8\bin>mysqld --initialize --console
2019-10-08T02:02:53.507151Z 0 [System] [MY-013169] [Server] C:\soft\tools\mysql-8\bin\mysqld.exe (mysqld 8.0.17) initializing of server in progress as process 12224
2019-10-08T02:02:53.508706Z 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-10-08T02:02:57.696885Z 5 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: fZie:ul.j4Dp
2019-10-08T02:02:58.762648Z 0 [System] [MY-013170] [Server] C:\soft\tools\mysql-8\bin\mysqld.exe (mysqld 8.0.17) initializing of server has completed
注意:如没记住密码,可以删除data目录,重新执行命令,生成新密码。
4、安装服务
- 管理员权限下打开命令行
- 进入mysql安装目录下的bin目录执行命令
mysqld --install [服务名]
D:\soft\tools\mysql-8\bin>mysqld --install mysql8
Service successfully installed.
3.通过net start mysql8启动服务
D:\soft\tools\mysql-8\bin>net start mysql8
mysql8 服务正在启动 ..
mysql8 服务已经启动成功。
三、更改密码
1.登录数据库,执行命令:
mysql -u root -p
C:\soft\tools\mysql-8\bin>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.17
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>
2.修改密码,执行命令:
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '新密码';
mysql> ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '12345678';
Query OK, 0 rows affected (0.01 sec)
mysql>
3.navicat测试连接