Windows安装MySQL

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服务即可。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

小强签名设计

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值