Search code examples
laraveldockermulti-tenantwindows-subsystem-for-linuxlaravel-sail

How To Create A New Database For Each Tenant on Laravel Sail, Docker


I'm developing a multi-tenant app first time by using Laravel 8, Tenancy For Laravel on Docker and WSL2. My issue occures when I try to create a tenant. I want to create a new database for each tenant, but creating database trows the following error:

SQLSTATE[42000]:
Syntax error or access violation:
1044 Access denied for user 'sail'@'%' to database 'tenant-a6d0813b-a546-428d-859a-15095724fb73'
(SQL: CREATE DATABASE `tenant-a6d0813b-a546-428d-859a-15095724fb73` CHARACTER SET `utf8mb4` COLLATE `utf8mb4_unicode_ci`) 

I don't even know where should I start from because I'm pretty new on Docker, WLS and Laravel Sail. Before I moved this project to Docker, I was able to create databases on Xammp, but not anymore.

docker-compose.yml file is as it's shipped by Laravel exept the part that phpmyadmin is included:

phpmyadmin:
   image: phpmyadmin
   restart: always
   ports:
       - 8080:80
   environment:
       - PMA_HOST=mysql
   depends_on:
       - mysql
   networks:
       - sail

Solution

  • I asked this question long time ago. I had stopped working on that project. Now, I've started a new one, faced with the same issue. I came across with my own question while searching the solution. I found it, here it's:

    You should execute the following commands on your teminal:

    docker-compose exec mysql bash
    mysql -u root -p
    password: password
    GRANT ALL PRIVILEGES ON *.* TO 'sail'@'%';
    FLUSH PRIVILEGES;
    EXIT;
    exit