Skip to content

Instantly share code, notes, and snippets.

@jjcodes78
Last active March 9, 2024 16:50
Show Gist options
  • Save jjcodes78/e12ce89c9029d520ce08f60a9ff8f304 to your computer and use it in GitHub Desktop.
Save jjcodes78/e12ce89c9029d520ce08f60a9ff8f304 to your computer and use it in GitHub Desktop.
Laravel Sail - GRANT ALL PRIVILEGES to user

Run this command in sail project folder:

docker-compose exec mysql bash

execute the mysql -u root -p command

provide the default password password

then executes

# May be any user created with sail docker-compose
#
GRANT ALL PRIVILEGES ON *.* TO '<sail-user-from-docker-compose-yml>'@'%';

and

FLUSH PRIVILEGES;

that`s it!

@GioValentin
Copy link

ERROR 1045 (28000): Access denied for user 'sail'@'%' (using password: YES)

@jjcodes78
Copy link
Author

Hi @GioValentin the user is laravel not sail. ;)
U can run this commands accordingly with sail user: GRANT ALL PRIVILEGES ON *.* TO 'sail'@'%';

@GioValentin
Copy link

Thank you!

@WhiskeyM1ke
Copy link

ERROR 1410 (42000): You are not allowed to create a user with GRANT

@mathijsqdrop
Copy link

@WhiskeyM1ke make sure you use the right username in your MySQL command!
In case your DB_USERNAME is laraval

GRANT ALL PRIVILEGES ON *.* TO 'laravel'@'%';

or in case your DB_USERNAME is sail

GRANT ALL PRIVILEGES ON *.* TO 'sail'@'%';

Also, make sure to flush the privileges

FLUSH PRIVILEGES;

and exit afterwards

EXIT;

@ferasalhallaknamaa
Copy link

Thank you

@jhang0912
Copy link

Really helped me, thanks

@iwasherefirst2
Copy link

iwasherefirst2 commented Jun 30, 2022

My DB_USERNAME is "adam" and I can login with this user in mysql workbench (not with root). And this is also the sail user of docker-compose, right?

grafik

So when I login with "adam" in the container mysql -u adam -p they try to give me all PRIVILEGES then this is denied:

ERROR 1045 (28000): Access denied for user 'adam'@'%' (using password: YES)
mysql> GRANT ALL PRIVILEGES ON *.* TO 'adam'@'%^C

Am I missing something?

@jjcodes78
Copy link
Author

My DB_USERNAME is "adam" and I can login with this user in mysql workbench (not with root). And this is also the sail user of docker-compose, right?

grafik

So when I login with "adam" in the container mysql -u adam -p they try to give me all PRIVILEGES then this is denied:

ERROR 1045 (28000): Access denied for user 'adam'@'%' (using password: YES)
mysql> GRANT ALL PRIVILEGES ON *.* TO 'adam'@'%^C

Am I missing something?

You need login with root user and grant all privileges to your adam user. ;)

@iwasherefirst2
Copy link

My DB_USERNAME is "adam" and I can login with this user in mysql workbench (not with root). And this is also the sail user of docker-compose, right?
grafik
So when I login with "adam" in the container mysql -u adam -p they try to give me all PRIVILEGES then this is denied:

ERROR 1045 (28000): Access denied for user 'adam'@'%' (using password: YES)
mysql> GRANT ALL PRIVILEGES ON *.* TO 'adam'@'%^C

Am I missing something?

You need login with root user and grant all privileges to your adam user. ;)

yes that worked and makes sense. I thought I don't have the password for root but then I spotted MYSQL_ROOT_PASSWORD is set to $db_password

@akatche
Copy link

akatche commented Jul 5, 2022

Thank you a lot!

@qingyueyiyun
Copy link

the .env content

APP_NAME=Laravel
APP_ENV=local
APP_KEY=base64:4sE3uAionWsXgJatwdc2JHHs/n1qcDOo/dTCglpCBnQ=
APP_DEBUG=true
APP_URL=http://backend-app.test

LOG_CHANNEL=stack
LOG_DEPRECATIONS_CHANNEL=null
LOG_LEVEL=debug

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=sail
DB_USERNAME=sail
DB_PASSWORD=123456

BROADCAST_DRIVER=log
CACHE_DRIVER=file
FILESYSTEM_DISK=local
QUEUE_CONNECTION=sync
SESSION_DRIVER=file
SESSION_LIFETIME=120

MEMCACHED_HOST=memcached

REDIS_HOST=redis
REDIS_PASSWORD=null
REDIS_PORT=6379

MAIL_MAILER=smtp
MAIL_HOST=mailhog
MAIL_PORT=1025
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=null
MAIL_FROM_ADDRESS="[email protected]"
MAIL_FROM_NAME="${APP_NAME}"

AWS_ACCESS_KEY_ID=
AWS_SECRET_ACCESS_KEY=
AWS_DEFAULT_REGION=us-east-1
AWS_BUCKET=
AWS_USE_PATH_STYLE_ENDPOINT=false

PUSHER_APP_ID=
PUSHER_APP_KEY=
PUSHER_APP_SECRET=
PUSHER_HOST=
PUSHER_PORT=443
PUSHER_SCHEME=https
PUSHER_APP_CLUSTER=mt1

VITE_PUSHER_APP_KEY="${PUSHER_APP_KEY}"
VITE_PUSHER_HOST="${PUSHER_HOST}"
VITE_PUSHER_PORT="${PUSHER_PORT}"
VITE_PUSHER_SCHEME="${PUSHER_SCHEME}"
VITE_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}"

SCOUT_DRIVER=meilisearch
MEILISEARCH_HOST=http://meilisearch:7700

when I exec docker-compose exec mysql bash;docker-compose exec mysql bash; GRANT ALL PRIVILEGES ON *.* TO 'sail'@'%'; FLUSH PRIVILEGES; ;and then in sail project forder, exec ./vendor/bin/sail shell; mysql -u sail -p -h 127.0.0.1,give me an error information ERROR 2003 (HY000): Can't connect to MySQL server on '127.0.0.1:3306' (111); when exec mysql -u sail -p, given me an another error information ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2), how can I connect with DBvaear tool?

@AtlasApollo
Copy link

Thank you very much!

@bulentAkgul
Copy link

I can't thanks enough.

@fumfel20
Copy link

You made my day! Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment