MySQL 5.7.22 免安装配置

Posted gru-blog

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了MySQL 5.7.22 免安装配置相关的知识,希望对你有一定的参考价值。

转自https://blog.csdn.net/hellboy0621/article/details/80458892

 

1、官网下载对应版本,下载地址为https://dev.mysql.com/downloads/mysql/5.7.html#downloads,我下载的文件为“mysql-5.7.22-winx64.zip”;

2、考虑到数据库容量会增加,建议解压缩到可用容量较大的盘符,我解压缩到D盘;

3、进入解压缩目录,新建my.ini文件,内容如下:

  1.  
    [mysqld]
  2.  
    # set basedir to your installation path
  3.  
    basedir=D:/mysql-5.7.22-winx64
  4.  
    # set datadir to the location of your data directory
  5.  
    datadir=D:/mysql-5.7.22-winx64/data

4、使用cmd进入解压缩目录下的bin/目录下

  1.  
    # 安装mysql服务,安装完成后,可在右键“计算机”-“管理”-“服务”中看到,默认服务名为“MySQL”,也可以在install后面指定服务名称
  2.  
    D:mysql-5.7.22-winx64bin>mysqld install
  3.  
    Service successfully installed.

技术分享图片

  1.  
    # 初始化data目录
  2.  
    D:mysql-5.7.22-winx64bin>mysqld.exe --initialize

初始化后会在datadir路径下生成一个*.err的文件,打开如下:

  1.  
    2018-05-27T04:49:08.182952Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
  2.  
    2018-05-27T04:49:11.016957Z 0 [Warning] InnoDB: New log files created, LSN=45790
  3.  
    2018-05-27T04:49:11.546958Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
  4.  
    2018-05-27T04:49:11.676958Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: 4c70979b-6169-11e8-9db4-00ff13a6d817.
  5.  
    2018-05-27T04:49:11.676958Z 0 [Warning] Gtid table is not ready to be used. Table ‘mysql.gtid_executed‘ cannot be opened.
  6.  
    2018-05-27T04:49:11.696958Z 1 [Note] A temporary password is generated for [email protected]: q&10*I#<fi-w

最后一行“A temporary password is generated for [email protected]: q&10*I#<fi-w”冒号后面的就是临时密码;

  1.  
    # 启动MySQL服务
  2.  
    D:mysql-5.7.22-winx64bin>net start mysql
  3.  
    MySQL 服务正在启动 .
  4.  
    MySQL 服务已经启动成功。

5、修改密码

后面有两种方式可以修改密码,一种是使用刚才生成的临时密码登录修改,另一种是修改配置文件跳过密码登录然后修改密码;

5.1 通过临时密码登录

  1.  
    # 使用临时密码登录
  2.  
    E:mysql-5.7.22-winx64in>mysql -u root -p
  3.  
    Enter password: ************
  4.  
    Welcome to the MySQL monitor. Commands end with ; or g.
  5.  
    Your MySQL connection id is 4
  6.  
    Server version: 5.7.22
  7.  
     
  8.  
    Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.
  9.  
     
  10.  
    Oracle is a registered trademark of Oracle Corporation and/or its
  11.  
    affiliates. Other names may be trademarks of their respective
  12.  
    owners.
  13.  
     
  14.  
    Type ‘help;‘ or ‘h‘ for help. Type ‘c‘ to clear the current input statement.
  15.  
     
  16.  
    # 查看端口号
  17.  
    mysql> show global variables like ‘port‘;
  18.  
    ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.
  19.  
    # 通过ALTER语句修改密码
  20.  
    mysql> ALTER user ‘root‘@‘localhost‘ identified by ‘Jiubugaosuni_01‘;
  21.  
    Query OK, 0 rows affected (0.00 sec)
  22.  
     
  23.  
    mysql> SHOW GLOBAL VARIABLES LIKE ‘port‘;
  24.  
    +---------------+-------+
  25.  
    | Variable_name | Value |
  26.  
    +---------------+-------+
  27.  
    | port | 3306 |
  28.  
    +---------------+-------+
  29.  
    1 row in set, 1 warning (0.01 sec)

5.2 跳过密码登录

5.2.1 跳过密码登录MySQL

  1.  
    # 停止MySQL服务
  2.  
    D:mysql-5.7.22-winx64bin>net stop mysql
  3.  
    MySQL 服务正在停止.
  4.  
    MySQL 服务已成功停止。
  5.  
     
  6.  
    # 卸载MySQL服务
  7.  
    D:mysql-5.7.22-winx64bin>mysqld remove
  8.  
    Service successfully removed.
  1.  
    # 编辑my.ini配置文件,在[mysqld]下添加skip-grant-tables
  2.  
    [mysqld]
  3.  
    # set basedir to your installation path
  4.  
    basedir=D:/mysql-5.7.22-winx64
  5.  
    # set datadir to the location of your data directory
  6.  
    datadir=D:/mysql-5.7.22-winx64/data
  7.  
    skip-grant-tables
  1.  
    # 安装MySQL服务
  2.  
    D:mysql-5.7.22-winx64bin>mysqld install
  3.  
    Service successfully installed.
  4.  
     
  5.  
    # 启动MySQL服务
  6.  
    D:mysql-5.7.22-winx64bin>net start mysql
  7.  
    MySQL 服务正在启动 .
  8.  
    MySQL 服务已经启动成功。

