Ser*_*ero 16 mysql windows command-line
通常,我会为Windows下载MySQL msi安装程序并安装然后在安装步骤中配置和创建数据库.然后使用任何应用程序/语言连接,然后从那里开始.
但是
我想在不使用msi安装程序的情况下达到相同的结果,而是想使用提供的MySQL存档.所以,
我想知道如何使用通过Windows命令行下载的服务器文件来创建和管理数据库.
大多数搜索尝试产生的结果要么假设msi安装已经发生,要么对于仍在尝试学习MySQL基础知识的人来说太复杂.
TL; DR:如何通过命令行在Windows上使用MySQL服务器归档文件创建和管理数据库?
Ser*_*ero 35
感谢Ryan Vincent的评论.我能够按照MySQL的参考文档中的步骤进行操作(出于某种原因,在询问此问题之前我的搜索从未找到过).
参考文档:2.3.5使用noinstall Zip Archive在Microsoft Windows上安装MySQL
简化步骤
D:\mysql\mysql-5.7.17-winx64)D:\mysql\mydb)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"
Run Code Online (Sandbox Code Playgroud)
[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
Run Code Online (Sandbox Code Playgroud)
创建批处理文件以启动MySQL数据库服务器
"D:\mysql\mysql-5.7.17-winx64\bin\mysqld.exe" --defaults-file="D:\\mysql\\config.ini"
Run Code Online (Sandbox Code Playgroud)
[mysqld]配置文件(D:\mysql\config.ini)的部分/组,并使用其中指定的选项来启动MySQL数据库服务器.创建批处理文件以关闭MySQL数据库服务器
"D:\mysql\mysql-5.7.17-winx64\bin\mysqladmin.exe" --defaults-file="D:\\mysql\\config.ini" shutdown
Run Code Online (Sandbox Code Playgroud)
[mysqladmin]配置文件(D:\mysql\config.ini)的部分/组,并使用其中指定的选项来指定和关闭MySQL数据库服务器.免责声明 这些步骤应该可以帮助您开始使用MySQL数据库,并且无法用于生产.(root用户甚至没有设置密码)
资源和更多细节
小智 15
上面的答案已经过时了,并且提供了太多的信息,可能会造成混乱。
对于只想在 Windows 上尽快运行数据库的 8.0.26+ 版本用户来说,这些步骤更加简单:
将主存档解压到所需的安装目录(C:\mysql 是安全的默认选择)
初始化数据目录。最近的 mysql 发行版不包含它。转到 C:\mysql\bin 并输入:
mysqld --初始化 --console
并保存行中的密码:
2021-11-03T21:33:13.455063Z 6 [注意] [MY-010454] [服务器] 为 root@localhost 生成临时密码: yIQ_4Ra2Q9g)
从 bin 目录运行 db
mysqld --控制台
更改分配的随机密码。打开单独的cmd窗口并连接
mysql -u 根 -p
输入第 3 点中的临时密码。“root”是默认的 mysql 用户名。然后输入:
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'root-password';
Run Code Online (Sandbox Code Playgroud)
“ root-password ”应该替换为您自己的密码。
您现在可以再次尝试 mysql -u root -p 以检查新密码是否有效或仅与任何其他客户端连接。
我通常遵循此处描述的步骤,但并非所有内容都一致。
小智 6
除此之外,如果遇到“ mysqld:无法创建或访问MySQL应用程序登录Windows EventLog所需的注册表项。请以足够的特权运行该应用程序以创建密钥,手动添加该密钥,或关闭该应用程序的日志记录。” 错误- 将以下行添加到步骤6、7:-- log_syslog = 0
| 归档时间: |
|
| 查看次数: |
27122 次 |
| 最近记录: |