User Access denied for programmatically newly created database.
Hi.
I am creating a Laravel Multitenancy website using this package https://tenancyforlaravel.com/
I have connected my Linode server with Laravel Forge https://forge.laravel.com/
I have already created a database and user on my server and connected this DB with my site in the env file. I'll use this DB as a central DB.
My DB name is "ezisaferxyz"
My user name is "ezisaferxyz"
now when this package creates a database on tenant creation I am getting this error on my live website
Illuminate\Database\QueryException
SQLSTATE[42000]: Syntax error or access violation: 1044 Access denied for user 'ezisaferxyz'@'%' to database 'tenant259abe15-5cbf-4069-94d3-f80d916898bd' (SQL: CREATE DATABASE tenant259abe15-5cbf-4069-94d3-f80d916898bd
CHARACTER SET utf8mb4
COLLATE utf8mb4_unicode_ci
)
All this is working great in my local environment (LARAGON).
What I think is: on local setup root user has full permissions to all databases (upcoming and existing). But on the live server when a new database creates the user "ezisaferxyz" doesn't have permissions to this newly created database and it throws this exception.
can you help me to figure this out, please? If this is the same issue I am thinking then how can I give full access to this user "ezisaferxyz" for all newly created databases? thanks
3 Replies
You can grant permissions to a wildcard. For example, if your new databases will always start with “tenant”, you could do something like:
grant all on `tenant%`.* to `ezisaferxyz`@`%`;
Hi [@andysh] (/community/user/andysh)
Thanks for your reply. Ok, it makes sense. But how can I do that? I mean from where I'll run this command?
On Forge dashboard -> on selected site -> we have 'commands' page where I can run artisan commands, there of course I can't run this command.
other than this place, I am not able to do it from anywhere even on the Linode dashboard.
I am in the initial stages (configuring server), maybe I am missing something , if you help me, please. Thanks again.
I mean from where I'll run this command?
This is a MySQL query so you need to run it against your installed MySQL instance.
Linode (the company, its staff and the dashboard) do not have access to the internals of your Linode so cannot run it for you.
I’m not familiar with Forge, but I’m assuming it has deployed your Linode and MySQL. You should therefore be able to SSH to your Linode and then access MySQL by running the mysql
command.