欢迎访问mehome的博客

Tomorrow is another day.
Fork me on GitHub

MySQL Windows安装配置

一、简介

系统:Windows10

MySQL:mysql-5.6.24-win32.zip(https://cdn.mysql.com/archives/mysql-5.6/mysql-5.6.24-win32.zip

https://downloads.mysql.com/archives/community/

二、安装配置启动

安装步骤:

  1. 下载压缩包;在安装目录解压。

配置步骤:

  1. 环境变量:右键此电脑,属性,高级,系统环境变量,path,添加解压目录的bin目录。例如:D:\install\mysql-5.6.24-win32\bin
  2. MySQL配置文件:配置文件my-default.ini,复制一份重命名为:my.ini。my.ini配置如下:
  1 [mysqld]
  2 # 设置3306端口
  3 port=3306
  4 # 设置mysql的安装目录
  5 basedir=D:\install\mysql-5.6.24-win32
  6 # 设置mysql数据库的数据的存放目录
  7 datadir=D:\install\mysql-5.6.24-win32\Data
  8 # 允许最大连接数
  9 max_connections=200
 10 # 允许连接失败的次数。这是为了防止有人从该主机试图攻击数据库系统
 11 max_connect_errors=10
 12 # 服务端使用的字符集默认为UTF8
 13 character-set-server=utf8
 14 # 创建新表时将使用的默认存储引擎
 15 default-storage-engine=INNODB
 16 # 默认使用“mysql_native_password”插件认证
 17 default_authentication_plugin=mysql_native_password
 18 # 防止group by带来的一系列问题
 19 sql_mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION
 20 [mysql]
 21 # 设置mysql客户端默认字符集
 22 default-character-set=utf8
 23 [client]
 24 # 设置mysql客户端连接服务端时默认使用的端口
 25 port=3306
 26 default-character-set=utf8

数据初始化启动(cmd右键管理员运行)

  1. 数据初始化:mysqld –initialize
  2. 注册到注册表添加MySQL服务:mysqld –install
  3. MySQL启动:net start mysql
  4. MySql服务停止:net stop mysql
  5. MySql服务删除:mysqld -remove mysql


执行历史记录

  1 C:\Windows\system32>d:
  2 
  3 D:\>cd D:\install\mysql-5.6.24-win32\bin
  4 
  5 D:\install\mysql-5.6.24-win32\bin>mysqld --initialize
  6 2022-06-04 23:10:55 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
  7 2022-06-04 23:10:55 0 [Warning] 'ERROR_FOR_DIVISION_BY_ZERO' is deprecated and will be removed in a future release.
  8 2022-06-04 23:10:55 0 [Warning] 'NO_ZERO_DATE' is deprecated and will be removed in a future release.
  9 2022-06-04 23:10:55 0 [Warning] 'NO_ZERO_IN_DATE' is deprecated and will be removed in a future release.
 10 2022-06-04 23:10:55 0 [Note] mysqld (mysqld 5.6.24) starting as process 6660 ...
 11 
 12 D:\install\mysql-5.6.24-win32\bin>mysqld --install
 13 Service successfully installed.
 14 
 15 D:\install\mysql-5.6.24-win32\bin>net start mysql
 16 MySQL 服务正在启动 .
 17 MySQL 服务已经启动成功。
 18 
 19 
 20 D:\install\mysql-5.6.24-win32\bin>
 21 D:\install\mysql-5.6.24-win32\bin>mysql -uroot -p
 22 Enter password:
 23 Welcome to the MySQL monitor.  Commands end with ; or \g.
 24 Your MySQL connection id is 1
 25 Server version: 5.6.24 MySQL Community Server (GPL)
 26 
 27 Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved.
 28 
 29 Oracle is a registered trademark of Oracle Corporation and/or its
 30 affiliates. Other names may be trademarks of their respective
 31 owners.
 32 
 33 Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
 34 
 35 mysql> exit
 36 Bye


MySQL密码设置:

  1 #mysq 5.7之前版本
  2 mysql> UPDATE user SET password=PASSWORD(“new password”) WHERE user='username';
  3 
  4 #mysql 5.7及之后版本:
  5 mysql> UPDATE user SET authentication_string=PASSWORD(“new_password”) WHERE user='root';
  6 
  7 //刷新系统权限表
  8 mysql> FLUSH PRIVILEGES;
  9 

MySQL删除用户名为空的用户:

  1 delete from mysql.user where user='';

MySQL允许远程登陆:

  1 GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'youpassword' WITH GRANT OPTION;

三、重置密码

  1. 管理员启动cmd(确定MySQL添加path并且注册注册表)
  2. 关闭mysql:net stop mysql
  3. 输入:mysqld --shared-memory --skip-grant-tables
  4. 直接进入MySQL登陆:mysql
  5. 输入:FLUSH PRIVILEGES;
  6. 更改密码:update mysql.user set password=password("123456") where user="root";
  7. 输入:FLUSH PRIVILEGES;
  8. 启动MySQL:net start mysql
  9. mysql -u root -p


四、相关参考

posted @ 2022-06-05 00:02  mehome  阅读(242)  评论(0编辑  收藏  举报