Published on

windows安装 mysql 8.0.19

Authors

前言

windows安装东西就是麻烦,一大堆坑。 尝试了好久,终于ok了,记录一下。 环境:windows10 x64, mysql 8.0.19

mysql下载地址

搜狐的国内镜像-Mysql-8.0.19 解压缩到硬盘。

安装

  • 新建一个my.ini
[mysqld]
# 设置3306端口
port=3306
# 设置mysql的安装目录
basedir=D:\\tjsql\mysql-8.0.19-winx64
# 设置mysql数据库的数据的存放目录
datadir=D:\\tjsql\Data
# 允许最大连接数
max_connections=200
# 允许连接失败的次数。
max_connect_errors=10
# 服务端使用的字符集默认为utf8mb4
character-set-server=utf8mb4
# 创建新表时将使用的默认存储引擎
default-storage-engine=INNODB
# 默认使用“mysql_native_password”插件认证
#mysql_native_password
default_authentication_plugin=mysql_native_password
[mysql]
# 设置mysql客户端默认字符集
default-character-set=utf8mb4
[client]
# 设置mysql客户端连接服务端时默认使用的端口
port=3306
default-character-set=utf8mb4
  • 进入到mysql路径 输入命令:mysqld --initialize --console
D:\tjsql\mysql-8.0.19-winx64\bin
λ mysqld --initialize --console
2020-04-16T08:39:23.366388Z 0 [System] [MY-013169] [Server] D:\tjsql\mysql-8.0.19-winx64\bin\mysqld.exe (mysqld 8.0.19) initializing of server in progress as process 5764
2020-04-16T08:39:35.622820Z 5 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: q#Uyy#3Blmw;

上方生成的这一串q#Uyy#3Blmw;是root用户密码,注意符号,这个密码是随机生成的,包括符号也是密码的一部分。

  • 安装服务
mysqld --install [服务名]
Service successfully installed.

服务名缺省,不填,默认为mysql

  • 启动服务
net start mysql
MySQL 服务正在启动 ..
MySQL 服务已经启动成功。
  • 登录
λ 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.19

Copyright (c) 2000, 2020, 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>
  • 修改默认密码 将密码修改为123
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY '123';

完成