mysql5.7.21压缩包安装

mysql5.7.21压缩包安装
mysql自5.5以后就不再提供64位可运行安装文件,所以要安装最新的mysql64位数据库就需要下载压缩包手动安装。

1.下载安装文件
    到官网地址下载https://www.mysql.com/downloads/ 社区版 MySQL Community Edition (GPL)
    例如:mysql-5.7.21-winx64.zip
    
2.解压缩
    将解压好的文件夹剪切到安装目录。例如D:\pf\mysql-5.7.21-winx64
    
3.创建配置文件
    If you need to specify startup options when you run the server,
    you can indicate them on the command line or place them in an option file.
    MySQL looks for options in each location first in the my.ini file, and then in the my.cnf file.
    However, to avoid confusion, it is best if you use only one file.

    =========================================================    
    [mysqld]
    # set basedir to your installation path
    basedir=D:/pf/mysql-5.7.21-winx64
    # set datadir to the location of your data directory
    datadir=D:/pf/mysql-5.7.21-winx64/data
    # 默认密码过期时间,0代表永不过期
    default_password_lifetime=0
    =========================================================

    Option Files Read on Windows Systems
    +=========================================================================================+========================================================+
    |File Name                                                                                  | Purpose                                                |
    +-----------------------------------------------------------------------------------------+--------------------------------------------------------+
    |%PROGRAMDATA%\MySQL\MySQL Server 5.7\my.ini, %PROGRAMDATA%\MySQL\MySQL Server 5.7\my.cnf |    Global options                                         |
    |%WINDIR%\my.ini, %WINDIR%\my.cnf                                                          | Global options                                         |
    |C:\my.ini, C:\my.cnf                                                                     | Global options                                         |
    |BASEDIR\my.ini, BASEDIR\my.cnf                                                              | Global options                                         |
    |defaults-extra-file                                                                      | The file specified with --defaults-extra-file, if any  |
    |%APPDATA%\MySQL\.mylogin.cnf                                                              | Login path options (clients only)                      |
    +==================================================================================================================================================+

    Option Files Read on Unix and Unix-Like Systems
    +=========================================================================================+========================================================+
    |File Name                                                                                  | Purpose                                                |
    +-----------------------------------------------------------------------------------------+--------------------------------------------------------+
    |/etc/my.cnf                                                                              | Global options                                         |
    |/etc/mysql/my.cnf                                                                          | Global options                                         |
    |SYSCONFDIR/my.cnf                                                                          | Global options                                         |
    |$MYSQL_HOME/my.cnf                                                                          | Server-specific options (server only)                  |
    |defaults-extra-file                                                                      | The file specified with --defaults-extra-file, if any  |
    |~/.my.cnf                                                                                  | User-specific options                                  |
    |~/.mylogin.cnf                                                                              | User-specific login path options (clients only)        |
    +==================================================================================================================================================+

4.选择MySQL服务类型
     The following table shows the available servers for Windows in MySQL 5.7.
    +========================================================================================================+
    | Binary        | Description                                                                            |
    +--------------------------------------------------------------------------------------------------------+
    | mysqld        | Optimized binary with named-pipe support                                               |
    | mysqld-debug    | Like mysqld, but compiled with full debugging and automatic memory allocation checking |
    +========================================================================================================+
    
    MySQL supports TCP/IP on all Windows platforms. MySQL servers on Windows also support named pipes, if you start the server with the --enable-named-pipe option.
    It is necessary to use this option explicitly because some users have experienced problems with shutting down the MySQL server when named pipes were used.
    The default is to use TCP/IP regardless of platform because named pipes are slower than TCP/IP in many Windows configurations.

5.安装MySQL
    注意默认可能需要手动创建data目录到MySQL安装目录下,如果有创建配置文件可以指定配置文件
    
    mysqld --initialize                    
    // 创建数据库文件,并为默认用户root创建随机密码,密码信息在{datadir}/DESKTOP-XFIRE.err文件中
    // 例如:[Note] A temporary password is generated for root@localhost: beiqyJ-)>5fB
    
    mysqld --initialize-insecure
    // 创建数据库文件,但不设置密码
    
    mysqld --initialize --user=mysql
    // 类Linux系统需要指定控制访问用户为mysql
    
    mysqld --defaults-file=D:\pf\mysql-5.7.21-winx64\my.ini --initialize
    // 指定配置文件创建初始化数据库,用于datadir有特殊配置
    
    注意:[ERROR] --initialize specified but the data directory exists. Aborting.这个错误相信代表datadir文件夹下数据不为空,最好将datadir下的文件备份后删除再允许初始化命令
    
6.启动MySQL服务
    mysqld --install
    // windows下安装服务
    
    mysqld --remove
    // windows下删除服务
    
    mysqld --console
    // 启动服务并显示启动信息
    
    net start mysql
    // 启动安装的服务

6.登录服务
    mysql -u root -p
    // 如果使用mysqld --initialize命令初始化数据库,要将生成的随机密码输入
    
    mysql -u root --skip-password
    // 如果使用mysqld --initialize-insecure命令初始化数据库,跳过密码输入

7。更改默认用户安全帐号
    mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'new_password';
    // 更改指定用户密码
    
    mysql> ALTER USER user() IDENTIFIED BY 'new_password';
    // 更改当前用户密码
    
    注意:如果使用的系统随机密码登录,必须先更改用户密码后才能执行其它操作

你可能感兴趣的:(数据库)