Can't connect to MySQL

68 views
Skip to first unread message

backseat

unread,
Sep 9, 2019, 12:54:30 PM9/9/19
to web2py-users
I've just downloaded web2py 2.18.5 and set the MySQL URI as follows:

uri       = 'mysql://rota:rota@localhost/rota'


Web2py gives:

1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
Traceback (most recent call last):
 
File "/home/kae/web2py-2.18.5/gluon/restricted.py", line 219, in restricted
   
exec(ccode, environment)
 
File "/home/kae/web2py-2.18.5/applications/rota/models/db.py", line 47, in <module>
   
check_reserved=['all'])
 
File "/home/kae/web2py-2.18.5/gluon/packages/dal/pydal/base.py", line 171, in __call__
    obj
= super(MetaDAL, cls).__call__(*args, **kwargs)
 
File "/home/kae/web2py-2.18.5/gluon/packages/dal/pydal/base.py", line 477, in __init__
   
"Failure to connect, tried %d times:\n%s" % (attempts, tb)
RuntimeError: Failure to connect, tried 5 times:
Traceback (most recent call last):
 
File "/home/kae/web2py-2.18.5/gluon/packages/dal/pydal/base.py", line 442, in __init__
   
self._dbname = REGEX_DBNAME.match(uri).group()
AttributeError: 'NoneType' object has no attribute 'group'



I can access the db from the command line:

$ mysql -h localhost -u rota -prota rota
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 187
Server version: 10.3.17-MariaDB-0+deb10u1 Debian 10

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [rota]>

I can see Web2py can't connect to MySQL, but I can't find any clues as to why. 

Where should I look to try to resolve this?

Annet

unread,
Sep 10, 2019, 2:39:46 AM9/10/19
to web2py-users
According to the book the connection string for MySql is:

mysql://username:password@localhost/test?set_encoding=utf8mb4

Maybe adding the TCP port solves the issue:

mysql://username:password@localhost:13306/test?set_encoding=utf8mb4


Kind regards,

Annet

backseat

unread,
Sep 10, 2019, 4:54:27 PM9/10/19
to web2py-users
MySQL is listening on the default port:

$ telnet localhost 3306
Trying ::1...
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
c
5.5.5-10.3.17-MariaDB-0+deb10u1�a3y(W]OS��-��5KZaY|$920;vmysql_native_password^CConnection closed by foreign host.

 

backseat

unread,
Sep 11, 2019, 1:56:02 AM9/11/19
to web2py-users
This code fails:

uri = configuration.get('db.uri')
print uri
db = DAL(uri)

The uri printed is:

'mysql://rota:rota@localhost/rota?set_encoding=utf8mb4'

This code works:

db = DAL('mysql://rota:rota@localhost/rota?set_encoding=utf8mb4')

That's exactly the same URI (it was copy and pasted in Vim). 

I'm moving on.
Reply all
Reply to author
Forward
0 new messages