ergast-f1-api icon indicating copy to clipboard operation
ergast-f1-api copied to clipboard

Unable to connect to database

Open gavboulton opened this issue 6 years ago • 8 comments

First of all, thanks for this API.

When running the docker-compose command and hitting the API (after waiting for the build to complete) I get 'Unable to select database'. The mysql connection is failing in a previous step. I thought this may have been a race condition with the two containers starting at the same time so I started the containers separately, running the db container first and then the app container but the same problem exists.

I have Mac/Docker Engine: 18.03.1-ce and Compose: 1.21.1.

Has anyone else had the same issue?

gavboulton avatar May 17 '18 10:05 gavboulton

I see the same issue. MySQL is up and running with the database fully populated. I see some errors in the Apache error log:

[Mon Sep 10 16:58:30.505278 2018] [:error] [pid 53] [client 172.17.0.1:60908] PHP Warning: mysql_connect(): Server sent charset unknown to the client. Please, report to the developers in /var/www/html/php/api/f1dbro.inc on line 5 [Mon Sep 10 16:58:30.505724 2018] [:error] [pid 53] [client 172.17.0.1:60908] PHP Warning: mysql_set_charset() expects parameter 2 to be resource, boolean given in /var/www/html/php/api/f1dbro.inc on line 6

lcrilly avatar Sep 10 '18 17:09 lcrilly

Solved by changing ergastdb/Dockerfile to use FROM mysql:5.6

lcrilly avatar Sep 24 '18 21:09 lcrilly

Nice. Thanks @lcrilly. Will you create a PR for this?

gavboulton avatar Sep 25 '18 11:09 gavboulton

I'm getting troubles with the same but I dont see any errors in the apache errors log

juansanluq avatar Jun 08 '19 17:06 juansanluq

Thanks for the API, first of all. Unfortunately I still encounter problems with connecting the database after following the above improvements. I did installed docker desktop 2.1.0.5 (OSX)

Can anyone help me out a bit.

wdpoppe avatar Nov 26 '19 17:11 wdpoppe

FWIW, my complete Dockerfile

FROM mysql:5.6
RUN sed -i -e"s/^bind-address\s*=\s*127.0.0.1/bind-address=0.0.0.0/" /etc/mysql/my.cnf
RUN apt-get update && apt-get install -y wget && apt-get clean
WORKDIR /docker-entrypoint-initdb.d
RUN wget http://ergast.com/downloads/f1db.sql.gz -O - | gzip -cd > f1db.sql

lcrilly avatar Nov 26 '19 17:11 lcrilly

Thank you for your reply. I've copy/paste the above dockerfile, restarted docker and did ran command docker-compose up --build -d --remove-orphans After I ran the command, the terminal said it it did make a build successfully. Unfortunately when I browse to http://localhost:8000/api/f1/2017.json it still encounters an error on the page; Unable to select database.

Any other suggestions left?

regards

wdpoppe avatar Nov 27 '19 23:11 wdpoppe

I am seeing the same error as above comments with and without FROM mysql:5.6. I think there is supposed to be two running containers but only one is still alive.

Doing sudo docker ps --last 2 and sudo docker logs 7ad8f71669e0 reveals a clue.

CONTAINER ID        IMAGE                    COMMAND                  CREATED             STATUS                      PORTS                  NAMES
9e1468fbbaff        ergast-f1-api_web        "/my_init"               4 minutes ago       Up 29 seconds               0.0.0.0:8000->80/tcp   ergast-f1-api_web_1
7ad8f71669e0        ergast-f1-api_ergastdb   "docker-entrypoint.s…"   4 minutes ago       Exited (1) 29 seconds ago                          ergastdb
2020-04-09 00:48:18+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 5.6.47-1debian9 started.
2020-04-09 00:48:18+00:00 [Note] [Entrypoint]: Switching to dedicated user 'mysql'
2020-04-09 00:48:18+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 5.6.47-1debian9 started.
2020-04-09 00:48:18 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2020-04-09 00:48:18 0 [Note] mysqld (mysqld 5.6.47) starting as process 1 ...
2020-04-09 00:48:18 1 [Note] Plugin 'FEDERATED' is disabled.
mysqld: Table 'mysql.plugin' doesn't exist
2020-04-09 00:48:18 1 [ERROR] Can't open the mysql.plugin table. Please run mysql_upgrade to create it.
2020-04-09 00:48:18 1 [Note] InnoDB: Using atomics to ref count buffer pool pages
2020-04-09 00:48:18 1 [Note] InnoDB: The InnoDB memory heap is disabled
2020-04-09 00:48:18 1 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2020-04-09 00:48:18 1 [Note] InnoDB: Memory barrier is not used
2020-04-09 00:48:18 1 [Note] InnoDB: Compressed tables use zlib 1.2.11
2020-04-09 00:48:18 1 [Note] InnoDB: Using Linux native AIO
2020-04-09 00:48:18 1 [Note] InnoDB: Using CPU crc32 instructions
2020-04-09 00:48:18 1 [Note] InnoDB: Initializing buffer pool, size = 128.0M
2020-04-09 00:48:18 1 [Note] InnoDB: Completed initialization of buffer pool
2020-04-09 00:48:18 1 [Note] InnoDB: Highest supported file format is Barracuda.
InnoDB: No valid checkpoint found.
InnoDB: If you are attempting downgrade from MySQL 5.7.9 or later,
InnoDB: please refer to http://dev.mysql.com/doc/refman/5.6/en/upgrading-downgrading.html
InnoDB: If this error appears when you are creating an InnoDB database,
InnoDB: the problem may be that during an earlier attempt you managed
InnoDB: to create the InnoDB data files, but log file creation failed.
InnoDB: If that is the case, please refer to
InnoDB: http://dev.mysql.com/doc/refman/5.6/en/error-creating-innodb.html
2020-04-09 00:48:18 1 [ERROR] Plugin 'InnoDB' init function returned error.
2020-04-09 00:48:18 1 [ERROR] Plugin 'InnoDB' registration as a STORAGE ENGINE failed.
2020-04-09 00:48:18 1 [ERROR] Unknown/unsupported storage engine: InnoDB
2020-04-09 00:48:18 1 [ERROR] Aborting

Not sure how to fix this.

MakotoE avatar Apr 09 '20 00:04 MakotoE