Cannot connect to local MySQL server through Script (JDBC) applications

Please see the edits below, I leave the original question to help others.

I am trying to connect to a local MySQL server through Script and JDBC applications, but I keep getting one of two errors. This code:

function connectTest() {
  var conn = Jdbc.getConnection("jdbc:mysql://localhost", "root", "xxx");
}

Gives an error Failed to establish a database connection. Check connection string, username and password.

This code:

function connectTest() {
  var conn = Jdbc.getConnection("jdbc:mysql://localhost:3306", "xxx", "pass");
}

Gives an error Invalid argument: url.

I have tried dozens of combinations and can't make it work. Attempts to log in from application scripts are not displayed in the access log for MySQL (i.e. if I try to log in locally with the wrong information, I see [Note] Access denied for user 'host'@'localhost' (using password: YES). I have granted the appropriate root authority:

mysql> show grants for 'root'@'%';
+-------------------------------------------------------------+
| Grants for root@%                                           |
+-------------------------------------------------------------+
| GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' WITH GRANT OPTION |
+-------------------------------------------------------------+
1 row in set (0.00 sec)

Do I need to do something to open a local database on the Internet / Google Apps Script?

EDIT:

MySQL (, Access denied for user 'root'@'12.123.12.123' (using password: YES)), - . bind-address IP-, MySQL , ([ERROR] Can't start server: Bind on TCP/IP port: Can't assign requested address)

function connectTest() {
  var conn = Jdbc.getConnection("jdbc:mysql://12.123.12.123:3306", "root", "xxx");
}

EDIT2: bind-address = 0.0.0.0, , . MySQL (, ensembldb.ensembl.org:3306), .

+6
1

- , :

  • my.cnf( ​​ , /usr/local/etc/:

    [mysqld]
    bind-address=0.0.0.0
    skip-host-cache
    skip-name-resolve
    
  • 3306 ( Xfinity http://10.0.0.1/ > "" a > Port Forwarding " > " ", , MySQL, " ") open port

  • MySQL FLUSH PRIVILEGES;. GRANT ALL PRIVILEGES ON *.* TO <USER>@'%' IDENTIFIED BY '<PASSWORD>', IP-, Python script IP- Google. IP- Google JDBC.

    from sqlalchemy import create_engine, MetaData
    
    conString = 'mysql+pymysql://<USER>:<PASSWORD>@localhost:3306/<DB>'
    mysql = create_engine(conString)
    
    ips = ['64.18.0.0 - 64.18.15.255',
    '64.233.160.0 - 64.233.191.255',
    '66.102.0.0 - 66.102.15.255',
    '66.249.80.0 - 66.249.95.255',
    '72.14.192.0 - 72.14.255.255',
    '74.125.0.0 - 74.125.255.255',
    '173.194.0.0 - 173.194.255.255',
    '207.126.144.0 - 207.126.159.255',
    '209.85.128.0 - 209.85.255.255',
    '216.239.32.0 - 216.239.63.255']
    
    for ip in ips:
        ip2 = ip.replace(' - ', '/')
        try:
            sql = "CREATE USER '<USER>'@'" + ip2 + "' identified by '<PASSWORD>';"
            mysql.execute(sql)
        except:
            print ip2
        sql = "GRANT ALL PRIVILEGES ON <DB>.* TO '<USER>'@'" + ip2 + "';"
        mysql.execute(sql)
    
+6

Source: https://habr.com/ru/post/1017245/


All Articles