Windows10安装MySQL

下载社区版的MySQL,

      最新版本下载地址:https://dev.mysql.com/downloads/mysql/

      历史版本下载地址:https://downloads.mysql.com/archives/community/

      我下载的是 8.0.30 版本,下载压缩包

      下载完成的压缩包文件名:mysql-8.0.30-winx64.zip

      把压缩包解压,我的解压目录是: D:\tools\mysql-8.0.30-winx64  ,解压后的内容如下:

       在解压目录里创建一个txt文件,并把名称改为 my.ini

 my.ini 文件的常用配置


[client] #客户端设置,即客户端默认的连接参数
# 设置mysql客户端连接服务端时默认使用的端口
port=3306


#默认编码
default-character-set = utf8mb4


[mysql] #客户端设置
#MySQL 提示符配置
#用户名@主机名+mysql版本号+数据库名
prompt=\\u@\\h \\v [\\d]>\\_


# 设置mysql客户端默认字符集
default-character-set = utf8mb4


[mysqld] #服务端基本设置
# 默认连接端口
port=3306


# MySQL安装根目录的路径
basedir=D:\\tools\\mysql-8.0.30-winx64


# MySQL服务器数据目录的路径
datadir=D:\\tools\\mysql-8.0.30-winx64\\data


# 允许最大连接数
max_connections=200


# 允许连接失败的次数。这是为了防止有人从该主机试图攻击数据库系统
max_connect_errors=10


#服务端默认编码
character_set_server = utf8mb4


#在创建新表时将使用的默认存储引擎
default-storage-engine=INNODB


# 配置时区
default-time_zone='+8:00'

 

 

1、以管理员身份运行命令提示符,下转到mysql的bin目录下

      执行安装命令:mysqld --install "MySQL" --defaults-file="D:\tools\mysql-8.0.30-winx64\my.ini"     

      MySQL的路径要填写正确,返回 Service successfully installed. 表示安装成功。  

D:\tools\mysql-8.0.30-winx64\bin>mysqld --install "MySQL" --defaults-file="D:\tools\mysql-8.0.30-winx64\my.ini"
Service successfully installed.

      执行初始化命令:mysqld --initialize --console

      初始化成功后,会生成一个数据库的随机初始密码:RivY<pS?R1C2  每次安装的初始密码都会不同,需要记住,如果忘记可删除安装目录的 data 文件夹重新初始化。

D:\tools\mysql-8.0.30-winx64\bin>mysqld --initialize --console
2025-04-02T06:41:09.609904Z 0 [System] [MY-013169] [Server] D:\tools\mysql-8.0.30-winx64\bin\mysqld.exe (mysqld 8.0.30) initializing of server in progress as process 19924
2025-04-02T06:41:09.639172Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2025-04-02T06:41:10.073610Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
2025-04-02T06:41:11.073444Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: RivY<pS?R1C2

 

      登录MySQL命令:mysql -uroot -p

      当输入正确的密码后,就会进入MySQL的内部命令行。

D:\tools\mysql-8.0.30-winx64\bin>mysql -uroot -p
Enter password: ************
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 8.0.30

Copyright (c) 2000, 2022, Oracle and/or its affiliates.

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.

root@localhost 8.0.30 [(none)]>

 

      把登录密码改为123456:ALTER USER 'root'@'localhost' IDENTIFIED BY '123456';

root@localhost 8.0.30 [(none)]> ALTER USER 'root'@'localhost' IDENTIFIED BY '123456';
Query OK, 0 rows affected (0.01 sec)

      查看 my.ini 配置文件是否生效:\s

root@localhost 8.0.30 [(none)]> \s
--------------
mysql  Ver 8.0.30 for Win64 on x86_64 (MySQL Community Server - GPL)

Connection id:          8
Current database:
Current user:           root@localhost
SSL:                    Cipher in use is TLS_AES_256_GCM_SHA384
Using delimiter:        ;
Server version:         8.0.30
Protocol version:       10
Connection:             localhost via TCP/IP
Server characterset:    utf8mb4
Db     characterset:    utf8mb4
Client characterset:    utf8mb4
Conn.  characterset:    utf8mb4
TCP port:               3306
Binary data as:         Hexadecimal
Uptime:                 3 min 57 sec

Threads: 2  Questions: 8  Slow queries: 0  Opens: 130  Flush tables: 3  Open tables: 46  Queries per second avg: 0.033
--------------

      退出MySQL命令行:\q

root@localhost 8.0.30 [(none)]> \q
Bye

 

      一行命令登录MySQL:mysql -uroot -hlocalhost -p123456

     mysql:安装的系统服务(不区分大小写)

     -u:user的简写,后跟用户名

     -h:host的简写,后跟主机名

     -p:password的简写,后跟密码

 

     MySQL启动命令:net start mysql

     MySQL关闭命令:net stop mysql

     查看是否安装MySQL:sc query mysql

     删除MySQL服务:sc delete mysql

     查询MySQL版本:mysql --version

参考文档:https://blog.csdn.net/2401_84578953/article/details/146337799

 
posted @ 2025-04-02 15:01  闲人鹤  阅读(84)  评论(0)    收藏  举报