一、下载MySQL数据库解压版并解压
二、配置环境变量
在系统变量path后面添加MySQL安装路径下的bin目录;
例:E:\mysql\bin
三、修改MySQL配置文件
在MySQL安装目录下有一个my-default.ini文件,复制一份,改名为my.ini,修改里面的配置。
原始文件my-default.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.
[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;datadir;port。
basedir为MySQL安装根路径,datadir为MySQL安装根目录下的data文件夹路径。port为默认端口号。
例:
修改后文件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.
[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用户的密码不能为空,在使用前必须设置密码。
1.在配置文件my.ini中,[mysqld]后一行加入skip-grant-tables;
2.重启MySQL服务;
3.执行mysql -u root -p
,此时会提示输入密码,直接回车跳过,登录成功。
4.选择mysql数据库。执行use mysql;
5.对user表执行更新操作。update user set authentication_string=password("你的密码") where user="root";
6.刷新MySQL的系统权限相关表。执行flush privileges
。刷新后退出,执行quit
。mysql 新设置用户或更改密码后需刷新相关表,否则会出现拒绝访问。
7.重新启动MySQL服务。