mysql我目前正在尝试使用 Node.Js或NPM 依赖项连接到互联网上的 MySQL 服务器,mysql2以使用查询和其他相关内容。
代码很简单...
//i import my dependency
const mysql = require('mysql2') //either 'mysql' or 'mysql2'
//i create my pool to create connections as needed
var conn = mysql.createPool({
host: 'some_database_i_have_access_to.mysql.uhserver.com',
user: 'valid_user',
password: 'valid_password',
database: 'some_existing_database'
})
//i try to connect (this is the part where it fails)
conn.getConnection((err,conn) => {
if (err) throw err //<- the error is thrown here
//i do query stuff
conn.query("SELECT * FROM atable",(err,res,firlds) => {
if(err) throw err …Run Code Online (Sandbox Code Playgroud) 我正在尝试通过私钥和管理员权限使用管理员权限访问 Firestore,以便我可以将其用于后端的查询和内容。
//i import fb-admin
const firebaseAdmin = require('firebase-admin')
//i initialize as admin with a valid credential
firebaseAdmin.initializeApp({
credential: firebaseAdmin.credential.cert('./pathto/myprivatekeyinfo.json')
})
//i initialize firestore
var dba = firebaseAdmin.firestore()
//i test the connection by listing all the available collections
dba.getCollections().then(collectionList => {
collectionList.forEach(collection => {
console.log(collection.id) //print available collections
}
},error => console.error(JSON.stringify(error,null," "))) //print error
Run Code Online (Sandbox Code Playgroud)
它看起来与文档中的说明完全一样,但我的问题是,对于我尝试在其中执行 Node 的某些计算机,我只能在少数计算机上随机连接。
有时我连接并且一切顺利,按应有的方式打印可用的集合,但大多数时候我得到的只是无效凭据的错误
{
"code": 16,
"metadata": {
"_internal_repr": {
"www-authenticate": [
"Bearer realm=\"https://accounts.google.com/\""
]
}
},
"details": "Request had invalid authentication credentials. Expected …Run Code Online (Sandbox Code Playgroud) javascript node.js firebase firebase-admin google-cloud-firestore