MySQL 8.0.15 installation tutorial and pitfall summary under Windows
MySQL 是一个关系型数据库管理系统,由瑞典 MySQL AB 公司开发,2008 年被 SUN 公司收购,后 SUN 公司又被 Oracle 公司收购。
相关推荐:《mysql视频教程》
一、下载
MySQL 官网 www.mysql.com/
点击 DOWNLOADS
进入下载地址,会看到几个不同的版本:
- MySQL Enterprise Edition:企业版(收费)
- MySQL Cluster CGE:高级集群版(收费)
- MySQL Community Edition:社区版(开源免费,但官方不提供技术支持)
通常我们用的都是社区版。点击进入社区版,看到一大堆东西,有点愣住了,不用急,其实点第一个 MySQL Community Server
的下载就可以了。
所以真正的下载地址其实是:dev.mysql.com/downloads/m…
拉到下面,选择 Windows 系统。

这里提供安装版和解压版,安装版是 32 位的(当然 64 位系统下也能安装),解压版是 64 位的。

点击 Download
后会跳转到如下页面,这是叫你注册/登录的,不理它,点击左下角的 No thanks, just start my download.
开始下载。

安装版是 32 位的,而现在的机器多半是 64 位机,虽然 32 位的程序也可以安装,但是并不建议。安装版的安装也比较容易,所以这里只讲解压版的安装。
二、解压版配置
1、配置环境变量
将安装包解压到你要安装的目录,将 bin
目录添加至环境变量。

2、配置 MySQL 8.0.15 installation tutorial and pitfall summary under Windows
在根目录下新建一个 MySQL 8.0.15 installation tutorial and pitfall summary under Windows
文件。

在 MySQL 8.0.15 installation tutorial and pitfall summary under Windows
中添加如下配置:
[mysqld]; 设置3306端口port=3306; 设置mysql的安装目录basedir=C:\\gl\\SQL\\mysql-8.0.18-winx64; 设置mysql数据库的数据的存放目录datadir=C:\\gl\\SQL\\mysql-data; 允许最大连接数max_connections=200; 允许连接失败的次数。这是为了防止有人从该主机试图攻击数据库系统max_connect_errors=10; 服务端使用的字符集默认为UTF8character-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=3306default-character-set=utf8复制代码
注意:basedir 和 datadir 要改成你自己的目录。
陷阱:
default_authentication_plugin=mysql_native_password
这一句必须要加上,否则可能导致 root 的初始密码无法登陆。
3、初始化数据库
以管理员身份 运行 cmd,切换至安装目录的 bin 目录下,输入如下命令:
mysqld --initialize --console复制代码
默认的服务名就是 mysql
,也可以指定服务名
mysqld --initialize --console 服务名复制代码
一般是不会去指定服务名的,但是如果你的电脑上需要安装多个 MySQL 服务,就可以用不同的名字区分。
执行成功后,会显示 root
的初始密码,如下图,这个密码需要保存下来。

如果命令中不加 --console
,则在 cmd 窗口将不显示日志信息。可以到 data 目录(MySQL 8.0.15 installation tutorial and pitfall summary under Windows 中 datadir 配置的目录)下找一个 .err 的文件,也可以查看日志信息。
陷阱 1
可能会报“找不到 MSVCP140.dll”

MSVCP140.dll 是 Visual Studio C++ 2015 Redistributable 的组成文件。
一般出现这个问题,是因为没有安装 Visual C++ Redistributable for Visual Studio 2015 所致。这个必须安装,否则后面服务无法启动。 下载地址:www.microsoft.com/zh-CN/downl…
如果已安装,则可以修复一下。
亦可下载一个 MSVCP140.dll,复制到 C:\Windows\System32
,运行如下批处理命令注册 dll
@echo 开始注册 copy msvcp140.dll %windir%\system32\ regsvr32 %windir%\system32\msvcp140.dll /s @echo msvcp140.dll注册成功 @pause复制代码
注册成功之后再运行上述 MySQL 命令,就可以正常初始化数据库了。当然不建议这么做。
陷阱 2
执行完成之后,仔细查看输出的信息,可能会有如下警告:
'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.复制代码
utf 8 目前是字符集 UTF8MB3 的别名,在将来的版本中将被 UTF8MB4 替换。请考虑使用 UTF8MB4,以便明确无误。
如果出现的话,我们只需将 MySQL 8.0.15 installation tutorial and pitfall summary under Windows 文件中的 utf8 替换成 UTF8MB4。
3.2、安装服务
安装服务:
mysqld -install复制代码
启动服务:
net start mysql复制代码
如果上一步中你指定了另外的服务名,将 mysql
改为你指定的服务名。
登录数据库:
mysql -u root -p复制代码
这时提示需要输入密码,就是前文让你保存的密码。
登录成功后显示如下:

修改密码:执行以下语句,即可将密码改为 root。
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'root';复制代码

The above is the detailed content of MySQL 8.0.15 installation tutorial and pitfall summary under Windows. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

Dreamweaver CS6
Visual web development tools

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.