Windows安装卸载MySQL

【官方】MySQL参考手册:介绍MySQL Server、SQL、InnoDB存储引擎、复制等。

Windows 卸载 MySQL

  1. 删除程序
    【win + x】 => p ,在安装的程序中卸载MySQL相关
  2. 删除安装目录和数据文件夹
    D:\ProgramFiles\MySQL
    C:\ProgramData\MySQL
  3. 删除服务
    • 【win + r】 => services.msc,在服务列表中查找mysql服务是否残留
    • cmd 删除服务SC DELETE mysql
  4. 删除注册表信息
    【win + r】 => regedit,打开注册表,删除如下路径信息
    • HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Services\EventLog\Application\MySQLD Service
    • HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\EventLog\Application\MySQLD Service

Windows 安装 MySQL

  1. 下载安装包

    Windows 平台下提供两种安装 MySQL 的方式:

    • MySQL 图形化安装(.msi 安装文件)见安装方式
    • 免安装版(.zip 压缩文件)

    本文使用的安装包Windows (x86, 64-bit), ZIP Archive

  2. 将安装包解压至目标安装目录

  3. 在安装目录下新建my.ini文件

    [mysqld]

    设置3306端口

    port=3306

    设置mysql的安装目录

    basedir=D:\安装路径

    设置 mysql 数据库的数据的存放目录,MySQL 8+ 不需要以下配置,系统自己生成即可,否则有可能报错

    datadir=D:\数据的存放目录

    允许最大连接数

    max_connections=200

    允许连接失败的次数。

    max_connect_errors=10

    设置mysql服务端默认字符集

    character-set-server=utf8mb4

    创建新表时将使用的默认存储引擎

    default-storage-engine=INNODB
    [mysql]

    设置mysql客户端默认字符集

    default-character-set=utf8mb4

Note

The utf8mb3 character set is deprecated and you should expect it to be removed in a future MySQL release. Please use utf8mb4 instead. utf8 is currently an alias for utf8mb3, but it is now deprecated as such, and utf8 is expected subsequently to become a reference to utf8mb4. MySQL 8.2 also displays utf8mb3 in place of utf8 in the columns of Information Schema tables, and in the output of SQL SHOW statements.

In addition, you should be aware that collations using the utf8_ prefix in older releases of MySQL have since been renamed using the prefix utf8mb3_, instead.

To avoid ambiguity about the meaning of utf8, consider specifying utf8mb4 explicitly for character set references.

  1. cmd进入bin目录下,初始化数据库

    mysqld --initialize --console

在打印信息中获取 root 用户的初始默认密码
[Server] A temporary password is generated for root@localhost: 初始密码

  1. 安装mysql命令
    mysqld install

  2. 启动命令
    net start mysql

  3. 登录MySQL,密码为初始密码
    mysql -u root -p

  4. 修改密码

    • SQL语句

      • 推荐 ALTER USER 语句
        mysql > ALTER USER 'root'@'localhost' IDENTIFIED BY '新密码';
      • 也可以使用 SET PASSWORD 语句
        mysql > SET PASSWORD FOR 'root'@'localhost' = '新密码';

      如果显示 Query OK, 0 rows affected (0.01 sec)则成功

    • 退出

      mysql > exit

    • 重新登录
      mysql -u root -p

Note

Rather than using SET PASSWORD to assign passwords, ALTER USER is the preferred statement for account alterations, including assigning passwords.

PowerShell 中使用MySQL

命令行需要加入当前路径.\,如.\mysqld install.\mysql -u root -p

否则会出现报错无法使用mysql命令

复制代码
找不到命令 mysql,但它确实存在于当前位置。默认情况下,Windows PowerShell 不会从当前位置加载命令。如果信任此命令,请改为键入".\mysql"。有关详细信息,请参阅 "get-help about_Command_Precedence"。

原因

在linux系统中,执行命令时,系统会从系统环境变量中包含的路径去寻找,如果找到就执行,没有找到会报命令未找到。

环境变量

在环境变量-系统变量-Path 中加入MySQL安装目录\bin;

为了方便调用MySQL程序,可以将MySQLbin目录的路径名添加到Windows系统PATH环境变量中。现在,您应该能够通过在系统上任何目录的 DOS 提示符下键入其名称来调用任何 MySQL 可执行程序,而无需提供路径。这包括服务器、mysql客户端和所有 MySQL 命令行实用程序,例如mysqladminmysqldump

相关推荐
zuoerjinshu31 分钟前
sql实战解析-sum()over(partition by xx order by xx)
数据库·sql
NocoBase2 小时前
【2.0 教程】第 1 章:认识 NocoBase ,5 分钟跑起来
数据库·人工智能·开源·github·无代码
Hoshino.413 小时前
基于Linux中的数据库操作——下载与安装(1)
linux·运维·数据库
Oueii4 小时前
Django全栈开发入门:构建一个博客系统
jvm·数据库·python
未来龙皇小蓝5 小时前
【MySQL-索引调优】11:Group by相关概念
数据库·mysql·性能优化
小涛不学习5 小时前
手写线程池(从0实现 ThreadPoolExecutor 核心思想)
windows
2401_831824965 小时前
使用Fabric自动化你的部署流程
jvm·数据库·python
njidf5 小时前
Python日志记录(Logging)最佳实践
jvm·数据库·python
twc8295 小时前
大模型生成 QA Pairs 提升 RAG 应用测试效率的实践
服务器·数据库·人工智能·windows·rag·大模型测试
@我漫长的孤独流浪5 小时前
Python编程核心知识点速览
开发语言·数据库·python