首选,去下面地址下载64位版MySQL数据库:
https://dev.mysql.com/downloads/mysql/
如果想快速部署,可以下载32位版MySQL,去小面地址下载,直接一键安装:
https://dev.mysql.com/downloads/installer/
①为了防止MySQL服务已经被安装,先强制删除;
sc delete FSvcDB_8100
注意:FSvcDB_8100是我的MySQL服务名称,你定义自己的服务名称。
②解压mysql-5.7.12-winx64.zip,发现没有data文件夹,这是我比较疑惑的地方,我是直接用mysql-5.6.29-winx64.zip内的data代替的。
③运行以下命令,对MySQL数据库初始化:
mysqld --initialize-inscure
④安装并运行服务(分别依次执行):
mysqld -install FSvcDB_8100
net start FSvcDB_8100
⑤更新MySQL系统数据库,否则将会报错Table 'performance_schema.session_variables' doesn't exist
的错误:
mysql_upgrade -u root -p --force
⑥在命令行中登录MySQL数据库:
mysql -u root -h localhost -p
注意:
如果使用mysql -u root
登录,当数据库没有密码时是可以的;否则将会报错,请参考连接MySQL数据库时常见故障问题的分析与解决
。
⑦分别依次执行修改密码操作:
SET PASSWORD FOR 'root'@'localhost' = PASSWORD('新密码');
SET PASSWORD FOR 'root'@'127.0.0.1' = PASSWORD('新密码');
SET PASSWORD FOR 'root'@'::1' = PASSWORD('新密码');
SET PASSWORD FOR 'root'@'%' = PASSWORD('新密码');
⑧如果想创建新的ddl和dml账号,可以这么写:
-- 创建ddl账号
-- 数据库运维权限:拥有所有权限
DROP USER 'ddl_mgr'@'%';
CREATE USER 'ddl_mgr'@'%' IDENTIFIED BY '新密码';
GRANT GRANT OPTION ON *.* TO 'ddl_mgr'@'%';
GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, RELOAD, SHUTDOWN, PROCESS, FILE, REFERENCES, INDEX, ALTER, SHOW DATABASES, SUPER, CREATE TEMPORARY TABLES, LOCK TABLES, EXECUTE, REPLICATION SLAVE, REPLICATION CLIENT, CREATE VIEW, SHOW VIEW, CREATE ROUTINE, ALTER ROUTINE, CREATE USER, EVENT, TRIGGER ON *.* TO 'ddl_mgr'@'%' WITH GRANT OPTION;
-- 创建dml账号
-- 数据库开发权限:增、删、改、查、创建临时表、使用Event对象、执行存储过程
DROP USER 'dml_mgr'@'%';
CREATE USER 'dml_mgr'@'%' IDENTIFIED BY '新密码';
GRANT GRANT OPTION ON *.* TO 'dml_mgr'@'%';
GRANT SELECT, INSERT, UPDATE, DELETE, CREATE TEMPORARY TABLES, EVENT, EXECUTE ON *.* TO 'dml_mgr'@'%' WITH GRANT OPTION;
⑨停止MySQL服务,压缩备份已经安装和配置好的空数据库,并且修改my.ini文件。
net stop FSvcDB_8100
并将my.ini文件、InstallService.bat、UninstallService.bat放到bin下面。
注意:InstallService.bat、UninstallService.bat是用于快速启动、停止并卸载MySQL服务的批处理脚本。
my.ini文件的配置(我并没有过多配置项。因为在没有具体需求前,最好的配置就是使用默认配置):
[client]
#password = [your_password]
port = 3306
socket = /tmp/mysql.sock
[mysqld]
skip_name_resolve
port = 3306
socket = /tmp/mysql.sock
max_connections = 500
default-storage-engine = InnoDB
character-set-server=utf8
innodb_buffer_pool_size = 1024M
注意:如果是32位版本,innodb_additional_mem_pool_size这个配置项有错误冲突,要注释掉。
MySQL 5.7 Reference Manual
★mysql-5.7.12-winx64安装的时候无法启动服务问题
★Table ‘performance_schema.session_variables’ doesn’t exist
连接MySQL数据库时常见故障问题的分析与解决
InstallService.bat,放在bin下面,用于快速启动MySQL服务:
@echo off
echo OFF
NET SESSION >nul 2>&1
IF %ERRORLEVEL% EQU 0 (
ECHO Administrator PRIVILEGES Detected!
ECHO 检测到以管理员权限运行!
) ELSE (
echo ######## ######## ######## ####### ########
echo ## ## ## ## ## ## ## ## ##
echo ## ## ## ## ## ## ## ## ##
echo ###### ######## ######## ## ## ########
echo ## ## ## ## ## ## ## ## ##
echo ## ## ## ## ## ## ## ## ##
echo ######## ## ## ## ## ####### ## ##
echo.
echo.
echo ####### ERROR: ADMINISTRATOR PRIVILEGES REQUIRED #########
echo ####### ERROR: 需要以管理员权限运行 #########
echo This script must be run as administrator to work properly!
echo If you're seeing this after clicking on a start menu icon, then right click on the shortcut and select "Run As Administrator".
echo 这个批处理脚本需要管理员权限才能正常运行!
echo 请右键该菜单或批处理文件,选择"以管理员身份运行".
echo ##########################################################
echo.
PAUSE
EXIT /B 1
)
echo Bin directory: %~dp0
cd /D "%~dp0"
echo curdir: %cd%
echo ini path: %~dp0my.ini
.\mysqld.exe --install FSvcDB_8100 --defaults-file="%~dp0my.ini"
net start FSvcDB_8100
pause
UninstallService.bat,放在bin下面,用于快速停止并卸载MySQL服务:
@echo off
echo OFF
NET SESSION >nul 2>&1
IF %ERRORLEVEL% EQU 0 (
ECHO Administrator PRIVILEGES Detected!
ECHO 检测到以管理员权限运行!
) ELSE (
echo ######## ######## ######## ####### ########
echo ## ## ## ## ## ## ## ## ##
echo ## ## ## ## ## ## ## ## ##
echo ###### ######## ######## ## ## ########
echo ## ## ## ## ## ## ## ## ##
echo ## ## ## ## ## ## ## ## ##
echo ######## ## ## ## ## ####### ## ##
echo.
echo.
echo ####### ERROR: ADMINISTRATOR PRIVILEGES REQUIRED #########
echo ####### ERROR: 需要以管理员权限运行 #########
echo This script must be run as administrator to work properly!
echo If you're seeing this after clicking on a start menu icon, then right click on the shortcut and select "Run As Administrator".
echo 这个批处理脚本需要管理员权限才能正常运行!
echo 请右键该菜单或批处理文件,选择"以管理员身份运行".
echo ##########################################################
echo.
PAUSE
EXIT /B 1
)
echo Bin directory: %~dp0
cd /D "%~dp0"
echo curdir: %cd%
net stop FSvcDB_8100
.\mysqld.exe --remove FSvcDB_8100
pause
完整的my.ini文件:
#BEGIN CONFIG INFO
#DESCR: 4GB RAM, InnoDB only, ACID, few connections, heavy queries
#TYPE: SYSTEM
#END CONFIG INFO
#
# This is a MySQL example config file for systems with 4GB of memory
# running mostly MySQL using InnoDB only tables and performing complex
# queries with few connections.
#
# You can copy this file to /etc/my.cnf to set global options,
# mysql-data-dir/my.cnf to set server-specific options
# (C:\mysql\data for this installation) or to
# ~/.my.cnf to set user-specific options.
#
# In this file, you can use all long options that a program supports.
# If you want to know which options a program supports, run the program
# with the "--help" option.
#
# More detailed information about the individual options can also be
# found in the manual.
#
#
# The following options will be read by MySQL client applications.
# Note that only client applications shipped by MySQL are guaranteed
# to read this section. If you want your own MySQL client program to
# honor these values, you need to specify it as an option during the
# MySQL client library initialization.
#
[client]
#password = [your_password]
port = 3306
socket = /tmp/mysql.sock
# *** Application-specific options follow here ***
#
# The MySQL server
#
[mysqld]
# name resolving may cost time,
# skip it, but 127.0.0.1 can't be used as localhost
skip_name_resolve
# generic configuration options
port = 3306
socket = /tmp/mysql.sock
# The maximum amount of concurrent sessions the MySQL server will
# allow. One of these connections will be reserved for a user with
# SUPER privileges to allow the administrator to login even if the
# connection limit has been reached.
max_connections = 500
# Table type which is used by default when creating new tables, if not
# specified differently during the CREATE TABLE statement.
default-storage-engine = InnoDB
character-set-server=utf8
# *** INNODB Specific options ***
# Use this option if you have a MySQL server with InnoDB support enabled
# but you do not plan to use it. This will save memory and disk space
# and speed up some things.
#skip-innodb
# Additional memory pool that is used by InnoDB to store metadata
# information. If InnoDB requires more memory for this purpose it will
# start to allocate it from the OS. As this is fast enough on most
# recent operating systems, you normally do not need to change this
# value. SHOW INNODB STATUS will display the current amount used.
innodb_additional_mem_pool_size = 16M
# InnoDB, unlike MyISAM, uses a buffer pool to cache both indexes and
# row data. The bigger you set this the less disk I/O is needed to
# access data in tables. On a dedicated database server you may set this
# parameter up to 80% of the machine physical memory size. Do not set it
# too large, though, because competition of the physical memory may
# cause paging in the operating system. Note that on 32bit systems you
# might be limited to 2-3.5G of user level memory per process, so do not
# set it too high.
innodb_buffer_pool_size = 1024M