具体步骤如下:
- 从官网下载对应的版本。官方网址:mysql服务下载地址
- 解压到本地。我的路径是:D:\Program Files\mysql-5.7.16-winx64
- 设置环境变量。
- 添加一个系统变量。变量名:MYSQL_HOME,变量值是mysql的安装目录,我这里是:D:\Program Files\mysql-5.7.16-winx64
- 在Path变量中添加的末尾添加 ;%MYSQL_HOME%\bin
- 在安装目录下新建一个文本文档,并改名为 my.ini,并添加如下内容,保存。
[WinMySQLAdmin]
Server=D:\Program Files\mysql-5.7.16-winx64\bin\mysqld.exe
[mysqld]
basedir=D:\Program Files\mysql-5.7.16-winx64
datadir=D:\Program Files\mysql-5.7.16-winx64\data
port = 3306
server_id = 1
max_connections=1024
log_bin = mysql-bin
explicit_defaults_for_timestamp = TRUE
在安装目录下新建一个文件夹命名为data用来存放数据。
管理员身份进入cmd执x行初始化命令:mysqld --initialize --user=mysql --console
C:\Users\Administrator>mysqld --initialize --user=mysql --console
2016-12-07T07:29:17.384477Z 0 [Warning] InnoDB: New log files created, LSN=45790
2016-12-07T07:29:18.266527Z 0 [Warning] InnoDB: Creating foreign key constraint
system tables.
2016-12-07T07:29:18.648549Z 0 [Warning] No existing UUID has been found, so we a
ssume that this is the first time that this server has been started. Generating
a new UUID: dd3b2bf3-bc4e-11e6-8a79-6c0b8469263a.
2016-12-07T07:29:18.693552Z 0 [Warning] Gtid table is not ready to be used. Tabl
e 'mysql.gtid_executed' cannot be opened.
2016-12-07T07:29:18.727554Z 1 [Note] A temporary password is generated for root@
localhost: x>%B_fO)v1VV
产生一个随机密码,用记事本保存下来:x>%B_fO)v1VV
如果出现了以下警告:
2016-12-07T07:18:13.748519Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see doc
umentation for more details).
检查你的my.ini 中explicit_defaults_for_timestamp = TRUE是否配置正确
2016-12-07T07:18:13.749519Z 0 [ERROR] --initialize specified but the data direct
ory has files in it. Aborting.
这是前面安装失败导致D:\Program Files\mysql-5.7.16-winx64\data下产生了旧数据,将旧数据删掉即可。
- 输入安装命令:mysqld --install
C:\Users\Administrator>mysqld --install
Service successfully installed.
表示安装成功
- 输入启动命令:net start MySQL
C:\Users\Administrator>net start MySQL
发生系统错误 2。
系统找不到指定的文件。
解决办法:修改mysql注册表。
开始-->运行-->regedit-->HKEY_LOCAL_MACHINE-->SYSTEM-->CurrentControlSet-->services-->mysql(服务名)-->ImagePath
将ImagePath的路径更改为:
"安装目录\bin\mysqld" --defaults-file="安装目录\my.ini" MySql
我这里是:
"D:\Program Files\mysql-5.7.16-winx64\bin\mysqld" --defaults-file="D:\Program Files\mysql-5.7.16-winx64\my.ini" MySql
更改后 服务成功启动。
>MySql 服务正在启动 .
MySql 服务已经启动成功。
-
输入进入mysql命令:mysql -u root -p
D:\Program Files\mysql-5.7.16-winx64\bin>mysql -u root -p
Enter password: 这里输入第6步产生的随机密码
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.16-log
Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql>出现了mysql> 表示成功进入到mysql
修改root用户的初始密码:set password for root@localhost = password('要修改的密码');
mysql> set password for root@localhost = password('要修改的密码');
Query OK, 0 rows affected, 1 warning (0.01 sec)
- 查看mysql数据库:show databases;
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
+--------------------+
4 rows in set (0.00 sec)
参考文章:
http://jingyan.baidu.com/article/8cdccae946133f315513cd6a.html
http://blog.csdn.net/yanlintao1/article/details/52202736
http://www.oschina.net/question/727667_121198