MySQL 8.0.11 Windows zip 安装过程

xiaoxiao2021-02-28  21

〇、准备: MySQL8.0 Windows zip包下载地址:https://cdn.mysql.com//Downloads/MySQL-8.0/mysql-8.0.11-winx64.zip

环境:Windows 10

一、安装

1. 解压zip包到安装目录

比如我的安装目录是:F:\installDir\mysql-8.0.11-winx64

2.配置文件

在Windows系统中,配置文件默认是安装目录下的 my.ini 文件,部分配置需要在初始安装时配置,大部分也可以在安装完成后进行更改。当然,极端情况下,所有的都是可以更改的。

在安装根目录(这里是F:\installDir\mysql-8.0.11-winx64)下新建my.ini,比如我这里是:‪F:\installDir\mysql-8.0.11-winx64\my.ini,写入基本配置:

[mysqld] # 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 # These are commonly set, remove the # and set as required. basedir = F:\installDir\mysql-8.0.11-winx64 datadir = F:\installDir\MySQLData port = 3306 # server_id = ..... # 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 sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES character-set-server = utf8mb4 performance_schema_max_table_instances = 600 table_definition_cache = 400 table_open_cache = 256 [mysql] default-character-set = utf8mb4 [client] default-character-set = utf8mb4注意,里面的 basedir 是我本地的安装目录,datadir 是我数据库数据文件要存放的位置,各项配置需要根据自己的环境进行配置。

查看所有的配置项,可参考:https://dev.mysql.com/doc/refman/8.0/en/mysqld-option-tables.html

3.初始化数据库

在MySQL安装目录的 bin 目录下执行命令,该命令不用在Admin下执行: mysqld --initialize --console

执行完成后,会打印 root 用户的初始默认密码,比如:

F:\installDir\mysql-8.0.11-winx64\bin>mysqld --initialize --console 2018-05-02T14:48:16.104721Z 0 [Warning] [MY-010915] [Server] 'NO_ZERO_DATE', 'NO_ZERO_IN_DATE' and 'ERROR_FOR_DIVISION_BY_ZERO' sql modes should be used with strict mode. They will be merged with strict mode in a future release. 2018-05-02T14:48:16.104854Z 0 [System] [MY-013169] [Server] F:\installDir\mysql-8.0.11-winx64\bin\mysqld.exe (mysqld 8.0.11) initializing of server in progress as process 532 2018-05-02T14:48:33.113492Z 5 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: 1cuP+wCQ2oni 2018-05-02T14:48:47.492974Z 0 [System] [MY-013170] [Server] F:\installDir\mysql-8.0.11-winx64\bin\mysqld.exe (mysqld 8.0.11) initializing of server has completed其中,第4行的“1cuP+wCQ2oni”就是初始密码,在没有更改密码前,需要记住这个密码,后续登录需要用到。 要是你手贱,关快了,或者没记住,那也没事,删掉初始化的 datadir 目录,再执行一遍初始化命令,又会重新生成的。当然,也可以使用安全工具,强制改密码,用什么方法,自己随意。

参考:https://dev.mysql.com/doc/refman/8.0/en/data-directory-initialization-mysqld.html

4.安装服务

在MySQL安装目录的 bin 目录下执行命令,注意该命令要使用admin去执行,否则无权限执行:

mysqld --install [服务名]

后面的服务名可以不写,默认的名字为 mysql。当然,如果你的电脑上需要安装多个MySQL服务,就可以用不同的名字区分了,比如 mysql5 和 mysql8。

执行成功效果如下:

F:\installDir\mysql-8.0.11-winx64\bin>mysqld --install Service successfully installed.安装完成之后,就可以通过命令net start mysql启动MySQL的服务了。

参考:https://dev.mysql.com/doc/refman/8.0/en/windows-start-service.html

二、更改密码和密码认证插件

在MySQL安装目录的 bin 目录下执行命令:

mysql -uroot -p这时候会提示输入密码,记住了第3步的密码,填入即可登录成功,进入MySQL命令模式。

在MySQL8.0.4以前,执行

SET PASSWORD=PASSWORD('[修改的密码]');就可以更改密码,但是MySQL8.0.4开始,这样默认是不行的。因为之前,MySQL的密码认证插件是“mysql_native_password”,而现在使用的是“caching_sha2_password”。 因为当前有很多数据库工具和链接包都不支持“caching_sha2_password”,为了方便,我暂时还是改回了“mysql_native_password”认证插件。

在MySQL中执行命令,其中password是自己想要修改的密码:

ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'password';修改密码验证插件,同时修改密码。 如果想默认使用“mysql_native_password”插件认证,可以在配置文件中配置 default_authentication_plugin项。 [mysqld] default_authentication_plugin=mysql_native_password参考: https://dev.mysql.com/doc/refman/8.0/en/upgrading-from-previous-series.html#upgrade-caching-sha2-password

三、速度测试

不用测了,官方说MySQL8比5快两倍。

附CentOS tar.gz 包安装:

wget https://cdn.mysql.com//Downloads/MySQL-8.0/mysql-8.0.11-linux-glibc2.12-x86_64.tar.gz shell> tar zxvf mysql-8.0.11-linux-glibc2.12-x86_64.tar.gz -C /usr/local/ shell> groupadd mysql shell> useradd -r -g mysql -s /bin/false mysql shell> cd /usr/local shell> ln -s mysql-8.0.11-linux-glibc2.12-x86_64 mysql shell> cd mysql shell> mkdir mysql-files shell> chown mysql:mysql mysql-files shell> chmod 750 mysql-files shell> bin/mysqld --initialize --user=mysql shell> bin/mysql_ssl_rsa_setup shell> bin/mysqld_safe --user=mysql & # Next command is optional shell> cp support-files/mysql.server /etc/init.d/mysql.server

最后附上自己win10上安装的MySQL8.0.11的my.ini中的内容供大家参考:

[mysqld] # 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 # These are commonly set, remove the # and set as required. basedir = F:\installDir\mysql-8.0.11-winx64 datadir = F:\installDir\MySQLData port = 3306 # server_id = ..... # 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 sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES character-set-server = utf8mb4 performance_schema_max_table_instances = 600 table_definition_cache = 400 table_open_cache = 256 [mysql] default-character-set = utf8mb4 [mysqld] default_authentication_plugin=mysql_native_password [client] default-character-set = utf8mb4注:该博客参考 https://blog.csdn.net/zwj1030711290/article/details/80039780,自己亲自测试安装过,对原博客中写得不清晰的地方做了补充。

转载请注明原文地址: https://www.6miu.com/read-2628729.html

最新回复(0)