1、解压缩
将下载到的文件解压缩到自己喜欢的位置,假设安装目录为D:\mysql
2、添加环境变量
右键计算机->属性->高级系统设置->环境变量;找到path,选择编辑,在原有值末尾添加:D:\mysql\bin
3、添加配置文件
在MySQL的安装目录(D:\mysql)下,建立新文本文件txt,并将其命名为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]
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 = D:\MySQL
datadir = D:\MySQL\data
port = 3306
#################################################
#cache
key_buffer_size=1024M
read_buffer_size=8M
query_cache_size=16M
table_open_cache=512
wait_timeout=30
sort_buffer_size = 16M
#################################################
#################################################
#connect
max-connections=1024
#################################################
#sql MySQL-slow
slow-query-log=On
slow_query_log_file="D:\\MySQL\\logs\\slowquery.log"
long_query_time=3
log_queries_not_using_indexes = ON
general_log = ON
general_log_file = "D:\\MySQL\\logs\\general_log.log"
########log settings########
log-error="D:\\MySQL\\logs\\error.log"
log_bin_trust_function_creators=1
server-id = 1
log_bin="D:\\MySQL\\logs\\MySQL-bin.log"
binlog_format = MIXED
expire_logs_days = 10
max_binlog_size = 100M
# 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
explicit_defaults_for_timestamp=true
innodb_flush_method=normal
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
保存后关闭
4、初始化数据库
以管理员自身份打开CMD执行以下命令(注意必须以管理员身份打开,否则报错)
mysqld --initialize --user=mysql --console
在控制台消息尾部会出现随机生成的初始密码,记下来(因为有特殊字符,很容易记错,最好把整个消息保存在记事本里);如果上述命令运行不成功请用以下命令代替:
D:\mysql\bin\mysqld --initialize --user=mysql --console
如果仍然不成功请检查第2步
5、将MySQL添加到系统服务
以管理员自身份打开CMD执行以下命令(注意必须以管理员身份打开,否则报错)
mysqld --install MySQL
net start MySQL
如果已有的话:
mysqld remove
mysqld --install MySQL
net start MySQL
安装成功,则显示“服务已启动成功”
如果上述命令运行不成功,可以用以下命令代替:
D:\mysql\bin\mysqld --install MySQL
net start MySQL
安装成功,则显示“服务已启动成功”;如果仍然不成功请检查第2步
6、启动MySQL并修改密码
在CMD控制台里执行命令:mysql -u root -p ;
回车执行后,输入刚才记录的随机密码;执行成功后,控制台显示 mysql>
,则表示进入mysql;输入命令set password for root@localhost = password('123'); (注意分号)
此时root用户的密码修改为123
7、MySQL远程登录设置
允许root用户在任何地方进行远程登录,并具有所有库任何操作权限,具体操作如下:
1)在本机先使用root用户登录mysql:
命令行执行:mysql -u root -p
输入密码(root的密码):12345
2)进行授权操作:
mysql>GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '12345' WITH GRANT OPTION;
重载授权表:
mysql>FLUSH PRIVILEGES;
退出mysql:quit