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
Related
friends.
Since I am new to Laravel sail and docker in general, I can't realy understand, is it a bug or a feature:
When trying this command: "$ ./vendor/bin/sail mysql", I'm automaticly get in MySQL cli whithout asking any creditials.
I supose that's not quite secure behavior.
I'd tried to set MYSQL_ALLOW_EMPTY_PASSWORD paran to '0' in my docker-compose, but that brang no any visible effects.
It's a convenience feature.
Sail automatically uses the password defined in the .env file (as well as user and database) to connect to MySQL. Since Sail is only intended for local development and the password is already saved in .env there shouldn't be any additional security concerns.
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
I ran into the exact same problem today.
The problem seems to be the db user 'sail' set in the .env file.
It doesn't have the required privileges to create a database.
Opening the mysql console with the sail mysql command and trying to create a database with CREATE DATABASE test; causes the same error.
Changing the paramater in the .env file to:
DB_USERNAME=root
and rebuilding the docker container caused an error in the docker creation log and therefore mysql not running at all.
Logging into docker mysql as root and trying to set new privileges to the 'sail' user didn't help either.
What worked for me in the end was building the application with the standard
DB_USERNAME=sail
starting the application with sail up -d and then changing the .env file to
DB_USERNAME=root
After that I reset the config with sail artisan config:clear.
Ran into the same problem, what worked for me was creating an init.sql file
GRANT ALL PRIVILEGES ON *.* TO 'sail'#'%';
FLUSH PRIVILEGES;
And adding this to the mysql entry:
volumes:
- ./path/to/init.sql:/docker-entrypoint-initdb.d/init.sql
What worked for me:
I have PhpMyAdmin installed in my container and I able to login to to it using,
server: mysql
username: root
password: secret
After successful login, I navigated to the User Accounts page, selected sail and granted all the permission that was appropriate for my work and save.
This will resolve the issue of SQLSTATE[HY000] [1045] Access denied
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
When trying to install CiviCrm in Drupal 7 I get "Could not create a database trigger".
Using a standard ddev config.yml for drupal7.
A couple of solutions are suggested at https://civicrm.stackexchange.com/questions/2770/database-trigger-error-message but I am struggling to implement them within ddev.
RE Grant - When I try ddev exec mysql GRANT..... I get failed to execute command. When I ssh into a mysql shell to try to grant privileges I get access denied for user.
RE log_bin_trust_function_creators = 1. Where would I insert that?
Update 2019-01-25: I went to check this out after you created the issue and what I suggested was inadequate. As explained there, you need to do a little custom config. Create a .ddev/mysql/trigger.cnf with these contents:
[mysqld]
log_bin_trust_function_creators=on
And the next release of ddev (mid-February) will make this the default (PR). So please report your results there. I was able to install CiviCRM with this mysql config.
Original response: True but not adequate for triggers:
The db container root user has full privileges, so you can use mysql -uroot -proot ... to do what you need to do. You can do that inside the db container ddev ssh -s db or inside the web container ddev ssh or from the host using the info in ddev describe (but using root/root). (You can also use the root user to grant additional privileges to the db user, of course.)
If you know what privileges are required, we should add them to the db user, so please make an issue requesting what you need, because we'd like this to be easier for you.
This is a followup question to How can I create and load a second database in ddev?. It is about doing that task automatically.
One use case for this is developing a migration to Drupal from another MySQL database, and collaborating with others on the migration. If the database name can be set by ddev, additional developers can get the database created automatically, and additional databases can be added to their settings.local.php, using known values.
Try this in your project's config.yaml:
hooks:
post-start:
- exec: mysql -uroot -proot -hdb -e "CREATE DATABASE IF NOT EXISTS another_db; GRANT ALL ON another_db.* TO 'db'#'%';"
I just started using docker, laradock and laravel, after setting up the entire environment I tried to login on my phpmyadmin and I couldn't sign in.
I looked pretty much everywhere and couldn't find a way to fix it so you guys are my last hope lol.
Docker version 17.12.0-ce, build c97c6d6
Here's my docker ps
My project's .env
DB_CONNECTION=mysql
DB_HOST=mysql
DB_PORT=3306
DB_DATABASE=homestead
DB_USERNAME=homestead
DB_PASSWORD=secret
And here are the errors I am getting from phpmyadmin (localhost:8080)
#2054 - The server requested authentication method unknown to the client
mysqli_real_connect(): The server requested authentication method unknown to the client [caching_sha2_password]
mysqli_real_connect(): (HY000/2054): The server requested authentication method unknown to the client
The easiest solution is to revert back to an earlier version of MySQL. It's probably a good idea anyway since 8.0 is a "developer's release". Unfortunately Laradock currently has a bug that installs 8.0 no matter what you set in the .env file. I've submitted a PR on Laradock to fix this particular issue.
https://github.com/laradock/laradock/pull/1409
This is caused by an update to libmysqlclient since MySQL version 8.0.4 which has changed the default authentication method to a more secure sha256_password.
As soon as Laravel and other software packages such as PhpMyAdmin are updated to support this new and more secure authentication method this problem wil resolve itself.
If you CANNOT delete and rebuild your existing mysql data volume, simply:
Sign in to your mysql container (docker-compose exec mysql mysql -uroot -proot)
Execute ALTER USER 'root'#'localhost' IDENTIFIED WITH mysql_native_password BY 'root';
Repeat step 2 for any other users you may have created.
If you CAN recreate your mysql data volume:
Modify your my.conf file. Under [mysqld] add the following configuration option default_authentication_plugin=mysql_native_password
Delete your mysql volume rm -rf ~./laradock/data/mysql
Rebuild the mysql container docker-compose -d --build mysql phpmyadmin