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.
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:
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
i see you use mariadb so type
sail mariadb
will open mariadb line command type
create database name
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.