5.2.2 无密码登录

  1.  
    D:mysql-5.7.22-winx64in>mysql -u root -p
  2.  
    Enter password:(回车,无需输入密码)
  3.  
    Welcome to the MySQL monitor. Commands end with ; or g.
  4.  
    Your MySQL connection id is 2
  5.  
    Server version: 5.7.22 MySQL Community Server (GPL)
  6.  
     
  7.  
    Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.
  8.  
     
  9.  
    Oracle is a registered trademark of Oracle Corporation and/or its
  10.  
    affiliates. Other names may be trademarks of their respective
  11.  
    owners.
  12.  
     
  13.  
    Type ‘help;‘ or ‘h‘ for help. Type ‘c‘ to clear the current input statement.
  14.  
     
  15.  
    mysql>
  1.  
    # 在这里不能使用ALTER语句,否则报错
  2.  
    mysql> ALTER user ‘root‘@‘localhost‘ identified by ‘Jiubugaosuni_01‘;
  3.  
    ERROR 1290 (HY000): The MySQL server is running with the --skip-grant-tables option so it cannot execute this
  4.  
    statement
  1.  
    # 而应该使用如下命令,设置临时密码
  2.  
    mysql> use mysql;
  3.  
    Database changed
  4.  
    mysql> UPDATE user SET authentication_string = password("Jiubugaosuni_01") WHERE user = "root";
  5.  
    Query OK, 1 row affected, 1 warning (0.07 sec)
  6.  
    Rows matched: 1 Changed: 1 Warnings: 1
  7.  
     
  8.  
    mysql> FLUSH PRIVILEGES;
  9.  
    Query OK, 0 rows affected (0.00 sec)
  10.  
     
  11.  
    mysql> QUIT;
  12.  
    Bye

5.2.3 恢复密码登录

  1.  
    # 停止MySQL服务
  2.  
    D:mysql-5.7.22-winx64bin>net stop mysql
  3.  
    MySQL 服务正在停止.
  4.  
    MySQL 服务已成功停止。
  5.  
     
  6.  
    # 卸载MySQL服务
  7.  
    D:mysql-5.7.22-winx64bin>mysqld remove
  8.  
    Service successfully removed.
  1.  
    # 修改my.ini配置文件,注释或者删除skip-grant-tables
  2.  
    [mysqld]
  3.  
    # set basedir to your installation path
  4.  
    basedir=D:/mysql-5.7.22-winx64
  5.  
    # set datadir to the location of your data directory
  6.  
    datadir=D:/mysql-5.7.22-winx64/data
  7.  
    # skip-grant-tables
  1.  
    # 安装MySQL服务
  2.  
    D:mysql-5.7.22-winx64bin>mysqld install
  3.  
    Service successfully installed.
  4.  
     
  5.  
    # 启动MySQL服务
  6.  
    D:mysql-5.7.22-winx64bin>net start mysql
  7.  
    MySQL 服务正在启动 .
  8.  
    MySQL 服务已经启动成功。

5.2.4 登录并查看端口号

  1.  
    # 使用修改的临时密码登录
  2.  
    D:mysql-5.7.22-winx64in>mysql -u root -p
  3.  
    Enter password: ***************
  4.  
    Welcome to the MySQL monitor. Commands end with ; or g.
  5.  
    Your MySQL connection id is 3
  6.  
    Server version: 5.7.22
  7.  
     
  8.  
    Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.
  9.  
     
  10.  
    Oracle is a registered trademark of Oracle Corporation and/or its
  11.  
    affiliates. Other names may be trademarks of their respective
  12.  
    owners.
  13.  
     
  14.  
    Type ‘help;‘ or ‘h‘ for help. Type ‘c‘ to clear the current input statement.
  15.  
     
  16.  
    # 必须通过ALTER语句修改密码才算正式修改密码成功
  17.  
    mysql> show global variables like ‘port‘;
  18.  
    ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.
  19.  
    mysql> ALTER user ‘root‘@‘localhost‘ identified by ‘Jiubugaosuni_01‘;
  20.  
    Query OK, 0 rows affected (0.00 sec)
  21.  
     
  22.  
    mysql> SHOW GLOBAL VARIABLES LIKE ‘port‘;
  23.  
    +---------------+-------+
  24.  
    | Variable_name | Value |
  25.  
    +---------------+-------+
  26.  
    | port | 3306 |
  27.  
    +---------------+-------+
  28.  
    1 row in set, 1 warning (0.04 sec)
  29.  
     
  30.  
    mysql> show databases;
  31.  
    +--------------------+
  32.  
    | Database |
  33.  
    +--------------------+
  34.  
    | information_schema |
  35.  
    | mysql |
  36.  
    | performance_schema |
  37.  
    | sys |
  38.  
    +--------------------+
  39.  
    4 rows in set (0.00 sec)
  40.  
     
  41.  
    mysql>

6、配置远程登录

  1.  
    # 赋予全部权限在所有数据库和所有表上给root用户在任何主机上使用Jiubugaosuni_01这个密码登录  
  2.  
    mysql> GRANT ALL PRIVILEGES ON *.* TO ‘root‘@‘%‘ IDENTIFIED BY ‘Jiubugaosuni_01‘ WITH GRANT OPTION;
  3.  
    Query OK, 0 rows affected, 1 warning (0.00 sec)
  4.  
     
  5.  
    mysql> FLUSH PRIVILEGES;
  6.  
    Query OK, 0 rows affected (0.02 sec)

以上是关于MySQL 5.7.22 免安装配置的主要内容,如果未能解决你的问题,请参考以下文章

mysql5.7安装

Centos7下MySql5.7安装及配置

MYSQL5.7.22安装教程

MYSQL5.7.22安装教程

mysql-5.7.22-winx64安装文档

详细配置主从同步的方法