# 数据库

## Oracle

### 记录oracle sql plus 执行时所有的输入输出：

```sql
spool d:\xx.txt
SQL statement
spool off (关闭)
```

## MySQL

### MySQL err 150

* 十个可能引起mysql 外键错误的原因：

> <http://verysimple.com/2006/10/22/mysql-error-number-1005-cant-create-table-mydbsql-328_45frm-errno-150/>

* MySql默认charset是瑞典的，应该这样修改：

  ```sql
  ALTER DATABASE db_name DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;
  ALTER TABLE db_table CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci;
  ```

## MongoDB

* [教程](http://www.runoob.com/mongodb/mongodb-connections.html)
* 常用命令

```
# 启动mongodb后端
mongod
# 连接mongodb
mongo
mongodb://user:psw@ip[:port]/dbname
# 查看与切换数据库（不存在会创建），展示所有的文档
show dbs
use reid
db.getCollectionNames()
# 查询文档（传统意义的表）
db.col_name.find()
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://blog.cweihang.io/backend/db.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
