2025年3月18日 星期二 甲辰(龙)年 月十七 设为首页 加入收藏
rss
您当前的位置:首页 > 计算机 > 系统应用 > Windows

在 Windows 上安装 MySQL

时间:02-19来源:作者:点击数:30

在 Windows 上安装 MySQL

操作系统:Winddows Server 2012 R2 Datacenter (64位系统)

MySQL 版本:mysql-5.6.36-winx64

1. 下载安装程序

下载 mysql-5.6.36-winx64.msi

下载地址:http://ftp.ntu.edu.tw/MySQL/Downloads/MySQL-5.6/

2. 安装

双击 开始安装...

因为只有一个磁盘,所以只能安装在C盘下,这里安装在默认目录下:C:\Program Files\MySQL\MySQL Server 5.6

3. 创建 my.ini 文件

拷贝 MySQL 的安装目录下的 my-default.ini 文件到系统目录 C:\Windows 下,并改名为 my.ini 。

编辑 my.ini 文件,编辑后文件内容如下:

  • # 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.
  • [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:/Program Files/MySQL/MySQL Server 5.6"
  • datadir = "C:/Program Files/MySQL/MySQL Server 5.6/data"
  • # port = .....
  • # server_id = .....
  • port = 3306
  • 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
  • skip_grant_tables

把 datadir 指定到了MySQL安装目录下的data("C:/Program Files/MySQL/MySQL Server 5.6/data"),因为如果指向C盘的其他位置,启动 MySQL 服务时总是失败,猜测可能是 Windows Server 服务器对 C 盘的访问权限做了限制。

skip_grant_tables 功能是跳过登录验证,这样用户即使输入错误的登录密码也能成功登录,尽管这样在登录 MySQL 时就不会出现 “ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)” 错误(如下图),但这是很不安全的,不能设置这一项,要屏蔽掉。正确解决“ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)”的方法是创建用户时要这样:'用户名'@'localhost' 而不是 '用户名'@'%',举例:

mysql> CREATE USER '用户名'@'localhost' IDENTIFIED BY '用户密码';

mysql> GRANT SELECT, INSERT, UPDATE, DELETE ON <数据库名>.* TO '用户名'@'localhost';

4. 配置环境变量

创建 MYSQL_HOME 环境变量,赋值MySQL的安装目录:C:/Program Files/MySQL/MySQL Server 5.6

编辑环境变量 Path,在原内容后面追加 %MYSQL_HOME%\bin 。

5. 安装 MySQL 服务

打开命令窗口,进入到 MySQL 安装目录下的 bin 目录下,即 C:\Program Files\MySQL\MySQL Server 5.6\bin 目录下,注意:必须进入这个目录才能成功安装服务,不能因为有了前面配置的环境变量而认为在哪执行命令安装都可以。

执行服务安装命令:

mysqld –initialize

mysqld.exe -install

安装成功后会提示服务安装成功,并且在系统的服务窗口中能看到刚安装的 MySQL 服务(下图)。

6. 启动 MySQL 服务

在系统服务窗口中启动 MySQL 服务。

7. 修改登录密码

MySQL 默认是没有密码的,用户名是 root。

打开命令窗口,输入命令:

mysql –uroot

mysql> show databases;

mysql> use mysql;

mysql> UPDATE user SET password=PASSWORD("123456") WHERE user='root';

mysql> FLUSH PRIVILEGES; 【 注意一定不要忘记执行这句,否则密码更改不能生效 】

mysql> quit

安装完毕!

方便获取更多学习、工作、生活信息请关注本站微信公众号城东书院 微信服务号城东书院 微信订阅号
推荐内容
相关内容
栏目更新
栏目热门