macOS 和 Windows 操作系统下如何安装和启动 MySQL / Redis 数据库

你好,我是 Kagol,个人公众号:前端开源星球。

TinyPro 后台管理系统的 NestJS 后端依赖 MySQL 和 Redis 数据库,本文主要带大家安装和启动 MySQL 和 Redis 数据库。

macOS

如果你使用的是 macOS 操作系统,安装 MySQL 和 Redis 数据库将变得非常简单,只需要一行命令即可。

MySQL

安装 MySQL:

bash 复制代码
$ brew install mysql

查看是否安装成功:

bash 复制代码
$ mysql --version
mysql  Ver 9.2.0 for macos13.7 on x86_64 (Homebrew)

启动 MySQL:

bash 复制代码
$ brew services start mysql
==> Successfully started `mysql` (label: homebrew.mxcl.mysql)

连接 MySQL 数据库:

bash 复制代码
$ mysql -u root -p

退出 MySQL 终端:

bash 复制代码
mysql> exit
Bye

停止数据库:

bash 复制代码
$ brew services stop mysql
Stopping `mysql`... (might take a while)
==> Successfully stopped `mysql` (label: homebrew.mxcl.mysql)

Redis

得益于 macOS 的 Homebrew 软件包管理器,Redis 数据库的安装和启动和 MySQL 一样简单。

安装 Redis:

bash 复制代码
$ brew install redis

查看 Redis 是否安装成功:

bash 复制代码
$ redis-cli --version
redis-cli 7.2.7

启动 Redis:

bash 复制代码
$ brew services start redis
==> Successfully started `redis` (label: homebrew.mxcl.redis)

验证是否启动成功:

bash 复制代码
$ redis-cli
127.0.0.1:6379> ping
PONG
127.0.0.1:6379>

退出 Redis 终端:

ruby 复制代码
127.0.0.1:6379> exit

停止 Redis:

bash 复制代码
$ brew services stop redis
Stopping `redis`... (might take a while)
==> Successfully stopped `redis` (label: homebrew.mxcl.redis)

Windows

如果你使用的是 Windows 操作系统,你需要先下载 MySQL 和 Redis 对应的软件包。

MySQL

下载软件包:downloads.mysql.com/archives/in...

点击文件:mysql-installer-community-8.0.40.0.msi 进行安装。

安装完成之后,在终端中执行以下命令连接数据库。

bash 复制代码
$ mysql -u root -p

Redis

下载软件包:github.com/redis-windo...

将文件:Redis-7.4.2-Windows-x64-cygwin.zip 进行解压。

点击文件:redis-server.exe 即可启动 Redis,不需要安装。

往期文章

联系我们

GitHub:github.com/opentiny/ti...(欢迎 Star ⭐)

官网:opentiny.design/vue-pro

个人博客:kagol.github.io/blogs

小助手微信:opentiny-official

公众号:OpenTiny

附录:MySQL 数据库基本操作

显示所有数据库:

bash 复制代码
mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| demo_tiny_pro      |
| information_schema |
| mysql              |
| order_sys          |
| performance_schema |
| sys                |
+--------------------+
6 rows in set (0.09 sec)

创建数据库:

bash 复制代码
mysql> create database order_sys;
Query OK, 1 row affected (0.01 sec)

删除数据库:

bash 复制代码
mysql> drop database order_sys;
Query OK, 0 rows affected (0.01 sec)

使用数据库:

bash 复制代码
mysql> use order_sys;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed

显示当前数据库下的所有数据表:

bash 复制代码
mysql> show tables;
+---------------------+
| Tables_in_order_sys |
+---------------------+
| lang                |
| menu                |
| order               |
| permission          |
| role                |
| role_menu           |
| role_permission     |
| user                |
| user_role           |
+---------------------+
9 rows in set (0.00 sec)

从数据表中查询数据:

bash 复制代码
mysql> select id,name from menu;
+----+---------------+
| id | name          |
+----+---------------+
|  1 | Board         |
|  2 | Home          |
|  3 | Work          |
|  4 | List          |
|  5 | Table         |
|  6 | Form          |
|  7 | Base          |
|  8 | Step          |
|  9 | Profile       |
| 10 | Detail        |
+----+---------------+
10 rows in set (0.00 sec)
相关推荐
子兮曰5 天前
jev-ultrafast 深度解析:7 秒订机票的浏览器 Agent 是如何炼成的
前端·后端·agent
子兮曰5 天前
Jev 爆发一周:7 秒 Agent 背后的 System One 生态与三场争议
前端·后端·ai编程
爱勇宝5 天前
ZCode 开源 24 小时:一份没有历史的账本,回答不了"有没有偷代码"
前端·后端·chatglm (智谱)
胡写代码5 天前
别再前后端各写一套表单校验了
java·后端
小白男神5 天前
MySQL进阶学习四(存储过程、游标、触发器)
mysql
大勇前进5 天前
原生 PHP 还是 Laravel?小项目到底要不要上框架
后端
这个DBA有点耶5 天前
MVCC深入:Read View、版本链与快照读——InnoDB并发控制的内核
数据库·mysql·架构
yuzhi_liu5 天前
我用 LangGraph4j 实现 Multi-Agent Supervisor
后端
alsmile5 天前
Node-RED 之外,国产规则引擎的新方案:基于标准语法,Go 先行实现
后端·开源·go
大白805 天前
PHP 内存溢出排查思路:看懂报错日志,精准定位问题
后端