MySQL 5.7 安装

MySQL logo

配置环境变量

变量名为:MYSQL_HOME,添加你的 MySQL 文件夹所在位置

编辑 Path,复制 ;%MYSQL_HOME%\bin 到原有值的后面

配置 my.ini 文件

在 MySQL 目录下新建 my.ini 文件,my.ini 文件的内容为:

[mysqld]
#端口号
port = 3306
#mysql-5.7.27-winx64的路径
basedir=D:\Program Files\mysql-5.7.36-winx64
#mysql-5.7.27-winx64的路径+\data
datadir=D:\Program Files\mysql-5.7.36-winx64\data 
#最大连接数
max_connections=200
#编码
character-set-server=utf8
default-storage-engine=INNODB
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
[mysql]

#编码
default-character-set=utf8 

安装 MySQL

以管理员身份运行命令提示符,一定要以管理员的身份运行,否则在安装过程中会出现因为管理权限不够而导致的 Install/Remove of the Service Denied!(安装/卸载服务被拒绝)

在命令提示符中进入到 D:\Program Files\mysql-5.7.36-winx64\bin 目录

输入安装命令:mysqld -install

若出现 Service successfully installed,证明安装成功;如出现 Install of the Service Denied,则说明没有以管理员权限来运行命令提示符

然后继续输入命令:mysqld --initialize,此时不会有任何提示

再输入启动命令:net start mysql,出现提示证明 MySQL 启动成功

D:\Program Files\mysql-5.7.36-winx64\bin>net start mysql
MySQL 服务正在启动 .
MySQL 服务已经启动成功。

设置 MySQL 密码

在这里设置密码主要是为了解决 ERROR 1045 (28000): Access denied for user ‘root’@‘localhost’ (using password: NO) 的问题

首先停止 MySQL 服务,输入命令行 net stop mysql

D:\Program Files\mysql-5.7.36-winx64\bin>net stop mysql
MySQL 服务正在停止.
MySQL 服务已成功停止。

在 D:\Program Files\mysql-5.7.36-winx64 目录下找到 my.ini,在 [mysqld] 字段下任意一行添加 skip-grant-tables ,保存即可

重启 MySQL,输入启动命令:net start mysql,出现提示证明 MySQL 启动成功

D:\Program Files\mysql-5.7.36-winx64\bin>net start mysql
MySQL 服务正在启动 .
MySQL 服务已经启动成功。

在输入命令 mysql -u root -p,不需要输入密码,直接回车

D:\Program Files\mysql-5.7.36-winx64\bin>mysql -u root -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.36 MySQL Community Server (GPL)

Copyright (c) 2000, 2021, Oracle and/or its affiliates.

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>

输入命令行 use mysql,进入数据库

mysql> use mysql
Database changed

输入命令行 update user set authentication_string=password("××××××") where user="root"; ××××××是你设置的新密码,敲击回车后若出现信息,证明修改成功

mysql> update user set authentication_string=password("123456") where user="root";
Query OK, 1 row affected, 1 warning (0.00 sec)
Rows matched: 1  Changed: 1  Warnings: 1

启动任务管理器,在“服务”中找到 MySQL,点击右键,然后点击停止即可

然后在刚刚的 my.ini 文件中删除 skip-grant-tables 这一行并保存关闭

再次以管理员身份运行命令提示符,输入启动命令:net start mysql,再输入 mysql -u root -p,再输入刚刚设置的密码,出现以下信息证明设置成功

D:\Program Files\mysql-5.7.36-winx64\bin>mysql -u root -p
Enter password: ******
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.36

Copyright (c) 2000, 2021, Oracle and/or its affiliates.

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>

输入命令行 use mysql 验证一下,结果报错

mysql> use mysql
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.
mysql>

既然没有重置密码,那就重置密码,键入命令行 alter user user() identified by "××××××";

mysql> alter user user() identified by "123456";
Query OK, 0 rows affected (0.00 sec)

再次输入命令行 use mysql 验证,成功

mysql> use mysql
Database changed

至此,MySQL 5.7 安装及配置完成

nginx 初始配置文件

nginx.conf 配置文件

user  nginx;
worker_processes  auto;

error_log  /var/log/nginx/error.log notice;
pid        /var/run/nginx.pid;


events {
    worker_connections  1024;
}


http {
    include       /etc/nginx/mime.types;
    default_type  application/octet-stream;

    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    access_log  /var/log/nginx/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    keepalive_timeout  65;

    #gzip  on;

    include /etc/nginx/conf.d/*.conf;
}

default.conf 配置文件

server {
    listen       80;
    listen  [::]:80;
    server_name  localhost;

    #access_log  /var/log/nginx/host.access.log  main;

    location / {
        root   /usr/share/nginx/html;
        index  index.html index.htm;
    }

    #error_page  404              /404.html;

    # redirect server error pages to the static page /50x.html
    #
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /usr/share/nginx/html;
    }

    # proxy the PHP scripts to Apache listening on 127.0.0.1:80
    #
    #location ~ \.php$ {
    #    proxy_pass   http://127.0.0.1;
    #}

    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
    #
    #location ~ \.php$ {
    #    root           html;
    #    fastcgi_pass   127.0.0.1:9000;
    #    fastcgi_index  index.php;
    #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
    #    include        fastcgi_params;
    #}

    # deny access to .htaccess files, if Apache's document root
    # concurs with nginx's one
    #
    #location ~ /\.ht {
    #    deny  all;
    #}
}