下载地址:
下载后解压到D盘或者其他盘
把mysql解压后的bin目录的路径加入 WINDOWS环境变量 参考:D:\mysql-5.6.45-winx64\bin
# 进入cmd
d: # 进入D盘
cd mysql-5.6.45-winx64 # 进入mysql的解压目录
cd bin
#-------------------
5.7版本要在bin目录下手动初始化data目录
cd到bin目录下先初始化
1. mysqld --initialize-insecure自动生成无密码的root用户,
或者
2. mysqld --initialize自动生成带随机密码的root用户
#-------------------
mysqld -install # 安装mysql mysqld install
net start MySQL # 启动mysql
mysql # 第一次进入直接进入mysql无密码
mysql> use mysql; # 设置mysql密码
update user set password=password("111111") where user="root";
#5.7方式不同
update mysql.user set authentication_string=password('111111') where user='root'
# 备注
以后进入mysql 使用mysql -uroot -p 输入密码
如果直接在cmd里mysql也可以进去,但是终端不可用
关于字符集问题
mysql> show create database day01; #mysql默认使用的不是utf-8 而是 latin1
+----------+------------------------------------------------------------------+
| Database | Create Database |
+----------+------------------------------------------------------------------+
| day01 | CREATE DATABASE `day01` /*!40100 DEFAULT CHARACTER SET latin1 */ |
+----------+------------------------------------------------------------------+
1 row in set (0.00 sec)
#修改 D:\mysql-5.6.45-winx64目录下的my-default.ini 文件问 my.ini(mysql5.7的配置)
[client]
port=3306
default-character-set=utf8
[mysqld]
#skip-grant-tables=1
port = 3306
basedir=D:\mysql-5.7.27-winx64
datadir=D:\mysql-5.7.27-winx64\data
max_connections=200
character-set-server=utf8
default-storage-engine=INNODB
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
# 开启慢日志查询
slow_query_log= 1
slow-query-log-file=D:\mysql-5.7.27-winx64\data\mysql-slow.log
long_query_time= 3
#log_queries_not_using_indexes=on
early-plugin-load = ""
[mysql]
default-character-set=utf8
# 进入cmd重启mysql服务
net stop mysql
net start mysql
# 扩展:进入CMD sc delete MySQL 卸载MySQL服务
mysql> show create database day03; # 字符集修改为utf8
+----------+----------------------------------------------------------------+
| Database | Create Database |
+----------+----------------------------------------------------------------+
| day03 | CREATE DATABASE `day03` /*!40100 DEFAULT CHARACTER SET utf8 */ |
+----------+----------------------------------------------------------------+
1 row in set (0.00 sec)