Windows下MySQL解压版安装配置详细步骤

安装数据库

一、下载MySQL数据库解压版并解压

从官网下载MySQL压缩包,解压到本地目录

二、配置环境变量

在系统变量path后面添加MySQL安装路径下的bin目录,例:E:\mysql\bin

三、修改MySQL配置文件

在MySQL安装目录下有一个my-default.ini文件,复制一份,改名为my.ini,修改里面的配置。

原始文件my-default.ini:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.7/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 = .....



# 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

修改基础配置

  • basedir:MySQL安装根路径
  • datadir:MySQL安装根目录下的data文件夹路径
  • port:默认端口

例:
修改后文件my.ini:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.7/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.

[mysql]
default-character-set=utf8

[mysqld]
#skip-grant-tables
# 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 = E:\mysql
datadir = E:\mysql\data
port = 3306
# 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

四、添加MySQL服务

    1.以管理员身份打开命令提示符,进入到MySQL安装路径bin目录。执行命令:mysqld -install将mysql安装到windows的服务。如需移除,执行mysqld --remove移除服务。
    2.输入命令:mysqld --initialize ,这一步用于初始化data目录,官方的压缩包解压后并没有data文件夹,运行命令后,自动在根目录下生成data文件夹。

服务启动和维护

一、启动MySQL服务

在命令提示符执行 net start mysql启动MySQL服务;执行net stop mysql停止服务。

二、登录维护MySQL

MySQL默认用户名为root,密码为空。初次安装完成后可以直接进入安装路径的bin目录,执行mysql -u root -p,此时会提示输入密码,直接回车跳过,登录成功。如需设置密码,执行mysqladmin -uroot -p password <新密码>命令,会提示输入旧密码,旧密码为空,直接回车跳过。

  • 新版本的MySQL中,root用户的密码不能为空,在使用前必须设置密码
    • 在配置文件my.ini中,[mysqld]后一行加入skip-grant-tables
    • 重启MySQL服务
    • 执行mysql -u root -p,此时会提示输入密码,直接回车跳过,登录成功
    • 选择mysql数据库。执行use mysql;
    • 对user表执行更新操作。update user set authentication_string=password("你的密码") where user="root"; 
    • 刷新MySQL的系统权限相关表。执行flush privileges 。刷新后退出,执行quit,mysql 新设置用户或更改密码后需刷新相关表,否则会出现拒绝访问
    • 重新启动MySQL服务
文章作者: DongyangHu
文章链接: http://hudongyang.com/2019/11/29/mysql-install-windows/
版权声明: 本博客所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明来自 Sunshine