在 Windows 上无需安装即可运行/启动 MySQL
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/42045494/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Running/Starting MySQL without installation on Windows
提问by Sero
Normally, I would download MySQL msi installer for windows and install then configure and created the database within the installation steps. Then just connect using whatever application/language and go from there.
通常,我会下载适用于 Windows 的 MySQL msi 安装程序并安装,然后在安装步骤中配置和创建数据库。然后只需使用任何应用程序/语言进行连接,然后从那里开始。
However
I want to reach the same result without using the msi installer, instead i want to use the provided MySQL archive.
So,
但是,
我想在不使用 msi 安装程序的情况下达到相同的结果,而是想使用提供的 MySQL 存档。所以,
- I have downloaded (MySQL Community Server => Windows (x86, 64-bit), ZIP Archive mysql-5.7.17-winx64.zip)
- Extracted the archive.
- 我已经下载(MySQL 社区服务器 => Windows (x86, 64-bit), ZIP Archive mysql-5.7.17-winx64.zip)
- 提取存档。
I want to know how to create and manage a database using those downloaded server files through windows command line.
我想知道如何通过 Windows 命令行使用下载的服务器文件创建和管理数据库。
Most of the search attempts yield results that either assume that msi installation have taken place or are far too complex for someone who is still attempting to learn MySQL basics.
大多数搜索尝试产生的结果要么假设 msi 安装已经发生,要么对于仍在尝试学习 MySQL 基础知识的人来说太复杂了。
TL;DR : How can i create and manage a database using MySQL server archive files on windows through command line?
TL;DR:如何通过命令行在 Windows 上使用 MySQL 服务器存档文件创建和管理数据库?
回答by Sero
Thanks to Ryan Vincent's comment. I was able to follow the steps in MySQL's reference documentations (For some reason my searches prior to asking this question never found it).
感谢Ryan Vincent的评论。我能够按照 MySQL 参考文档中的步骤进行操作(出于某种原因,我在问这个问题之前的搜索从未找到它)。
Reference Documentation : 2.3.5 Installing MySQL on Microsoft Windows Using a noinstall Zip Archive
参考文档:2.3.5 使用 noinstall Zip Archive 在 Microsoft Windows 上安装 MySQL
Simplified Steps
简化步骤
- Download MySQL Community Server 5.7.17 Windows (x86, 64-bit), ZIP Archive
- Extract the downloaded MySQL Server Archive to the desired location for MySQL server files (example :
D:\mysql\mysql-5.7.17-winx64
) - Create a directory for MySQL's database's data files (example :
D:\mysql\mydb
) - Create a directory for MySQL's database logging (example
D:\mysql\logs
) Create MySQL options file (example location :
D:\mysql\config.ini
)# For advice on how to change settings please see # http://dev.mysql.com/doc/refman/5.7/en/server-configuration-defaults.html [mysqld] # Remove leading # and set to the amount of RAM for the most important data # cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%. # innodb_buffer_pool_size = 128M # Remove leading # to turn on a very important data integrity option: logging # changes to the binary log between backups. # log_bin # These are commonly set, remove the # and set as required. # basedir = ..... # datadir = ..... # port = ..... # server_id = ..... # Remove leading # to set options mainly useful for reporting servers. # The server defaults are faster for transactions and fast SELECTs. # Adjust sizes as needed, experiment to find the optimal values. # join_buffer_size = 128M # sort_buffer_size = 2M # read_rnd_buffer_size = 2M sql_mode = NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES # set basedir to your installation path basedir = "D:\mysql\mysql-5.7.17-winx64" # set datadir to the location of your data directory datadir = "D:\mysql\mydb" # The port number to use when listening for TCP/IP connections. On Unix and Unix-like systems, the port number must be # 1024 or higher unless the server is started by the root system user. port = "55555" # Log errors and startup messages to this file. log-error = "D:\mysql\logs\error_log.err" [mysqladmin] user = "root" port = "55555"
- Selected port is 55555
[mysqld]
groups options relating to mysqld.exe which will be used when mysql.exe reads this configuration file.[mysqladmin]
groups options relating to mysqladmin.exe which will be used when mysqladmin.exe reads this configuration file.
Initialize MySQL database files using Windows Batch File/Command Prompt
"D:\mysql\mysql-5.7.17-winx64\bin\mysqld.exe" --defaults-file="D:\mysql\config.ini" --initialize-insecure --console
- This will create a database files in the location specified in the configuration file.
- It will have root user with no password
- Error messages will be printed on current console window.
Create a batch file to start the MySQL database server
"D:\mysql\mysql-5.7.17-winx64\bin\mysqld.exe" --defaults-file="D:\mysql\config.ini"
- This will read
[mysqld]
part/group of the configuration file (D:\mysql\config.ini
) and use options specified there to start the MySQL database server.
- This will read
Create a batch file to shutdown the MySQL database server
"D:\mysql\mysql-5.7.17-winx64\bin\mysqladmin.exe" --defaults-file="D:\mysql\config.ini" shutdown
- This will read
[mysqladmin]
part/group of the configuration file (D:\mysql\config.ini
) and use options specified there to specify and shutdown the MySQL database server.
- This will read
- You can now start your database and access it, and shut it down when it is not needed.
- 下载MySQL 社区服务器 5.7.17 Windows(x86,64 位),ZIP 存档
- 解压下载的MySQL服务器存档为MySQL服务器的文件所需的位置(例如:
D:\mysql\mysql-5.7.17-winx64
) - 创建MySQL的数据库的数据文件的目录(例如:
D:\mysql\mydb
) - 为 MySQL 的数据库日志创建目录(示例
D:\mysql\logs
) 创建MySQL选项文件(例如位置:
D:\mysql\config.ini
)# For advice on how to change settings please see # http://dev.mysql.com/doc/refman/5.7/en/server-configuration-defaults.html [mysqld] # Remove leading # and set to the amount of RAM for the most important data # cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%. # innodb_buffer_pool_size = 128M # Remove leading # to turn on a very important data integrity option: logging # changes to the binary log between backups. # log_bin # These are commonly set, remove the # and set as required. # basedir = ..... # datadir = ..... # port = ..... # server_id = ..... # Remove leading # to set options mainly useful for reporting servers. # The server defaults are faster for transactions and fast SELECTs. # Adjust sizes as needed, experiment to find the optimal values. # join_buffer_size = 128M # sort_buffer_size = 2M # read_rnd_buffer_size = 2M sql_mode = NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES # set basedir to your installation path basedir = "D:\mysql\mysql-5.7.17-winx64" # set datadir to the location of your data directory datadir = "D:\mysql\mydb" # The port number to use when listening for TCP/IP connections. On Unix and Unix-like systems, the port number must be # 1024 or higher unless the server is started by the root system user. port = "55555" # Log errors and startup messages to this file. log-error = "D:\mysql\logs\error_log.err" [mysqladmin] user = "root" port = "55555"
- 选择的端口是 55555
[mysqld]
将与 mysqld.exe 相关的选项分组,当 mysql.exe 读取此配置文件时将使用这些选项。[mysqladmin]
与 mysqladmin.exe 相关的组选项,将在 mysqladmin.exe 读取此配置文件时使用。
使用 Windows 批处理文件/命令提示符初始化 MySQL 数据库文件
"D:\mysql\mysql-5.7.17-winx64\bin\mysqld.exe" --defaults-file="D:\mysql\config.ini" --initialize-insecure --console
- 这将在配置文件中指定的位置创建一个数据库文件。
- 它将有没有密码的 root 用户
- 错误消息将打印在当前控制台窗口上。
创建批处理文件以启动 MySQL 数据库服务器
"D:\mysql\mysql-5.7.17-winx64\bin\mysqld.exe" --defaults-file="D:\mysql\config.ini"
- 这将读取
[mysqld]
配置文件 (D:\mysql\config.ini
) 的部分/组并使用其中指定的选项来启动 MySQL 数据库服务器。
- 这将读取
创建一个批处理文件来关闭 MySQL 数据库服务器
"D:\mysql\mysql-5.7.17-winx64\bin\mysqladmin.exe" --defaults-file="D:\mysql\config.ini" shutdown
- 这将读取
[mysqladmin]
配置文件 (D:\mysql\config.ini
) 的部分/组并使用在那里指定的选项来指定和关闭 MySQL 数据库服务器。
- 这将读取
- 您现在可以启动并访问数据库,并在不需要时将其关闭。
DISCLAIMERThose steps are supposed to help you get started with MySQL database and are in no way intended or secure for production.(root user doesn't even have a password set yet)
免责声明这些步骤应该可以帮助您开始使用 MySQL 数据库,并且对于生产而言绝不是打算或安全的。(root 用户甚至还没有设置密码)
Resources And More Details
资源和更多详细信息
- Reference Documentation : 2.3.5 Installing MySQL on Microsoft Windows Using a noinstall Zip Archive
- Reference Documentation : 5.2.6 Using Option Files
- Reference Documentation : 5.2.3 Specifying Program Options
- Reference Documentation : 6.1.4 Server Command Options
- [Additional] Reference Documentation : 5.6 Running Multiple MySQL Instances on One Machine
回答by smexy
In addition to that, if you encounter the "mysqld: Could not create or access the registry key needed for the MySQL application to log to the Windows EventLog. Run the application with sufficient privileges once to create the key, add the key manually, or turn off logging for that application." error - Add to the steps 6, 7 the following line: --log_syslog=0
除此之外,如果您遇到“mysqld:无法创建或访问 MySQL 应用程序登录到 Windows EventLog 所需的注册表项。使用足够的权限运行应用程序一次以创建密钥,手动添加密钥,或关闭该应用程序的日志记录。” 错误 - 在步骤 6、7 中添加以下行:-- log_syslog=0