欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

MySQL Community Server 5.7.22 安装

程序员文章站 2024-03-21 18:28:34
...

本文档为MySQL Community Server 配置过程步骤指南,包括在安装过程中出现的问题及解决方案

资源获取

官方下载路径

安装步骤

1.选择与操作系统适配的版本,将安装包mysql-5.7.22-winx64.zip下载,完成后解压到任意目录下,在本机上是解压至:D:\Mysql ,目录结构如下
MySQL Community Server 5.7.22 安装
2.在根目录下(和bin目录相同级别)新建my.txt文件,把如下代码复制进去,并修改文件后缀为ini类型,即my.ini。【注意】basedir及datadir字段需根据安装目录需要修改。

[mysql]
# 设置mysql客户端默认字符集
default-character-set=utf8 
[mysqld]
#设置3306端口
port = 3306 
# 设置mysql的安装目录
basedir=D:\Mysql
# 设置mysql数据库的数据的存放目录
datadir=D:\Mysql\data
# 允许最大连接数
max_connections=200
# 服务端使用的字符集默认为8比特编码的latin1字符集
character-set-server=utf8
# 创建新表时将使用的默认存储引擎
default-storage-engine=INNODB
# 开启查询缓存
explicit_defaults_for_timestamp=true
# 无需密码登录mysql
skip-grant-tables

3.配置环境变量
新建系统变量
变量名:MYSQL
变量值:D:\Mysql
MySQL Community Server 5.7.22 安装
编辑Path变量
添加变量值:%MYSQL%\bin

4.注册windows系统服务,以管理员身份运行cmd,进入D:\Mysql\bin 目录,输入以下命令

D:\Mysql\bin>mysqld --install
D:\Mysql\bin>mysqld --initialize

5.Win+R启动运行服务,进入services.msc, 启动MySQL服务
MySQL Community Server 5.7.22 安装
6.设置登录密码 进入mysql,未设置时,密码为回车键

D:\Mysql\bin>mysql -u root -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.22 MySQL Community Server (GPL)

Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

设置密码为password

mysql> update mysql.user set authentication_string=password('password') where user='root';
Query OK, 1 row affected, 1 warning (0.00 sec)
Rows matched: 1  Changed: 1  Warnings: 1
mysql> flush privileges;
mysql> exit
Bye

7.修改成功后,删除my.ini中的skip-grant-tables,再次重启MySQL服务

参考资料

https://www.cnblogs.com/cxc2012/p/8387839.html
https://blog.csdn.net/u012689588/article/details/14127621
http://www.jb51.net/article/125910.htm