
# 创建M-Compatibility数据库及用户
创建M-Compatibility数据库需要在非M-Compatibility数据库下进行，需要确保当前环境中已有templatem模板数据库。
```
gaussdb=# \l
                              List of databases
   Name    | Owner | Encoding |   Collate   |    Ctype    | Access privileges 
-----------+-------+----------+-------------+-------------+-------------------
 postgres  | omm   | UTF8     | en_US.UTF-8 | en_US.UTF-8 | 
 template0 | omm   | UTF8     | en_US.UTF-8 | en_US.UTF-8 | =c/omm           +
           |       |          |             |             | omm=CTc/omm
 template1 | omm   | UTF8     | en_US.UTF-8 | en_US.UTF-8 | =c/omm           +
           |       |          |             |             | omm=CTc/omm
 templatem | omm   | UTF8     | en_US.UTF-8 | en_US.UTF-8 | =c/omm           +
           |       |          |             |             | omm=CTc/omm
 (4 rows)
```
注意：从505.2.0之前的版本升级到最新版本，基础包中如果templatem模板库未创建，升级之后templatem模板库也不会创建。使用M-Compatibility数据库，需要先通过以下示例创建数据库。
```
gaussdb=# CREATE DATABASE m_db dbcompatibility = 'M' template=templatem;
gaussdb=# \c m_db
Non-SSL connection (SSL connection is recommended when requiring high-security)
You are now connected to database "m_db" as user "omm".
m_db=# CREATE USER omm_test password '********';
m_db=# GRANT ALL privileges to omm_test;
```
创建M-Compatibility数据库后，其他操作请参见[SQL参考](https://support.huaweicloud.com/distributed-m-comp-devg-v8-gaussdb/gaussdb-81-0029.html#ZH-CN_TOPIC_0000002527805440)。
![](https://support.huaweicloud.com/distributed-m-comp-devg-v8-gaussdb/public_sys-resources/notice_3.0-zh-cn.png)
一个GaussDB集群只允许同时存在一个M-Compatibility模式数据库。
