Featured image of post windows7环境zip方式安装mysql

windows7环境zip方式安装mysql

前言

今天临时需要在办公环境安装个数据库,简单记录下安装过程及中间问题解决方案。

mysql安装过程

下载MySql

安装包下载MySQL Community Server

解压放在D:\Program Files下

配置

创建数据目录和配置文件

D:\Program Files\mysql-5.7.41-winx64\data\

D:\Program Files\mysql-5.7.41-winx64\my.ini

[mysql]
auto-rehash
default-character-set           = utf8mb4
connect-timeout                 = 3

[mysqld]
skip-name-resolve
bind-address=0.0.0.0
port = 3306
# 设置mysql的安装目录
basedir=D:\Program Files\mysql-5.7.41-winx64
# 设置mysql数据库的数据的存放目录
datadir=D:\Program Files\mysql-5.7.41-winx64\data
# 允许最大连接数
max_connections=200
# 服务端使用的字符集默认为8比特编码的latin1字符集
character-set-server=utf8mb4
# 创建新表时将使用的默认存储引擎
default-storage-engine = INNODB  # myisam 或 INNODB  
#innodb_buffer_pool_size  = 100M

lower_case_table_names=1
max_allowed_packet=16M
sql_mode='STRICT_TRANS_TABLES,NO_ENGINE_SUBSTITUTION'

#skip-grant-tables # 放开次参数root免密码登录

启动

设置环境变量 PATH中加入$MYSQL_HOME/bin

在CMD命令下执行

 # 安装数据库
 mysqld --install
 
 # 初始化数据库
 mysqld --initialize --console # 此命令结束后会打印root默认密码
 
 # 启动数据库
 net start mysql
 
 # 停止数据库
 net stop mysql 
 
 # 登录数据库
 mysql -u root -p 
 
 # 创建数据库、建表、建用户等等....

问题处理

问题1

提示错误信息:ERROR 1130 : Host ‘127.0.0.1’ is not allowed to connect to this MySQL server

stack overflow第7条回复

I had the same message after a fresh installation with the no-install zip and solved it as follows. Perhaps this could have been a solution for your problem too:

  1. Stop the MySQL server or service.
  2. Open a Command Prompt window with administrative rights and go to the bin folder in the MySQL install directory.
  3. Start MySQL with skip-grants-table and don’t forget your config file:

mysqld –defaults-file=[filename] –skip-grant-tables

  1. Open another Command Prompt window and go to the bin folder again.

  2. Now you can login:

mysql -u root -p

  1. Show the users with:

SELECT user, host FROM mysql.user;

  1. Verify there is one ‘root’ with host ’localhost’.

  2. Change the host:

UPDATE mysql.user SET host=’%’ WHERE user=‘root’;

  1. Exit the mysql program and close the Command Prompt window.

  2. Type Ctrl-C in the other Command Prompt window to stop the server, then close the Command Prompt Window.

  3. Start MySQL as you normally would and verify that you can login.

问题2

提示错误信息:系统找不到制定的文件。

打开注册表 “我的计算机\HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\MySQL"下ImagePath配置改成"D:\Program Files\mysql-5.7.41-winx64\bin\mysqld” MySQL

CSDN-MySQL报错

问题3

忘记root用户密码

  1. 在my.ini配置文件中加入 skip-grant-tables
  2. 重新启停mysql,在用root免密码方式登录
  3. 修改密码UPDATE user SET authentication_string=password('xxxxxx') WHERE user='root';

MySql5.7重置root密码

最后

简单记录下简答安装过程,以免后续还需要用。

参考

CSDN-Windows安装MySQL 5.7(Zip)

stack overflow第7条回复

CSDN-MySQL报错

MySql5.7重置root密码

Licensed under CC BY-NC-SA 4.0
最后更新于 2024-05-02 03:38 -0400
 赣ICP备18015110号-1   
使用 Hugo 构建 主题 StackJimmy 设计