安装MySQL
准备阶段
在这里使用的是压缩包版本的,非msi格式安装包
压缩版的优点是安装快,方便,相对不复杂
mysql5.7 64位下载地址:
https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.19-winx64.zip
安装阶段
步骤一:解压
下载后得到zip压缩包,放到自己的文件目录中
建议要有自己的特定安装环境文件目录,易于后期的文件查找便利性
步骤二:配置环境变量
我的电脑–>右键–>属性–>高级系统设置–>环境变量–>(系统变量(S)区域)–>打开Path
点击新建,输入 mysql 安装文件下面的bin目录
例如: D:\mysql-5.7.19\bin
在win7中的Path内容是整条的,需要以英文分号做间隔;D:\mysql-5.7.19\bin
步骤三:补充配置文件
在D:\mysql-5.7.19
文件夹下新建一个my.ini文件,根据个人文件夹添加
编辑 my.ini 文件, 添加以下数据, 注意替换basedir和datadir路径位置,
[mysqld]
basedir=D:mysql-5.7\
datadir=D:mysql-5.7\data\
port=3306
skip-grant-tables
步骤四:初始化配置
1.安装MySQL服务
启动管理员模式下的CMD,并将路径切换至mysql下的bin目录
然后输入mysqld –install
D:\mysql-5.7.19\bin> mysqld –install
Service Succesfully install.
2.初始化数据文件
输入mysqld --initialize-insecure --user=mysql
D:\mysql-5.7.19\bin> mysqld --initialize-insecure --user=mysql
没有提示说明成功,可以看到D:\mysql-5.7.19目录下多了一个data文件夹
步骤五:更改root密码
1.开启mysql服务
输入命令net start mysql
启动mysql
D:\mysql-5.7.19\bin> net start mysql
MySQL 服务正在启动.
MySQL 服务已经启动成功.
2.进入mysql管理界面
输入命令 mysql –u root –p 进入mysql
管理界面(密码可为空),按Enter直接进入
D:\mysql-5.7.19\bin>mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.7.19 MySQL Community Server (GPL)
Copyright (c) 2000, 2017, 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>
3.更改root密码
输入命令:
update mysql.user set authentication_string=password('123456') where user='root' and Host = 'localhost';
必须注意:password(‘123456’)中的123456就是root密码,可以将整条命令粘贴到文本文档中做修改,然后再粘贴到CMD当中
mysql> update mysql.user set authentication_string=password('123456') where user='root' and Host = 'localhost';
Query OK, 1 row affected, 1 warning (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 1
mysql>
刷新权限:
配置好root密码后,需要刷新权限,输入命令:
mysql> flush privileges;
Query OK, 0rows affected (0.01 sec)
mysql>
4.修改 my.ini文件
上面的步骤无报错后,需要把配置文件中最后一条注释或删除,
//注释方式:加#
[mysqld]
basedir=D:\mysql-5.7.19\
datadir=D:\mysql-5.7.19\data\
port=3306
#skip-grant-tables
这条是的意思是跳过验证,免密直接进入,否则设置密码的步骤就没有意义了!
步骤六:测试验证
1.重启mysql
退出mysql, 输入exit
mysql> exit
Bye
停止服务,输入net stop mysql
C:\WINDOWS\system32>net stop mysql
MySQL 服务正在停止.
MySQL 服务已成功停止。
重启服务,输入net start mysql
C:\WINDOWS\system32>net start mysql
MySQL 服务正在启动 .
MySQL 服务已经启动成功。
2.连接测试
输入mysql –u root –p
+密码,能够进入mysql控制台即安装完成!
注意:最后的 -p和密码之间没有空格,如果敲了空格进去,则被认为是密码的一部分
C:\WINDOWS\system32>mysql -u root -p123456
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 5
Server version: 5.7.19 MySQL Community Server (GPL)
Copyright (c) 2000, 2017, 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 –u root –p
,然后会提醒输入非明文的密码,相对安全不易出错
C:\WINDOWS\system32>mysql -u root -p
Enter password: ******
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.7.19 MySQL Community Server (GPL)
Copyright (c) 2000, 2017, 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服务
net start mysql
个人电脑使用后以免浪费系统资源,关闭服务
net stop mysql