MySQL 5.6 Install

简单记录下 mysql 5.6 的安装方式,便于以后查阅。

Windows 安装

本次安装环境:

OS 名称:          Microsoft Windows 7 旗舰版
OS 版本:          6.1.7601 Service Pack 1 Build 7601
OS 制造商:        Microsoft Corporation
OS 配置:          独立工作站

下载

下载页面,点击下方

No thanks, just start my download.

解压

解压到任意路径,约定为 ${BASE_DIR}。本地是:

D:\Learn\mysql\mysql-5.6.39-winx64\mysql-5.6.39-winx64\

解压后的文件列表如下:

[bin]            
[data]           
[docs]           
[include]        
[lib]
[mysql-test]     
[scripts]        
[share]          
[sql-bench]
my-default.ini
README  
COPYING

配置

指定 mysql 的配置

复制 my-default.ini,重命名为 my.ini

主要指定 basedir、datadir、port、server_id

修改内容如下:

# 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 = D:\Learn\mysql\mysql-5.6.39-winx64\mysql-5.6.39-winx64
datadir = D:\Learn\mysql\mysql-5.6.39-winx64\mysql-5.6.39-winx64\data
port = 3306
server_id = 1


# 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 

安装服务

命令行(管理员模式)打开 ${BASE_DIR}\bin 下运行命令:

D:\Learn\mysql\mysql-5.6.39-winx64\mysql-5.6.39-winx64\bin>

mysqld install MySQL_BackingStore --defaults-file=D:\Learn\mysql\mysql-5.6.39-winx64\mysql-5.6.39-winx64\my.ini

安装结果如下:

Service successfully installed.
  • 启动服务

服务列表启动,或者用下面的命令行启动:

D:\Learn\mysql\mysql-5.6.39-winx64\mysql-5.6.39-winx64\bin>
net start MySQL_BackingStore

启动结果如下:

MySQL_BackingStore 服务正在启动 .
MySQL_BackingStore 服务已经启动成功。

访问 MySQL

命令行访问

D:\Learn\mysql\mysql-5.6.39-winx64\mysql-5.6.39-winx64\bin>mysql -uroot -p

默认密码为空。

  • 修改密码

修改为 123456

set password for root@localhost = password('123456'); 
  • 指定 mysql.exe path

每次都要跑到指定路径下很麻烦,

【环境变量】=》【系统变量】=》【Path】

在最后添加:

D:\Learn\mysql\mysql-5.6.39-winx64\mysql-5.6.39-winx64\bin;
  • 测试
C:\Users\bbhou>mysql --version
mysql  Ver 14.14 Distrib 5.6.39, for Win64 (x86_64)

Windows 10 安装

下载 & 解压

5.7 下载界面

此次测试环境为 win10 64 位。

所以直接下载了 mysql-5.7.24-winx64

解压到指定文件夹,比如此次测试为 D:\tool\mysql,解压后的文件夹如下:

$   pwd
D:\tool\mysql\mysql-5.7.24-winx64

$   ls
COPYING  README  bin/  docs/  include/  lib/  share/

修改配置文件

进入解压后的目录,新建 my.ini 文件,修改basedir与datadir两个参数。

本例如下:

[mysql]
# 设置mysql客户端默认字符集
default-character-set=utf8
[mysqld]
sql_mode='NO_AUTO_VALUE_ON_ZERO,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION,PIPES_AS_CONCAT,ANSI_QUOTES'
#设置3306端口
port = 3306
# 设置mysql的安装目录
basedir=D:/tool/mysql/mysql-5.7.24-winx64
# 设置mysql数据库的数据的存放目录
datadir=D:/tool/mysql/mysql-5.7.24-winx64/data
# 允许最大连接数
max_connections=200
# 服务端使用的字符集默认为8比特编码的latin1字符集
character-set-server=utf8
# 创建新表时将使用的默认存储引擎
default-storage-engine=INNODB

命令行安装

打开命令行窗口,进入 D:\tool\mysql\mysql-5.7.24-winx64\bin 下,依次运行

mysqld.exe --install MySQL
mysqld.exe --initialize-insecure (不设置root密码,建议使用)
net start mysql
  • 临时密码

mysqld.exe --initialize 这种方式会生成一个临时密码。

可以在 D:\tool\mysql\mysql-5.7.24-winx64\data\SJ-JQ2508.err 中找到这个密码:

2018-11-08T06:49:43.305367Z 1 [Note] A temporary password is generated for root@localhost: ?8GQfhsQmMN;

登录

  • 登录
mysql -u root -p 

输入密码即可(非安全模式则不用输入密码)

  • 修改密码
set password for root@localhost=password('你的密码');