How to connect to database with SSL in google apps script?

前端 未结 1 1930
感动是毒
感动是毒 2020-12-18 22:19

I\'m trying to connect to a database via SSL within Google Apps Script, referencing these docs. The error is:

Execution failed: Failed to establish a databas         


        
相关标签:
1条回答
  • 2020-12-18 22:58

    I can confirm that I can connect to a MySQL database with SSL within Google Apps Script.

    It's important to note useSSL=true is indeed necessary

    I was able to get it working by following the example at https://issuetracker.google.com/issues/36761592#comment18 (relevant snippet repeated below):

    var conn = Jdbc.getConnection('jdbc:mysql://<ip address>/<db name>?useSSL=true', { 
      user: '<user>', 
      password: '<pass>', 
      _serverSslCertificate: '-----BEGIN CERTIFICATE-----\n...\n-----END CERTIFICATE-----', 
      _clientSslCertificate: '-----BEGIN CERTIFICATE-----\n...\n-----END CERTIFICATE-----', 
      _clientSslKey: '-----BEGIN RSA PRIVATE KEY-----\n...\n-----END RSA PRIVATE KEY-----' 
    });
    

    If you're using a Google Cloud SQL instance, you may want to consider using getCloudSqlConnection(). Presumably it's encrypted as well (based on the fact that I can indeed get a connection when the corresponding instance has "Only secured connections are allowed to connect to this instance." enabled), and, importantly, doesn't require you to manage (i.e. not lose control of) the key and certs yourself.

    0 讨论(0)
提交回复
热议问题