Mysql安装与配置

mysql的安装和配置

软件下载

  1. Mysql5.7软件下载
  2. 下载后会得到zip 安装文件
  3. 解压的路径最好不要有中文和空格
  4. 我解压到 D:\mysql-5.7.19-winx64 目录下 【根据自己的情况来指定目录,尽量选择空间大的盘】

添加环境变量

  • 电脑-属性-高级系统设置-环境变量,在Path 环境变量增加mysql的安装目录\bin目录, 如下图

image

软件安装

添加配置文件

  1. 在D:\mysql-5.7.19-winx64 目录下下创建 my.ini 文件, 需要我们自己创建

    文件内容为:

    [client]
    port=3306
    default-character-set=utf8
    [mysqld]
    # 设置为自己MYSQL的安装目录
    basedir=D:\mysql-5.7.19-winx64\
    # 设置为MYSQL的数据目录
    datadir=D:\mysql-5.7.19-winx64\data\
    port=3306
    character_set_server=utf8
    #跳过安全检查(就是无需密码登录,待会要注释掉)
    skip-grant-tables
    
  2. 使用管理员身份打开 cmd , 并切换到 D:\mysql-5.7.19-winx64\bin 目录下, 执行mysqld -install

    D:\mysql-5.7.19-winx64\bin>mysqld -install
    Service successfully installed.
    
  3. 始化数据库: mysqld --initialize-insecure --user=mysql

    D:\mysql-5.7.19-winx64\bin>mysqld --initialize-insecure --user=mysql
    

    image

  4. 启动mysql 服务: net start mysql 【停止mysql服务指令 net stop mysql】, 如果成功:

    D:\mysql-5.7.19-winx64\bin>net start mysql
    MySQL 服务正在启动 .
    MySQL 服务已经启动成功。
    
  5. 进入mysql 管理终端: mysql -u root -p 【当前root 用户密码为 空】

    D:\mysql-5.7.19-winx64\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.
    
  6. 修改root 用户密码

    use mysql;

    update user set authentication_string=password('sdy') where user='root' and Host='localhost';

    上面的语句就是修改 root用户的密码为 hsp

    注意:在后面需要带 分号,回车即可执行该指令

    执行: flush privileges; 刷新权限

    退出: quit

    mysql> use mysql;
    Database changed
    mysql> use mysql; update user set authentication_string=password('sdy') where user='root' and Host='localhost';
    Database changed
    Query OK, 1 row affected, 1 warning (0.00 sec)
    Rows matched: 1  Changed: 1  Warnings: 1
    mysql> flush privileges;
    Query OK, 0 rows affected (0.00 sec)
    mysql> quit
    Bye
    
  7. 修改my.ini , 再次进入就会进行权限验证了

    注释掉配置文件中这行

    #skip-grant-tables
    
  8. 重新启动mysql

    net stop mysql
    net start mysql

    D:\mysql-5.7.19-winx64\bin>net stop mysql
    MySQL 服务正在停止.
    MySQL 服务已成功停止。
    
    
    D:\mysql-5.7.19-winx64\bin>net start mysql
    MySQL 服务正在启动 .
    MySQL 服务已经启动成功。
    
  9. 再次进入Mysql, 输入正确的用户名和密码

    D:\mysql-5.7.19-winx64\bin>mysql -u root -p
    Enter password: ***
    Welcome to the MySQL monitor.  Commands end with ; or \g.
    Your MySQL connection id is 4
    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服务, 再次安装.

    清除mysql服务指令:

    sc delete mysql 
    

    【删除已经安装好的mysql服务 ,提示:慎重!】

posted @ 2022-03-25 23:57  ふじさんのゆき  阅读(48)  评论(0编辑  收藏  举报