编译后的MySQL安装

MySQL安装

1.下载网址

复制代码
https://dev.mysql.com/downloads/mysql/

2.下载方式

选择对应版本下载 mysql-xxx-winx64.zip,该压缩包为编译后文件,并非源码, 可以直接运行。

3.配置

配置环境变量

为方便 Mysql 服务的使用和管理,可以在 PATH 中加入 Mysql 的 bin 目录。

修改配置文件

Mysql 配置默认读取自安装目录下 my.ini,如没有需要创建一个,Mysql 默认有一套配置,如端口默认为 3306 等,my.ini 并非必须,只需要在其中写明需要的配置即可,如下:

复制代码
[mysqld]

lower_case_table_names=2

注意:此处 lower_case_table_names 有三种取值:

0:表示表名区分大小写。

1:表示将表名转换为小写,但在比较时仍然区分大小写。

2:表示将表名转换为小写,并且在比较时也不区分大小写。

初始化

初始化 Mysql 需要管理员权限,需要管理员权限运行 Powershell 或 CMD。执行mysqld --initialize --console既可初始化并在控制台显示密码。

服务初始化过程如下:

复制代码
PS D:\Element\mysql-8.0.35> ./bin/mysqld --initialize  --console
2024-01-04T07:08:20.705336Z 0 [System] [MY-013169] [Server] D:\Element\mysql-8.0.35\bin\mysqld.exe (mysqld 8.0.35) initializing of server in progress as process 3008
2024-01-04T07:08:20.730739Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2024-01-04T07:08:21.033652Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
2024-01-04T07:08:22.291288Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: /YlA-/3M_yny

初始化完成后,会在 Mysql 安装目录生成一个 data 目录,即为 Mysql 数据存储目录。初始化日志最后一行显示的即为初始化的随机密码,权限为 root@localhost。

安装服务

运行mysqld install即可在 Windows 系统中安装 Mysql 服务。

复制代码
PS D:\Element\mysql-8.0.35> .\bin\mysqld install
Service successfully installed.

启动服务

可以使用 net start mysql 命令启动 Mysql 服务,如出现如下内容,即为启动成功:

复制代码
PS C:\Users\mufeng> net start mysql
MySQL 服务正在启动 .
MySQL 服务已经启动成功。

测试

服务启动之后,即可连接 Mysql:

复制代码
PS C:\Users\mufeng> 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.35

Copyright (c) 2000, 2023, Oracle and/or its affiliates.

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>

修改 Mysql 默认密码

Mysql 权限管理是基于 域 + 用户 + 权限 的方式,本地对安全性要求不高,此处修改 root 用户随处可以登录。

如下:

复制代码
mysql> ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'root';
Query OK, 0 rows affected (0.01 sec)
mysql> use mysql;
Database changed
mysql> update user set host = '%' where host = 'localhost' and user = '123456';
Query OK, 1 row affected (0.00 sec)
Rows matched: 1  Changed: 1  Warnings: 0

测试:

复制代码
PS C:\Users\mufeng> mysql -uroot -p123456
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 10
Server version: 8.0.35 MySQL Community Server - GPL

Copyright (c) 2000, 2023, Oracle and/or its affiliates.

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>

登录成功!至此,Mysql For Windows 安装完成。

相关推荐
测试界的小码农17 分钟前
【图数据库实战进阶(01):从零认识 Neo4j,搭建第一个图数据库项目】
数据库·neo4j
x_SpiderMan38 分钟前
搭建Oracle RAC 集群
数据库·oracle
测试界的小码农44 分钟前
【图数据库实战进阶(03):Neo4j 图数据建模实战——节点、关系与属性应该怎么设计?】
数据库·oracle·neo4j
瑞克-桑切斯1 小时前
redis
数据库·redis·缓存
噜哥带你玩转 AI 大模型1 小时前
面试加分项!CASE WHEN 两种写法、CTE 公共表表达式、四大类窗口函数,老哥一次讲透
mysql·窗口函数·cte·sql 进阶
freejackman2 小时前
【工程化】从“单兵作战”到“多引擎架构”:基于门面模式的重构实战
大数据·数据库·hive·sql·测试工具·设计模式·架构
bksczm2 小时前
InnoDB 内存结构总览:Change Buffer、AHI 与 Log Buffer
数据库·mysql
招风的黑耳2 小时前
SpringBoot+Vue+MySQL 民宿在线预定平台 完整可运行版(源码+文档)
vue.js·spring boot·mysql
花间相见2 小时前
【计算基础|Redis02】【上手】五大数据类型命令逐条实操
数据库·redis·后端
敲上瘾3 小时前
Qt Widgets入门:项目模板解析与Hello World
开发语言·数据库·c++·qt·ui·qt6.3