所以我一直在使用本地 mysql 工作台开发一个 Web 应用程序。我最近将数据库移至 Azure Database for MySQL。在我离开当地之前,一切正常。我所有的网页都可以正常工作,现在 4 个页面中只有 2 个可以工作,当我点击损坏的页面时,我遇到了下面的错误。下面是我连接到数据库的方式,我不确定第二个连接是否正常。
我需要做这样的事情吗?
https://docs.microsoft.com/en-us/azure/mysql/howto-configure-ssl
感谢您的任何帮助!
var connection = mysql.createConnection({
host: 'host',
user: 'user',
password: "password",
database: 'schema_1',
ssl: true
});
var connection = mysql.createConnection({
host: 'host',
user: 'user',
password: "password",
database: 'schema_2',
ssl: true
});
在这里编辑------------
table_routes.js
var express = require('express')
, http = require('http')
, mysql = require('mysql'); // <---- HERE
var app = express();
const fs = require('fs');
const path = require('path');
app.use(function(req, res, next) {
res.header("Access-Control-Allow-Origin", "http://127.0.0.1:3000");
res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
next();
});
var connection = mysql.createConnection({
host: 'host',
user: 'root',
password: "password",
database: 'db1',
ssl: {
ca: fs.readFileSync(path.resolve(__dirname, 'BaltimoreCyberTrustRoot.crt.pem'))
}
});
connection.connect(); // <---- AND HERE
// all environments
app.set('port', process.env.PORT || 7003);
table_routes2.js
var express = require('express')
, http = require('http')
, mysql = require('mysql'); // <---- HERE
var app = express();
const fs = require('fs');
const path = require('path');
app.use(function(req, res, next) {
res.header("Access-Control-Allow-Origin", "http://127.0.0.1:3000");
res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
next();
});
var connection = mysql.createConnection({
host: 'host',
user: 'user',
password: "password",
database: 'db2',
ssl: {
ca: fs.readFileSync(path.resolve(__dirname, 'BaltimoreCyberTrustRoot.crt.pem'))
}
});
connection.connect(); // <---- AND HERE
// all environments
app.set('port', process.env.PORT || 7004);