windows中运行mysql,在Windows上无需安装即可运行/启动MySQL

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.

However

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

So,

I have downloaded (MySQL Community Server => Windows (x86, 64-bit),

ZIP Archive mysql-5.7.17-winx64.zip)

Extracted the archive.

I want to know how to create and manage a database using those downloaded server files through windows command line.

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 : How can i create and manage a database using MySQL server archive files on windows through command line?

解决方案

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

Simplified Steps

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.

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.

You can now start your database and access it, and shut it down when it is not needed.

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)

Resources And More Details

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值