1下载安装包
去官网下载,http://dev.mysql.com/downloads/mysql/,不过官网推陈出新比较快,永远是最新的一个版本,这里我放了在百度云盘上,百度云下载地址是:链接: https://pan.baidu.com/s/1jI5CGpK 密码: yjkw
2解压
下载出来的包名字:mysql-5.7.16-winx64.zip,鼠标右键解压mysql安装包,解压到D:\MySQL5716目录下面。
3配置基本参数
配置my.ini
[mysqld] basedir = D:\MySQL5716\ datadir = D:\MySQL5716\data port = 3306 |
4库初始化
以管理员身份administrator账号进去cmd窗口界面,初始化mysql库,会自动在my.inf文件里面的datadir目录上建好data目录的:
D:\MySQL5716\bin>mysqld.exe --initialize mysqld: Could not create or access the registry key needed for the MySQL application to log to the Windows EventLog. Run the application with sufficient privileges once to create the key, add the key manually, or turn off logging for that application.
C:\Users\mch> |
Install:
D:\MySQL5716\bin>D:\MySQL5716\bin\mysqld.exe -install Install/Remove of the Service Denied!
C:\Users\mch> |
执行完后,会在目录看到err文件,打开文件搜索password,里面会有如下的描述,可以看到root账号初始化密码,如下所示:
2016-12-13T06:23:05.678590Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details). 2016-12-13T06:23:05.695700Z 0 [ERROR] Cannot open Windows EventLog; check privileges, or start server with --log_syslog=0 2016-12-13T06:23:05.695700Z 0 [ERROR] Can't find error-message file 'D:\MySQL5716\share\errmsg.sys'. Check error-message file location and 'lc-messages-dir' configuration directive. 2016-12-13T06:23:06.968561Z 0 [Warning] InnoDB: New log files created, LSN=45790 2016-12-13T06:23:07.359516Z 0 [Warning] InnoDB: Creating foreign key constraint system tables. 2016-12-13T06:23:07.563190Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: 9cc22678-c0fc-11e6-ae45-507b9d506141. 2016-12-13T06:23:07.594490Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened. 2016-12-13T06:23:07.594490Z 1 [Note] A temporary password is generated for root@localhost: HsApgaVUJ8-9 2016-12-13T07:37:58.619588Z 0 [Warning] option 'new': boolean value 't' wasn't recognized. Set to OFF. |
5启动MySQL服务
启动:
D:\MySQL5716\bin>mysqld.exe -nt --skip-grant-tables mysqld: Could not create or access the registry key needed for the MySQL application to log to the Windows EventLog. Run the application with sufficient privileges once to create the key, add the key manually, or turn off logging for that application. |
然后再开一个cmd窗口,使用mysql登陆
D:\MySQL5716\bin>mysql Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 2 Server version: 5.7.16 MySQL Community Server (GPL)
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> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | mysql | | performance_schema | | sys | | test | +--------------------+ 5 rows in set (0.00 sec)
mysql> show grants; ERROR 1290 (HY000): The MySQL server is running with the --skip-grant-tables option so it cannot execute this statement mysql> use test; Database changed mysql> create table z1(id int,cn varchar(10)) comment='only a test table .'; Query OK, 0 rows affected (0.34 sec)
mysql> |
6修改root密码
修改密码:
mysql> update MySQL.user set authentication_string=password('root') where user='root'; Query OK, 1 row affected, 1 warning (0.00 sec) Rows matched: 1 Changed: 1 Warnings: 1
mysql> flush privileges; Query OK, 0 rows affected (0.00 sec)
mysql> |
7关闭MySQL服务
鼠标底下右击工具栏-> 启动任务管理器-> 进程-> 右击mysqld.exe,选择结束进程。
8设置开机启动
设置命令是:D:\MySQL5716\bin\mysqld.exe --install mysqld--defaults-file="D:\MySQL5716\my.ini",其中后面的file是mysql启动的参数文件,中间的mysqld是服务名。
如果报错,Install/Remove of the Service Denied!,那是你没有以管理员administrator启动,即使你当前用户在administrator用户组里面,还是会报一模一样的错误,如下图12.png所示:
这里运行的时候,注意了,以administrator运行cmd.exe;操作过程是,在下面电脑的左下角搜索框输入cmd.exe,回车会弹出黑色的cmd.exe标示,然后再上面右键点击,选择以系统管理员的身份打开,如下所示,12.png
然后执行命令设置,就顺利设置成功了。
Microsoft Windows [版本 10.0.14393] (c) 2016 Microsoft Corporation。保留所有权利。
C:\Windows\system32>cd D:MySQL5716\bin C:\Windows\system32>cd D:MySQL5716\bin
C:\Windows\system32>D:
D:\MySQL5716\bin> D:\MySQL5716\bin> D:\MySQL5716\bin>D:\MySQL5716\bin\mysqld.exe --install mysqld --defaults-file="D:\MySQL5716\my.ini" Service successfully installed.
D:\MySQL5716\bin> |
然后查看,可以使用service命令来启动了