欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

MySQL5.7.21在Windows下安装教程

程序员文章站 2022-05-01 18:33:43
...

MySQL5.7.21在Windows下安装教程

本文主要介绍怎么在Windoes下安装MySQL5.7.21,需要准备的环境有:

  • WindowsServer2012 R2
  • mysql-5.7.21-winx64.zip

准备环境

  • 解压mysql-5.7.21-winx64.zip至当前目录,本文使用C盘根目录,为了方便,根目录命名为mysql
  • 设置环境变量
    – 创建系统变量MYSQL_HOME,值为C:\mysql
    MySQL5.7.21在Windows下安装教程
    – 添加至PATH变量中,保存即可
    MySQL5.7.21在Windows下安装教程
    – 测试,打开cmd命令提示符,输入mysql。如下图示则为成功
    MySQL5.7.21在Windows下安装教程

安装mysql

  • 创建my.ini文件,仅给出部分参数,其余参数依据需要添加
# 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.

[client]

port=3306
default-character-set=utf8

[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=C:\mysql
datadir=C:\mysql\data
port=3306
# server_id = .....
character_set_server=utf8

# 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

#explicit_defaults_for_timestamp=true

max_connections=32000

#time
interactive_timeout=28800000
wait_timeout=28800000
  • 安装mysql,注册为Windows服务
    mysqld install
    MySQL5.7.21在Windows下安装教程
  • 初始化mysql,生成data文件夹,-insecure代表不安全,初始不生成密码即可登录
    mysqld --initialize-insecure --user=mysql
    MySQL5.7.21在Windows下安装教程
  • 启动mysql服务
    net start mysql
    MySQL5.7.21在Windows下安装教程
  • 登录mysql,初始登录不需要密码,直接回车即可
    mysql -u root -p
    MySQL5.7.21在Windows下安装教程
  • 更新密码
    alter user 'root'@'localhost' identified by 'root';update user set authentication_string=password('root') where user='root';括号中代表新密码
    flush privileges;
    MySQL5.7.21在Windows下安装教程
  • 开启远程连接权限
    update user set host='%' where user='root';
    flush privileges;
    或者
    grant all privileges on *.* to 'root'@'%' identified by 'root' with grant option;其中%可以替换成指定主机ip,identified by后跟密码
    flush privileges;

注意事项

  • 缺少MSVCP120.dll文件
    运行mysql相关命令时可能会提示改错误,需要安装Visual C++组件, [下载地址]
    MySQL5.7.21在Windows下安装教程