导读:这里介绍的是5.7.28版本的安装,选择它并非某方面的优势,只因工作需要,与在用生产版本保持一致,若更高版本,建议是更换为mariadb。
1.下载MySQL安装包
2.解压并配置
(1)把下载回来的压缩包解决到目标目录,(原目录名 mysql-5.7.28-winx64 这里修改为 mysq5.7.28)
(2)配置环境变更
右击我的电脑/计算机,点击属性,打开高级系统设置,点击环境变量。
变量名:MYSQL_HOME
变量值:E:\mysq5.7.28
path里添加:%MYSQL_HOME%\bin
(3)创建数据目录及配置文件
这个版本没有data目录与my.ini文件,需要手动创建。在MYSQL_HOME目录下创建data目录,我这里设为E:\mysq5.7.28\data,my.ini建议放在MYSQL_HOME目录下,简单配置可参考:
[mysqld]
port=3306
character_set_server=utf8
basedir=E:\mysq5.7.28
datadir=E:\mysq5.7.28\data
server-id=1
sql_mode=NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION
lower_case_table_names=1
innodb_file_per_table = 1
log_timestamps=SYSTEM
log-error=error.log
slow_query_log = 1
slow_query_log_file = slow.log
long_query_time = 5
log-bin = binlog
binlog_format = row
expire_logs_days = 15
log_bin_trust_function_creators = 1
secure-file-priv=E:\mysq5.7.28\Uploads
[client]
default-character-set=utf8
注:
1)、my.ini文件 需要是 ASCII格式
2)、各参数“=”号两边 不能留空格
该步骤完成后目录情况如下:(Uploads目录视情况,需要就建立)
3.初始化数据库
在命令行cmd里进入 E:\mysq5.7.28\bin目录,执行命令 mysqld --initialize-insecure ,执行后
注:在执行这个步骤中遇到了丢失MSVCR120.dll的问题,下了所谓的dll修复工具然而并没有用,应是 VC++文件缺失,最后找到一个各版本合集修复工具“VisualCppRedist_AIO_x86_x64_20200123.exe”,安装后解决。
4.注册并启动MySQL服务
(1)命令行,进入E:\mysq5.7.28\bin目录,执行mysqld –install MySQL5728安装服务(MySQL5728是服务名,自行定义)
(2)命令行,同样在E:\mysq5.7.28\bin目录下,执行 net start MySQL5728启动MySQL服务
E:\mysq5.7.28\bin>mysqld –install MySQL5728
Service successfully installed.
E:\mysq5.7.28\bin>net start MySQL5728
MySQL5728 服务正在启动 .
MySQL5728 服务已经启动成功。
E:\mysq5.7.28\bin>
5.登陆/修改密码
(1)登陆
E:\mysq5.7.28\bin>mysql -uroot
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.28-log MySQL Community Server (GPL)
Copyright (c) 2000, 2019, 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>
(2)修改密码
mysql> alter user 'root'@'localhost' identified by ' password123456';
Query OK, 0 rows affected (0.00 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
(3)设置权限,允许远程登陆
mysql> grant all privileges on *.* to 'root'@'%' identified by 'password123456' with
grant option;
Query OK, 0 rows affected, 1 warning (0.01 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
测试登陆成功: