麦思实验室 - 数据库
type: channel
link: https://blog.wiseidc.com/category/database/
items: MySQL从入门到应用
items: MongoDB入门操作指南
items: Postgres入门操作指南

MySQL从入门到应用
type: item
date: 2026-07-28T04:03:00+00:00
description: 安装Windowsmysql 5.7.40创建my.ini[mysql] default_character_set=utf8mb4 [mysqld] port=3306 basedir=D:/usr/local/mysql/ datadir=D:/usr/local/mysql/data max_connections=200 character_set_server=utf8mb4 default_storage_engine=INNODB lower_case_table_names=1 default_time_zone='+8:00'初始化数据库D:\>cd D:\usr\local\mysql\bin D:\usr\local\mysql\bin>mysqld --initialize --user=mysql --console --explicit_defaults_for_timestamp 2025-06-20T13:25:08.995251Z 0 [Warning] InnoDB: New log files created, LSN=45790 2025-06-20T13:25:09.081107Z 0 [Warning] InnoDB: Creating foreign key constraint system tables. 2025-06-20T13:25:09.175719Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: fcb9b279-4dd9-11f0-bcff-3c970e3c7ec6. 2025-06-20T13:25:09.197778Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened. 2025-06-20T13:25:10.723739Z 0 [Warning] A deprecated TLS version TLSv1 is enabled. Please use TLSv1.2 or higher. 2025-06-20T13:25:10.727148Z 0 [Warning] A deprecated TLS version TLSv1.1 is enabled. Please use TLSv1.2 or higher. 2025-06-20T13:25:10.730535Z 0 [Warning] CA certificate ca.pem is self signed. 2025-06-20T13:25:10.937104Z 1 [Note] A temporary password is generated for root@localhost: if<d/xGoY6#?if<d/xGoY6#?为自动生成的root密码。注册服务D:\usr\local\mysql\bin>mysqld --install MySQL --defaults-file="D:\usr\local\mysql\my.ini" Service successfully installed.启动服务D:\usr\local\mysql\bin>net start mysql删除服务D:\usr\local\mysql\bin>net stop mysql D:\usr\local\mysql\bin>mysqld --remove MySQLmysql 8.0创建my.ini[mysql] default_character_set=utf8mb4 [mysqld] port=3306 basedir=D:/usr/local/mysql/ datadir=D:/usr/local/mysql/data max_connections=200 character_set_server=utf8mb4 default_storage_engine=INNODB lower_case_table_names=1 default_time_zone='+8:00' server_id=1 log_bin=D:/usr/local/mysql/log/bin log_bin_index=D:/usr/local/mysql/log/bin.index expire_logs_days=7 binlog_format=ROW…

MongoDB入门操作指南
type: item
date: 2026-07-23T13:58:00+00:00
description: MongoDB是一个基于分布式文件存储的数据库，由C++编写，旨在为WEB应用提供可扩展的高性能数据存储解决方案。MongoDB将数据存储为一个文档，数据结构由键值对组成，MongoDB文档类似于JSON对象，字段值可以包含其他文档，数组及文档数组。MongoDB服务端可运行在Linux、Windows或macOS X平台，支持32位和64位应用，默认端口为27017。安装Windows进入MongoDB官网下载预编译二进制包（下载地址：https://www.mongodb.com/download-center/community），打开之后选择Version后，点击Download下载即可。msi安装向导点击下载好的mongodb-windows-x86_64-6.0.5-signed.msi，安装类型需要选择Custom；修改安装目录为：D:\usr\local\mongodb；服务配置保持默认值；需要将Install MongoDB Compass的勾去掉，否则安装过程中会下载Install MongoDB Compass并安装，比较耗费时间。Install MongoDB Compass是一个图形界面管理工具，可以使用其他GUI管理工具，如：Navicat for MongoDB。之后一直Next直到安装完成。安装完成后，浏览器访问：http://localhost:27017/，如果显示：It looks like you are trying to access MongoDB over HTTP on the native driver port.说明MongoDB已经安装成功了。zip手动安装下载地址：https://fastdl.mongodb.org/windows/mongodb-windows-x86_64-6.0.10.zip解压mongodb-windows-x86_64-6.0.10.zip文件到：D:\usr\local\mongodb；切换到D:\usr\local\mongodb目录，创建data和log目录，分别用于存储数据库和日志文件；切换到D:\usr\local\mongodb目录，创建配置文件mongod.cfg，内容参考：storage: dbPath: D:\usr\local\mongodb\data systemLog: destination: file logAppend: true path: D:\usr\local\mongodb\log\mongod.log net: port: 27017 bindIp: 127.0.0.1注册MongoDB服务C:\Users\Administrator> D:\usr\local\mongodb\bin\mongod --config "D:\usr\local\mongodb\mongod.cfg" --install --serviceName "MongoDB"启动MongoDB服务C:\Users\Administrator> net start mongodb卸载MongoDB服务C:\Users\Administrator> D:\usr\local\mongodb\bin\mongod --removeLinux5.0.9[root@ecs src]# wget https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-rhel70-5.0.9.tgz [root@ecs src]# tar -zxvf mongodb-linux-x86_64-rhel70-5.0.9.tgz -C /usr/local [root@ecs src]# mv /usr/local/mongodb-linux-x86_64-rhel70-5.0.9 /usr/local/mongodb [root@ecs src]# mkdir /usr/local/mongodb/{data,log} [root@ecs src]# cat > /etc/mongodb.cnf <<EOF dbpath=/usr/local/mongodb/data logpath=/usr/local/mongodb/log/mongodb.log port=27017 fork=true journal=false bind_ip=0.0.0.0 auth=true EOF [root@ecs src]# echo "export PATH=\$PATH:/usr/local/mongodb/bin/" >> /etc/profile [root@ecs src]# source /etc/prof…

Postgres入门操作指南
type: item
date: 2026-06-30T12:31:00+00:00
description: 安装PostgresDocker部署拉取镜像[root@ecs ~]# docker pull registry.cn-shanghai.aliyuncs.com/maisi/postgres:16.13-alpine [root@ecs ~]# docker tag registry.cn-shanghai.aliyuncs.com/maisi/postgres:16.13-alpine postgres:16.13-alpine [root@ecs ~]# docker rmi registry.cn-shanghai.aliyuncs.com/maisi/postgres:16.13-alpine创建容器[root@ecs ~]# docker run --name postgres \ --privileged=true \ -e POSTGRES_PASSWORD=wfb88Os2xBk0sUQH \ -p 5432:5432 \ -v /data/postgresql:/var/lib/postgresql/data \ -d postgres:16.13-alpinePSQL操作登录Postgres[root@ecs ~]# docker exec -it postgres /bin/bash dc4d208b728b:/# psql -U postgres; psql (16.13) Type "help" for help. postgres=# 常见指令说明：命令说明\l,\l+列出所有数据库\du列出所有用户\c [db-name]切换数据库\d列出数据库内所有内容，包含table、sequence等\dt列出数据库内所有表\d [table-name]查看表结构\q退出登录创建用户postgres=# create user maisi with password 'Ri71kHISuS9mDVBF'; CREATE ROLE或者：postgres=# create role maisi password 'Ri71kHISuS9mDVBF' login;CREATE USER is now an alias for CREATE ROLE. The only difference is that when the command is spelled CREATE USER, LOGIN is assumed by default, whereas NOLOGIN is assumed when the command is spelled CREATE ROLE.create user默认有login权限，而create role默认没有login权限，需要单独指定。删除用户postgres=# drop user maisi;创建数据库postgres=# create database maisi_db with owner maisi; CREATE DATABASE授权数据库postgres=# grant all on database maisi_db to maisi; GRANT这是数据库级别的授权，权限包括：CONNECT（允许连接数据库）、CREATE（允许在数据库创建schema）和TEMPORARY（允许在数据库创建临时表），不会授予任何表的权限，即只能连上数据库，看不到、也操作不了数据库里面的任何表。授权表postgres=# \c maisi_db; You are now connected to database "maisi_db" as user "postgres". maisi_db=# grant select,insert,update,delete on all tables in schema public to maisi; GRANT这是表级别的授权，作用对象是public schema下的已存在的所有表。权限包括：SELECT、INSERT、UPDATE和DELETE，不包含TRUNCATE、REFERENCES、TRIGGER等权限。注：只对当前已存在的表生效，新建的表不会自动获得授权。自动授权新建表默认情况下，maisi用户新创建的表，maisi自动拥有所有权限，但如果是其他用户创建的表，maisi用户就没有操作权限了。可以通过alter default privileges将其他用户新创建的表自动授权给maisi用户。postgres=# \c maisi_db; maisi_db=# alter default privileges in schema public grant select,insert,update,delete on…