V
V
Viktor Familyevich2018-04-24 16:18:07
MySQL
Viktor Familyevich, 2018-04-24 16:18:07

How to connect to mysql database via Google Script?

Greetings. On a virtual hosting (beget) there is a database to which I try to connect, but it does not come out, I write an error: Failed to connect to the database. Check the connection string and username and password. (line 9, database file)

function myFunction() {
  const dbPassword = 'password';
  const dbName = 'name';
  const dbLogin = 'login';
  const dbAdress = 'account.beget.tech';
  
  var instanceUrl = 'jdbc:mysql://' + dbAdress;
  var dbUrl = instanceUrl + '/' + dbName;
  var conn = Jdbc.getConnection(instanceUrl, dbLogin, dbPassword);
}

Plz tell me how to connect? I'm guessing it's the getConnection method.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
C
Codebaker, 2018-04-24
@Wintego

1) Throw a ticket to your hoster with a question: are remote connections allowed with your database
2) GRANT ALL PRIVILEGES ON dbName .* TO ' login '@'%' IDENTIFIED BY ' password ' WITH GRANT OPTION;
FLUSH PRIVILEGES;

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question