1.下载相应的安装包
从官方网站可以找到两种文件包,一种是exe安装程序,这种的基本下一步下一步就OK了,但是在没有网络的状态下我并没有成功,另一种是zip压缩包。这次我下载的是ZIP压缩包,我选择的是8.0.11版本。
下载地址:https://downloads.mysql.com/archives/community/
2.解压进行配置
将该zip包解压到相应的目录下新建my.ini文件,相关内容如下:
# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/8.0/en/server-configuration-defaults.html
# *** DO NOT EDIT THIS FILE. It's a template which will be copied to the
# *** default location during install, and will be replaced if you
# *** upgrade to a newer version of MySQL.
[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 = C:\Mysql8.0.11
datadir = C:\Mysql8.0.11\data
port = 3306
server_id = 1
# 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
3.进行初始化命令
以管理员身份运行cmd
进入到mysql安装目录的bin下,执行命令:mysqld --defaults-file=C:\Mysql8.0.11\my.ini --initialize --console
注意:将红框内的密码记录下来(AIRlFkiEb7_B)临时密码,后续用于登陆修改密码。
注:可能会遇到这个错误
解决:windows系统缺少vc++2015,则需要下载安装vc_redist
4.创建服务
还是在bin目录下执行mysqld install MySQLXLM --defaults-file="C:\Mysql8.0.11\my.ini"
MySQLXLM为服务名,出现Service successfully installed.说明创建已成功
注意:如果不是以管理员身份运行cmd,到这步会报错Install/Remove of the Service Denied!
5.测试连接
使用win+r打开compmgmt.msc管理
找到MySQLXLM(自定义服务名)启动
启动后使用navicat连接
输入临时密码连接会出现1251错误(这里缺张报错的截图有机会补上),原因是MySQL8.0版本的加密方式和MySQL5.0的不一样,连接会报错。mysql8 之前的版本中加密规则是mysql_native_password
,而在mysql8之后,加密规则是caching_sha2_password
。
6.修改密码
还是在bin目录下执行mysql -uroot -p -P3306
(3306为my.ini文件中自定义的端口)后输入之前记录的临时密码登录。远程连接请将localhost
换成%
:
更改加密方式:alter user root@localhost identified by 'password' password expire never;
更新用户密码:alter user root@localhost identified with mysql_native_password by 'password';
其中by后面的为修改后的密码,最后再输入flush privileges
刷新权限;
7.修改数据库存储的位置
比如从安装目录下的C:\Mysql8.0.11\data文件夹转移到D:\mySQLData文件夹。
(1)在D:\下新建mySQLData文件夹
(2)停止MySQL服务
(3)将C:\Mysql8.0.11\data下的文件夹和文件一起拷贝到D:\mySQLData文件夹下
(4)在安装目录C:\Mysql8.0.11下找到my.ini文件,修改datadir为:
datadir = D:\mySQLData
保存后,重新启动mySQL服务即可。