Bookstack database issues

I’m having some trouble with Bookstack. I’m getting this error on a fresh install with docker-compose:

Illuminate\Database\QueryException  : SQLSTATE[HY000] [1045] Access denied for user 'bookstack'@'bookstack.shared_default' (using password: NO) (SQL: select * from information_schema.tables where table_schema = bookstackapp and table_name = migrations and table_type = 'BASE TABLE')

  at /var/www/html/vendor/laravel/framework/src/Illuminate/Database/Connection.php:669
    665|         // If an exception occurs when attempting to run a query, we'll format the error
    666|         // message to include the bindings with SQL, which will make this exception a
    667|         // lot more helpful to the developer instead of just the database's errors.
    668|         catch (Exception $e) {
  > 669|             throw new QueryException(
    670|                 $query, $this->prepareBindings($bindings), $e
    671|             );
    672|         }
    673|

  Exception trace:

  1   Doctrine\DBAL\Driver\PDOException::("SQLSTATE[HY000] [1045] Access denied for user 'bookstack'@'bookstack.shared_default' (using password: NO)")
      /var/www/html/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDOConnection.php:31

  2   PDOException::("SQLSTATE[HY000] [1045] Access denied for user 'bookstack'@'bookstack.shared_default' (using password: NO)")
      /var/www/html/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDOConnection.php:27

  Please use the argument -v to see more details.

Here’s my docker-compose.yml section for Bookstack:

bookstack:
    image: linuxserver/bookstack 
    container_name: bookstack
    environment:
      - PUID=1001
      - PGID=1001
      - DB_HOST=bookstack-db
      - DB_USER=bookstack
      - DB_PASS=password
      - DB_DATABASE=bookstackapp
      - APP_URL=http://wiki.domain.com
    volumes:   
      - /home/user/docker/bookstack/config:/config
    labels:
      - "traefik.enable=true"
      # HTTP Routers
      - "traefik.http.routers.bookstack-rtr.entrypoints=https"
      - "traefik.http.routers.bookstack-rtr.rule=Host(`wiki.domain.com`)"
      - "traefik.http.routers.bookstack-rtr.tls=true"
      - "traefik.http.routers.bookstack-rtr.tls.certresolver=cloudflare"
      # HTTP Services
      - "traefik.http.routers.bookstack-rtr.service=bookstack-svc"
      - "traefik.http.services.bookstack-svc.loadbalancer.server.port=80"
    restart: unless-stopped
    depends_on:
      - bookstack-db
  bookstack-db:
    image: linuxserver/mariadb
    container_name: bookstack-db
    environment:
      - PUID=1001
      - PGID=1001
      - MYSQL_ROOT_PASSWORD=root_password
      - TZ=City/Country
      - MYSQL_DATABASE=bookstackapp
      - MYSQL_USER=bookstack
      - MYSQL_PASSWORD=password
    volumes:
      - /home/user/docker/bookstack/data:/config
    restart: unless-stopped

Looks like bookstack is not using the password when connecting to the database.
Did you also grant the bookstack db user to access from outside localhost?

Have you tested using the IP of the database?

How would I do that?

Have you tested using the IP of the database?

That would mean assigning a port to the database container and setting the value DB_HOST to the host IP along with the port I had set, right? I did that and it didn’t work.

You would just need to expose the port and then mysql -u bookstack -p -h <docker host ip> it would then prompt you for your password.

When I have a database problem, this is generally tshoot step #1, try to login using the credentials created for the failing app

I get a command not found when trying to run mysql

that means you need to install mysql

I suppose that was pretty obvious. I did this:

mysql -u bookstack -p 3307 -h 192.168.50.16

and got this:

Enter password: 
ERROR 1045 (28000): Access denied for user 'bookstack'@'172.22.0.1' (using password: YES)

so as you can see, whatever you built isn’t working, this isn’t a container issue, just some potential error you made with the db

login to mysql as root and do select user,host from mysql.user where user="bookstack"; and paste the results here

I can’t login into it as root either. It seems like it didn’t pass my password environment variables into the container correctly. I tried setting the password to just password and it still didn’t work.

you can’t change the password after it’s built, it’s 1 time use.

you’ll need to start mysql in safe mode to bypass passwords, google mysql safe mode and edit custom.cnf in /config to add it in.

or blow it away and start over, make sure you follow the directions fully.

I’ll probably just blow it all away. How safe is it to set the password to just “password” if the mysql server isn’t externally accessible?

as safe as you think it is.

Hello!
I have the same problem and really suspecting is some bug. I created a database and username and made sure I have connection from other system.

The command actually is:

mysql -u bookstack -p -P 3307 -h 192.168.100.15 bookstackapp

-u username
-p ASK for a password
-P port
-h host
and the latter is the DB name.

I’m able to connect, but can’t get the Bookstack docker to do so.
Any ideas well be appreciated!
thanks!

login as root
`select user,host from mysql.user where user=‘bookstack’;

give us the output

when you login as you show above where you say it works, remove the bookstackapp portion and give the output of show databases;

I’m sorry I’m very unfamiliar with SQL…
I did the first part in PhpMyAdmin

this…

select user,host from mysql.user where user=‘bookstack’;

Returns this

ERROR `#1054 - La columna ‘‘bookstack’’ en where clause es desconocida

This is logging in without setting the DB
I do the show databases but nothing shows…

root@nginx-rv-proxy ~# mysql -u bookstack -p -P 3307 -h 192.168.100.15
Enter password:
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 377
Server version: 10.3.21-MariaDB Source distribution

Copyright © 2000, 2018, Oracle, MariaDB Corporation Ab and others.

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

MariaDB [(none)]> show databases
->
-> show databases
->

couple things
for your first query, it says the bookstack user is unknown… show me the output of
select user,host from mysql.user;

for the second one, you need a semicolon after you put it it’s show databases;

thanks!

Ok, thank you. I could get it to work, these are the outputs:

So the database and username are OK?

first screen looks fine, you have user bookstack that can login from anywhere.

Your second screenshot looks like you ran it as root though, i need you to login as bookstack and run show databases; what we are looking for is to ensure your bookstack user sees the bookstackapp database under its own account.

Hello

I had the same error.
I found the problem.
This is the DB_PASS variable. it is not DB_PASS but DB_PASSWORD that must be added !

i don’t think so…

DB_PASSWORD is set from the envvar DB_PASS