回到顶部

阅读目录

windows 安装 mysql 8.0+

下载 mysql

下载页面 MySQL :: Download MySQL Community Server

安装 MySQL

下载完成之后,解压 zip 包,再把整个解压之后的结果放到 D 盘(其他盘也可以)。打开这个 MySQL 文件夹,里面的文件如下图所示:

配置 MySQL

[mysqld]
# 设置mysql的安装目录,我们实际存放MySQL的目录
basedir=D:/mysql-8.0.32-winx64
# 设置mysql数据库的数据的存放目录
datadir=D:/mysql-8.0.32-winx64/data
# 设置默认使用的端口
port=3306
# 允许最大连接数
max_connections=200
# 允许连接失败的次数。这是为了防止有人试图攻击数据库
max_connect_errors=10
# 服务端使用的字符集
character-set-server=utf8mb4
# 数据库字符集对应一些排序等规则使用的字符集
collation-server=utf8mb4_general_ci
# 创建新表时将使用的默认存储引擎
default-storage-engine=INNODB
# 默认使用“mysql_native_password”插件作为认证加密方式
# MySQL8.0默认认证加密方式为caching_sha2_password
default_authentication_plugin=mysql_native_password
 
[mysql]
# 设置mysql客户端默认字符集
default-character-set=utf8mb4
 
[client]
default-character-set=utf8mb4
port=3306

bin目录加入环境变量

初始化 MySQL

打开cmd,快捷键“win+R”,输入cmd再回车,即可打开cmd。执行初始化命令,该命令会创建一个密码为空的root用户。

mysqld --initialize-insecure --user=mysql --console
D:\mysql-8.0.32-winx64>mysqld --initialize-insecure --user=mysql --console
2023-02-27T06:33:22.062461Z 0 [Warning] [MY-010918] [Server] 'default_authentication_plugin' is deprecated and will be removed in a future release. Please use authentication_policy instead.
2023-02-27T06:33:22.062480Z 0 [System] [MY-013169] [Server] D:\mysql-8.0.32-winx64\bin\mysqld.exe (mysqld 8.0.32) initializing of server in progress as process 49700
2023-02-27T06:33:22.081374Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2023-02-27T06:33:22.885540Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
2023-02-27T06:33:24.034585Z 6 [Warning] [MY-010453] [Server] root@localhost is created with an empty password ! Please consider switching off the --initialize-insecure option.

执行初始化命令成功之后,再执行下面的命令,安装 mysql 服务(要管理员模式打开 命令行):

mysqld --install

安装服务成功之后,启动服务(cmd 管理员模式):

net start mysql

停止 mysql 服务(cmd 管理员模式):

net stop mysql

修改 root 用户的密码

上面步骤成功之后,可以在 cmd 输入如下命令进入MySQL:

mysql -u root -p

输入如下 SQL 语句,修改 root 用户的密码:

alter user 'root'@'localhost' identified by '你的密码';

创建数据库

blog 是库名

create database blog default character set utf8mb4 collate utf8mb4_general_ci;

创建用户

CREATE USER '你的用户名'@'localhost' IDENTIFIED BY '你的密码';

修改权限

blog 数据库的管理权限给予刚刚创建的MySQL用户

GRANT ALL PRIVILEGES ON 你的数据库名.* TO '你的用户名'@'localhost';

刷新权限

FLUSH PRIVILEGES;

 


^_^
请喝咖啡 ×

文章部分资料可能来源于网络,如有侵权请告知删除。谢谢!

前一篇: Oracle Cloud 更换 ip 地址步骤
下一篇: DBeaver 连接 mysql8 报错:Public Key Retrieval is not allowed Public Key Retrieval is not allowed
captcha