MySQL8安装

作者: spilledyear | 来源:发表于2018-04-23 13:33 被阅读360次

    title: MySQL8安装
    date: 2018-04-25 02:12:21
    tags:
    - MySQL


    配置文件

    首先是下载安装包,我下载的是一个绿色版的,版本是 8.0.11 ,解压之后再配置一下就能用。我的解压目录是:D:\GreenSoft\MySQL

    image.png

    注意上面标记的那5个文件和 data,解压之后是没有的,都是手动加进去的。data 文件夹是在 my.ini 文件中配置的,也可以是别的名字。最主要的是 my.ini 文件, 这就是mysql默认读取的配置文件,my-default.ini 是配置文件的一个模块, my.ini 文件就是 根据 my-default.ini 修改过来的,所以,我们只需要 my.ini 文件,至于其它几个文件,是我自己图方便的,可以不用。my.ini 文件内容如下:

    # Other default tuning values
    # MySQL Server Instance Configuration File
    # ----------------------------------------------------------------------
    # Generated by the MySQL Server Instance Configuration Wizard
    #
    #
    # Installation Instructions
    # ----------------------------------------------------------------------
    #
    # On Linux you can copy this file to /etc/my.cnf to set global options,
    # mysql-data-dir/my.cnf to set server-specific options
    # (@localstatedir@ for this installation) or to
    # ~/.my.cnf to set user-specific options.
    #
    # On Windows you should keep this file in the installation directory 
    # of your server (e.g. C:\Program Files\MySQL\MySQL Server X.Y). To
    # make sure the server reads the config file use the startup option 
    # "--defaults-file". 
    #
    # To run run the server from the command line, execute this in a 
    # command line shell, e.g.
    # mysqld --defaults-file="D:\GreenSoft\MySQL\my.ini"
    #
    # To install the server as a Windows service manually, execute this in a 
    # command line shell, e.g.
    # mysqld --install mysql --defaults-file="D:\GreenSoft\MySQL\my.ini"
    #
    # And then execute this in a command line shell to start the server, e.g.
    # net start mysql
    #
    #
    # Guildlines for editing this file
    # ----------------------------------------------------------------------
    #
    # In this file, you can use all long options that the program supports.
    # If you want to know the options a program supports, start the program
    # with the "--help" option.
    #
    # More detailed information about the individual options can also be
    # found in the manual.
    #
    # For advice on how to change settings please see
    # http://dev.mysql.com/doc/refman/8.0/en/server-configuration-defaults.html
    #
    #
    # CLIENT SECTION
    # ----------------------------------------------------------------------
    #
    # The following options will be read by MySQL client applications.
    # Note that only client applications shipped by MySQL are guaranteed
    # to read this section. If you want your own MySQL client program to
    # honor these values, you need to specify it as an option during the
    # MySQL client library initialization.
    #
    
    
    [client]
    no-beep
    
    # pipe
    # socket=0.0
    port=3306
    
    
    [mysql]
    
    default-character-set=utf8
    
    
    
    
    
    
    
    
    [mysqld]
    
    # 这是8.0.4的新特性 caching_sha2_password,在linux上面使用命宁 mysql -uroot -proot 可以链接,但是使用windows下面的navict链接不成功 
    default_authentication_plugin = mysql_native_password
    
    # These are commonly set, remove the # and set as required.
    character-set-server = utf8
    basedir = D:\GreenSoft\MySQL
    datadir = D:\GreenSoft\MySQL\data
    port = 3306
    server_id = 1
    
    
    
    # Remove leading # and set to the amount of RAM for the most important data
    # cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
    innodb_buffer_pool_size = 128M
    
    # Remove leading # to turn on a very important data integrity option: logging
    # changes to the binary log between backups.
    # log_bin
    
    # General and Slow logging.
    log-output=FILE
    general-log=0
    general_log_file="CUPID.log"
    slow-query-log=1
    slow_query_log_file="CUPID-slow.log"
    long_query_time=10
    
    # Binary Logging.
    # log-bin
    
    # Error Logging.
    log-error="CUPID.err"
    
    
    
    # Remove leading # to set options mainly useful for reporting servers.
    # The server defaults are faster for transactions and fast SELECTs.
    # Adjust sizes as needed, experiment to find the optimal values.
    # join_buffer_size = 128M
    # sort_buffer_size = 2M
    # read_rnd_buffer_size = 2M 
    
    # 8.0.4版本的时候,用的是这个sql_mode,但在8.0.11版本中会报错,改成下面那个
    # sql_mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION
    sql-mode="STRICT_TRANS_TABLES,NO_ENGINE_SUBSTITUTION"
    
    default-storage-engine=INNODB
    
    innodb_log_file_size = 512M
    binlog_format='MIXED'
    max_allowed_packet = 1G
    # innodb_file_per_table = 1
    # innodb_file_format = Barracuda
    
    # 大小写是否敏感,0敏感 Linux下默认为0, Windows下默认值是 1, MacOS下默认值是 2(0敏感)
    lower_case_table_names = 1
    
    innodb_strict_mode = 0
    max_connections = 500
    
    

    初始化

    在 D:\GreenSoft\MySQL\bin 目录下,执行 以下命令

     mysqld --initialize --user=mysql --console
    
    image.png

    注意在上面生成了一个临时密码。初始化之后就会在data目录下生成一些文件,mysql自带了几个数据库,所以初始化动作是一定要执行的。此时的data文件夹内容如下:

    image.png

    安装服务

    可以使用 mysqld 工具添加服务,也可以用 nssm工具 添加服务。

    mysqld -install
    
    image.png

    然后启动mysql 服务

    net start mysql
    
    image.png

    net 可以有对应的 start、stop 操错,但是没有 remove 操错,所以如果你想 卸载 mysql 服务,需要执行 mysqld -remove。当然也可以用 nssm 工具,执行 nssm remove mysql。

    然后在命令行下登录数据库

    mysql -uroot -prhli5-jt;bxW
    
    //或者 mysql -u root -p 然后输入密码,密码就是那个初始化时生成的那个临时密码
    
    image.png

    登录之后重置密码

    set password = 'root';
    
    image.png

    退出的话,输入 exit

    image.png

    在mysql启动之后,就可以在Navicate下连接数据库了

    image.png

    在安装mysql服务之后,其实 nssm 就可以用来管理服务了,以下命令是生效的,例如:

    image.png

    因为在执行 mysqld -install 命令后, 在服务管理界面就已经可以看到 mysql 服务了,所以可以通过 nssm 来操作。

    相关文章

      网友评论

        本文标题:MySQL8安装

        本文链接:https://www.haomeiwen.com/subject/pqyklftx.html