在Windows上无需安装即可运行/启动MySQL [英] Running/Starting MySQL without installation on Windows

查看:308
本文介绍了在Windows上无需安装即可运行/启动MySQL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

通常,我将下载Windows的MySQL msi安装程序并进行安装,然后在安装步骤中配置和创建数据库.然后只需使用任何应用程序/语言进行连接,然后从那里进行.

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.

但是
我想在不使用msi安装程序的情况下达到相同的结果,而是要使用提供的MySQL存档. 因此,

However
I want to reach the same result without using the msi installer, instead i want to use the provided MySQL archive. So,

  • 我已下载(MySQL社区服务器=> Windows(x86,64位), ZIP存档 mysql-5.7.17-winx64.zip )
  • 提取档案文件.
  • I have downloaded (MySQL Community Server => Windows (x86, 64-bit), ZIP Archive mysql-5.7.17-winx64.zip)
  • Extracted the archive.

我想知道如何通过Windows命令行使用那些下载的服务器文件来创建和管理数据库.

大多数搜索尝试都会得出结果,即假定已经安装了msi,或者对于仍在尝试学习MySQL基础知识的人来说太复杂了.

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.

TL; DR:如何通过命令行在Windows上使用MySQL服务器归档文件创建和管理数据库?

推荐答案

感谢 Ryan Vincent 评论.我能够按照MySQL参考文档中的步骤进行操作(出于某种原因,在问这个问题之前我的搜索从未找到它).

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).

参考文档:2.3.5安装使用noinstall Zip存档的Microsoft Windows上的MySQL

Reference Documentation : 2.3.5 Installing MySQL on Microsoft Windows Using a noinstall Zip Archive

简化的步骤

  1. 下载 MySQL Community Server 5.7.17 Windows (x86,64位),ZIP存档
  2. 将下载的MySQL Server存档提取到MySQL服务器文件的所需位置(例如:D:\mysql\mysql-5.7.17-winx64)
  3. 为MySQL数据库的数据文件创建目录(例如:D:\mysql\mydb)
  4. 为MySQL的数据库记录创建目录(示例D:\mysql\logs)
  5. 创建MySQL选项文件(示例位置:D:\mysql\config.ini)

  1. Download MySQL Community Server 5.7.17 Windows (x86, 64-bit), ZIP Archive
  2. Extract the downloaded MySQL Server Archive to the desired location for MySQL server files (example : D:\mysql\mysql-5.7.17-winx64)
  3. Create a directory for MySQL's database's data files (example : D:\mysql\mydb)
  4. Create a directory for MySQL's database logging (example D:\mysql\logs)
  5. 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"

  • 所选端口为55555
  • [mysqld]对与mysqld.exe相关的选项进行分组,当mysql.exe读取此配置文件时将使用这些选项.
  • [mysqladmin]将与mysqladmin.exe相关的选项分组,当mysqladmin.exe读取此配置文件时将使用这些选项.
    • 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.
    • 使用Windows批处理文件/命令提示符初始化MySQL数据库文件

      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
      

      • 这将在配置文件中指定的位置创建一个数据库文件.
      • 它将具有没有密码的root用户
      • 错误消息将显示在当前控制台窗口上.
      • 创建一个批处理文件以启动MySQL数据库服务器

        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"
        

        • 这将读取配置文件(D:\mysql\config.ini)的[mysqld]部分/组,并使用在那里指定的选项来启动MySQL数据库服务器.
          • 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.
          • 创建一个批处理文件以关闭MySQL数据库服务器

            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
            

            • 这将读取配置文件(D:\mysql\config.ini)的[mysqladmin]部分/组,并使用在那里指定的选项来指定和关闭MySQL数据库服务器.
              • 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.
              • 免责声明 这些步骤应该可以帮助您开始使用MySQL数据库,并且绝不对生产进行预期或安全的操作.(root用户甚至还没有设置密码)

                DISCLAIMER Those 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)

                资源和更多详细信息

                1. 参考文档:2.3.5在Microsoft上安装MySQL Windows使用noinstall Zip存档
                2. 参考文档:5.2.6使用选项文件
                3. 参考文档:5.2.3指定程序选项
                4. 参考文档:6.1.4服务器命令选项
                5. [其他]参考文档:5.6在多个MySQL实例上运行一台机器
                1. Reference Documentation : 2.3.5 Installing MySQL on Microsoft Windows Using a noinstall Zip Archive
                2. Reference Documentation : 5.2.6 Using Option Files
                3. Reference Documentation : 5.2.3 Specifying Program Options
                4. Reference Documentation : 6.1.4 Server Command Options
                5. [Additional] Reference Documentation : 5.6 Running Multiple MySQL Instances on One Machine

                这篇关于在Windows上无需安装即可运行/启动MySQL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