参考博客地址:https://my.oschina.net/715/blog/1798352?nocache=1524302856642
mysql安装一般有两种,一种是通过msi文件安装,一种是zip解压。
由于我几次都没有弄好msi文件安装,所以只能zip方式解压安装。
环境:
win7专业版
一、zip解压安装步骤
官网下载zip安装包
地址:https://dev.mysql.com/downloads/file/?id=476233
解压zip文件到安装目录
- 创建my.ini文件
首先,需要在安装目录里创建新文件 my.ini ,此文件与bin文件夹并列
大概内容如下:
[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 = D:\runtime software\mysql-8.0.11-winx64 datadir = D:\runtime software\mysql-data 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为数据存放目录,大家根据自己需要自行修改
2.初始化并安装mysql
在bin文件夹,按住shift+右键,打开cmd命令行
(如没有权限,在C:\Windows\System32 找到cmd文件,发送快捷方式到桌面,然后右键-管理员身份运行)
进入到bin目录
输入
mysqld --initialize --console |
显示 .....has completed就表示完成了
其中有一个初始密码,要记下来
A temporary password is generated for root@localhost:后面的就是密码
然后输入命令:
mysqld install |
结果为下图就安装成功了
(tips: 如果提示 service exists ,那说明以前的mysql没有删除干净,建议百度一篇比较详细的,删除后重启电脑。)
3.启动mysql服务
输入命令启动mysql服务:
net start mysql |
看到,就是启动成功了
4.登陆并修改密码
在bin目录下输入:mysql -uroot -p
输入刚刚记下的密码,如下就登陆成功了。
下面需要做的是修改密码,根据参考博客,首先需要把密码的认证插件改掉。因为之前,MySQL的密码认证插件是“mysql_native_password”,而现在使用的是“caching_sha2_password”。
这里更改密码的语句就是
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'new password'; |
new password 处改成你的新密码
好了,到这里就基本完成了。