2017-08-06 10 views
1

hello私はサーバエクスプレスjsの切断を処理しようとしていますが、私はこのハンドル切断コードを使用していて、localhostのユーザに対してエラーアクセスを拒否します。 Handle Disconnect Express JSユーザlocalhostに対してエラーアクセスが拒否されました

var connection; 

function handleDisconnect() { 
    connection = mysql.createConnection(db_config); // Recreate the connection, since 
                // the old one cannot be reused. 

    connection.connect(function(err) {    // The server is either down 
    if(err) {          // or restarting (takes a while sometimes). 
     console.log('error when connecting to db:', err); 
     setTimeout(handleDisconnect, 2000); // We introduce a delay before attempting to reconnect, 
    }          // to avoid a hot loop, and to allow our node script to 
    });          // process asynchronous requests in the meantime. 
              // If you're also serving http, display a 503 error. 
    connection.on('error', function(err) { 
    console.log('db error', err); 
    if(err.code === 'PROTOCOL_CONNECTION_LOST') { // Connection to the MySQL server is usually 
     handleDisconnect();       // lost due to either server restart, or a 
    } else {          // connnection idle timeout (the wait_timeout 
     throw err;         // server variable configures this) 
    } 
    }); 
} 

handleDisconnect(); 

と私の接​​続ホスト

var mysql = require('mysql'); 
var db_config = module.exports = { 

    'connection': { 
     'host': 'localhost', 
     'user': 'root', 
     'password': '' 
    }, 
    'database': 'database' 
}; 

、それがユーザーのローカルホスト用のアクセス拒否のようなエラーを投げているにも私のサーバー上でhappends。

エラーこの

Error: ER_DBACCESS_DENIED_ERROR: Access denied for user ''@'localhost' to database 'databases' 

答えて

1

エラーメッセージが許可されていないローカルホスト(AT)空のユーザを語っているように示しています。 コード行でdb_config.connection

connection = mysql.createConnection(db_config.connection); 
+0

にありがとうをdb_configを置き換えますDB_CONFIGに私をリードし !できます !! –

関連する問題