1

I'm using laravel sail and trying to create another database for my Laravel project which required to use multiple databases connections, I've tried to create from user root with empty password and sail with password password but go access denied. tried command line to run

docker-compose exec -u 0 "mariadb" mysql -usail -ppassword -e 'create database databaseName;'

but also got access denied.

2 Answers2

1

You can do this by adding an additional volume in your docker-compose.yml file

volumes:
     - 'sail-mariadb:/var/lib/mysql'
     - ./docker/8.1/create-extra-database.sql:/docker-entrypoint-initdb.d/create-extra-database.sql
     - './vendor/laravel/sail/database/mysql/create-testing-database.sh:/docker-entrypoint-initdb.d/10-create-testing-database.sh'

Then make sure to have the create-extra-database.sql in the proper directory. Like this: enter image description here

Then add whatever mysql commands you'd like in that file. Here I'm adding an additional log database.

CREATE DATABASE IF NOT EXISTS log;
GRANT ALL PRIVILEGES ON `log`.* TO 'sail'@'%';

Make sure to delete the previous mysql docker container and volume. Then run sail up

Cam
  • 988
  • 1
  • 12
  • 25
-2

i see you use mariadb so type

sail mariadb

will open mariadb line command type

create database name
xpredo
  • 1,282
  • 17
  • 27