下载 MySQL 免安装(zip)版,从 5.7 版本以后,不再含有 data 目录,没有 data 目录也就是没有默认数据库,需要用户手动创建。
运行创建 data 的命令
D:\mysql\5.7.12\bin>mysqld –initialize-insecure –user=mysql
将自动创建默认目录于 home 位置,之后可以通过 my.ini 设置到任意位置
D:/mysql/5.7.12/data
创建完成并启动服务器,此时密码为空
/bin/mysql -u root -p 即可进入
简单的 my.ini 设置
文件位置默认 d:\mysql\5.7.12,设置服务时可以选为其他位置。
设置 data 目录和 bin 目录,且设置字符集为 utf-8.
# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.6/en/server-configuration-defaults.html
# *** DO NOT EDIT THIS FILE. It's a template which will be copied to the
# *** default location during install, and will be replaced if you
# *** upgrade to a newer version of MySQL.
[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 = .....
basedir = "d:/mysql/5.7.12/"
datadir = "d:/mysql/data"
port = 3306
# 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
character_set_server=utf8
max_connections = 1500
max_connect_errors = 150
Windows 下将 mysql 作为服务启动的命令
mysqld --install "MySQL 5.7" --defaults-file="d:/mysql/my.ini"
参考资料
https://dev.mysql.com/doc/refman/5.7/en/mysql-install-db.html
https://dev.mysql.com/doc/refman/5.7/en/data-directory-initialization-mysqld.html
MySQL 下载
http://dev.mysql.com/downloads/
Q群讨论:236201801.