参考:z1074907546的博客,网址:http://blog.csdn.net/z1074907546/article/details/51482718
一、安装方式一
下载对应的mysql的zip文件,mysql-5.7.19-winx64.zip
解压到任意位置
在path中添加bin目录,如:E:\install\mysql\mysql-5.7.19-winx64\bin
在mysql-5.7.19-winx64下建立my.ini
如下:
[client]
port=3306
default-character-set=utf8
[mysqld]
port=3306
character_set_server=utf8
#解压目录
basedir=E:\install\mysql\mysql-5.7.19-winx64
#解压目录下data目录
datadir=E:\install\mysql\mysql-5.7.19-winx64\data
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
进入:cmd下解压的目录的bin下面
命令:mysqld --initialize #直接初始化mysql,生成data文件夹中的文件。
命令:mysqld -install #安装mysql
命令:net start mysql #启动服务器
skip-grant-tables
之后重启mysql net start mysql
如果关闭服务 net stop mysql
此时在cmd下mysql -uroot -p 不需要密码
进入mysql后,则修改root账号密码
(版本5.5)update user set password=password("新密码") where user="root";
(版本5.7)update user set authentication_string=password('12345') where user='root' and Host = 'localhost';
刷新权限表,flush privileges;
退出后,重新修改my.ini把kip-grant-tables"这行删除。
修改后重启mysql服务,重新登陆
mysql -uroot -p12345即可。
二、安装方式二
下载对应的zip文件,如mysql-5.7.17-winx64.zip
在目录下建立data文件,主目录下有my-default.ini配置文件,修改对应的
basedir=E:\install\mysql5.7\mysql-5.7.17-winx64
datadir=E:\install\mysql5.7\mysql-5.7.17-winx64\data
port=3306
完整如下:
# 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=E:\install\mysql5.7\mysql-5.7.17-winx64
datadir=E:\install\mysql5.7\mysql-5.7.17-winx64\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
添加path到环境变量的mysql的bin目录
安装服务:
cmd进入解压缩的文件的bin下,
mysqld --install "MySQL5.7.17" --defaults-file="E:\install\mysql5.7\mysql-5.7.18-winx64\my-default"
MySQL5.17为注册的服务器名称
之后运行net start mysql或者直接在服务中重启mysql,启动后,可能会提示有问题,
此时需要在cmd的管理员下进入myql安装的bin下,输入:
mysqld --initialize-insecure 自动生成无密码的root用户,如果有其他问题,则需要清空mysql的data文件夹下面的所有文件,之后继续运行那个即可。
之后输入mysql -uroot -p 密码为空,即可进入mysql中,修改密码为:
SET PASSWORD FOR 'root'@'localhost' = PASSWORD('12345');
FLUSH PRIVILEGES;
即可。
如果删除本地服务,可在cmd下dos 命令, sc delete ServiceName