Home  >  Article  >  Database  >  Graphical tutorial on the installation and configuration of mysql5.7.15 in Windows environment

Graphical tutorial on the installation and configuration of mysql5.7.15 in Windows environment

黄舟
黄舟Original
2017-07-24 15:46:361239browse

这篇文章主要为大家详细介绍了mysql 5.7.15 安装配置方法图文教程,具有一定的参考价值,感兴趣的小伙伴们可以参考一下

因本人需要需要安装MySQL,现将安装过程记录如下,在自己记录的同时,希望对有疑问的人有所帮助。

一、下载软件

1. 进入mysql官网,登陆自己的oracle账号(没有账号的自己注册一个),下载Mysql-5.7.15,下载地址:http://dev.mysql.com/downloads/mysql/

2.将下载好的文件解压到指定目录,笔者解压在D:\mysql-5.7.15-winx64

二、 安装过程

1.首先配置环境变量path,将D:\mysql-5.7.15-winx64\bin配置到自己的path中,具体再次不详述

2.在解压路径下复制my-default.ini,修改名称为my.ini如下图所示

3.打开文件my.ini,添加内容如下:


[mysqld] 
basedir=D:\\mysql-5.7.15-winx64 
datadir=D:\\mysql-5.7.15-winx64\\data 
port=3306

sql_mode="STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION"  

其中basedir:是上述mysql的解压路径

datadir:后续初始化等数据都会保存在该目录下(注意:不要在该文件目录下新建data文件夹,我的新建data文件夹就会出错,按我的操作步骤,后续操作会自动创建的。)
port:表示连接数据库的端口
sql_mode:表示sql的模式

三、 初始化数据库   配置相关信息

1.以管理员身份运行windows 命令行(特别提醒:WIN7及WIN7以上版本系统这里一定要用管理员身份,不然后续操作会出错)

2. 进入mysql的解压缩目录 D:\mysql-5.7.15-winx64\bin(提醒:此处需要进入bin目录,否则后续操作会出现错误)

3.输入:mysqld --initialize --user=mysql --console,执行后进行初始化,此时会生成root的初始密码

记下此时生成的初始化密码。

4.注册Mysql服务。运行命令:mysqld --install MySQL

如果出现:"Service successfully installed.“ 提示,证明成功安装mysql服务.

5.此时,可以起动mysql服务,net start mysql

用户可能会出现如下错误:
发生系统错误 2. 系统找不到指定文件。

错误原因:如上所述,在运行安装service命令:mysqld --install MySQL时,我们没有进入bin目录,进行安装。                      
解决方案:进入bin目录,首先移除service,运行命令 mysqld --remove
Service successfully removed。
重新安装mysql服务,运行命令mysqld --install ,再启动mysql服务
D:\mysql-5.7.15-winx64>net start mysql
MySQL 服务正在启动
MySQL 服务已启动成功
此时mysql服务已成功起动。

四、登陆数据库,修改密码

在my.ini文件中在[mysqld]后一行加入skip-grant-tables
此时,关闭mysql服务,再重新启动。
(命令行中输入net stop mysql关闭MySQL服务,输入net start mysql 开启MySQL服务)
登陆:输入 mysql -u root -p 后回车键,密码为空,不输入,直接回车,即可登录MySQL

选择mysql数据库:

查询mysql数据库的user表,select * from user

此时,我们发现密码字段的名称为authentication_string。有的可能会是password,根据你查询出来的结果为准。
对表user执行update操作:update user set authentication_string = password("123456") where user="root" 

操作成功。退出mysql
删除my.ini 文件中的skip-grant-tables ,重新启动mysql服务。登录MySQL

Possible problems in the future:
After installing mysql, after logging in, no matter what command is run, this is always prompted: You must reset your password using ALTER USER statement before executing this statement.

When this problem occurs, you only need to continue running the following two commands under the command line mysql:

ALTER USER 'root'@'localhost' PASSWORD EXPIRE NEVER;

flush privileges;


Note: The above are 2 commands and need to be executed separately.

After completing the above two commands, MySQL will be installed completely.

The above is the detailed content of Graphical tutorial on the installation and configuration of mysql5.7.15 in Windows environment. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn