gpt4 book ai didi

strapi - 在Stradi中连接到MySql DB

转载 作者:行者123 更新时间:2023-12-03 13:54:56 25 4
gpt4 key购买 nike

我似乎无法理解http://strapi.io/documentation/configuration#databases中的文档

如何连接到MySqlDB?我在哪里可以在database.json中设置所有数据库设置,例如用户:root,pwd:secret123,主机:192.1.2.2.123等?

最佳答案

MySQL adapter for the Sails framework and Waterline ORM. Allows you to use MySQL via your models to store and retrieve data. Also provides a query() method for a direct interface to execute raw SQL commands.



从NPM安装。

在您的应用中:
$ npm install sails-mysql

帆配置

将mysql配置添加到config/connections.js文件。基本选项:
module.exports.connections = {
mysql: {
module : 'sails-mysql',
host : 'localhost',
port : 3306,
user : 'username',
password : 'password',
database : 'MySQL Database Name'

// OR (explicit sets take precedence)
module : 'sails-mysql',
url : 'mysql2://USER:PASSWORD@HOST:PORT/DATABASENAME'

// Optional
charset : 'utf8',
collation : 'utf8_swedish_ci'
}
};

然后将默认模型配置更改为config/models.js:
module.exports.models = {
connection: 'mysql'
};

运行测试

您可以设置环境变量以覆盖测试的默认数据库配置,例如:
$ WATERLINE_ADAPTER_TESTS_PASSWORD=yourpass npm test
Default settings are:

{
host: process.env.WATERLINE_ADAPTER_TESTS_HOST || 'localhost',
port: process.env.WATERLINE_ADAPTER_TESTS_PORT || 3306,
user: process.env.WATERLINE_ADAPTER_TESTS_USER || 'root',
password: process.env.WATERLINE_ADAPTER_TESTS_PASSWORD || '',
database: process.env.WATERLINE_ADAPTER_TESTS_DATABASE || 'sails_mysql',
pool: true,
connectionLimit: 10,
waitForConnections: true
}

引用: https://www.npmjs.com/package/sails-mysql

关于strapi - 在Stradi中连接到MySql DB,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45719510/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com