Connect to laravel sail mysql from macOS local machine - mysql

I have installed a fresh Laravel 8 Project using sail
https://laravel.com/docs/8.x/installation#getting-started-on-macos
I followed the guide. First ran this
curl -s "https://laravel.build/example-app" | bash
Then this
./vendor/bin/sail up
But now I have difficulty connecting using mysql client. This is the command that I'm trying to execute
mysql -u sail -D example_app -h localhost -P 3306 -p
I get the following error
ERROR 1045 (28000): Access denied for user 'sail'#'localhost' (using password: YES)

The .env file at the root of the project – docker-compose.yml automatically detects and imports the content of this file. For instance, in the MYSQL_ROOT_PASSWORD: '${DB_PASSWORD}' line, the container's MYSQL_ROOT_PASSWORD environment variable will receive the value of DB_PASSWORD from the .env file.
By default these are sail for the username and password for the pass. Are you passing that password when connecting?
This is a really good article i followed to get more insights: https://tech.osteel.me/posts/you-dont-need-laravel-sail

Use DB_HOST as 'mysql' in .env file.

Related

How to find the password of mysql on desktop docker in laravel?

After Laravel installation by sail and docker on windows, I run the server by:
./vendaor/bin/sail up -d
and this is the containers:
I can't connect to MySQL by user: root and password and port 3306
docker exec -it app-mysql-1 mysql -u root -p
I delete the app-mysql-1 from app containers and Run a MySQL image but problem still exists and I can't connect to MySQL and make or migrate.
I can find the auto generated MySQL password and can change it but can't connect and use this one in app containers
How I can connect to MySQL in the app containers?
If you didn't change the default Sail database user then you should use:
User: sail
Password: password
And in ./.env:
DB_USERNAME=sail
DB_PASSWORD=password

Unable to connect to mysl container via HeidiSQL via localhost

Environment:
I've created and started a Docker container on Windows 11 via the following command:
docker run --name some-mysql -e MYSQL_ROOT_PASSWORD=root -d mysql:latest
Then I've created a new HeidiSQL session with the following options:
library: libmysql.dll
host: 127.0.0.1
user: root
password: root
port: 3306
After click on Open it says "Can't connect to MySQL server on '127.0.0.1' (10061)".
I'am able to connect to the container via the terminal.
After some research and some experiment I am able to find a solution.
First of all the port fordwarding must be forced to be 3306:3306.
You must create and run the Docker container with the parameter -p 3306:3306.
docker run --name some-mysql -p 3306:3306 -e MYSQL_ROOT_PASSWORD=root -d mysql:latest
Now the error is changed, but at least it can connect to the server.
"Access denied for user 'root'#'172.17.0.1' (using password: YES)"
Now most solutions found on the web tells to create a new user 'root'#'172.17.0.1' and grant all privileges to the user.
But, even after creating the user, HeidiSQL is unable to login again (same "access denied" error).
The strange thing is that if you login with the new user with a terminal, and then, try to login with HeidiSQL, now it works, this happens everytime you restart the container.
After searching I found this: https://github.com/HeidiSQL/HeidiSQL/issues/980
So the problem is that libmysql.dll is outdated and not supported, and it fails everytime you try to access for the first time with HeidiSQL.
You must switch to libmariadb.dll that is also compatible with mysql, is not needed to create the new user.
Do not use libmysql-6.1.dll, because crashes and not works for some reasons...

Intellij Connect to Docker MySQL DB

I have a problem connecting to a docker mysql DB through the Intellij UI.
I am able to connect using the following command through the terminal:
mysql -h localhost -P 3306 --protocol=tcp -u root -p db_name --password=password
Note the user of the --protocol flag, without this I could not connect. In addition, I assume that since I can connect through the terminal to the docker DB then setup is correct, i.e. the port is exposed and I am able to connect.
In Intellij I use the following connection settings - I am not sure where you specify the protocol of the connection, in case this resolved the issue. I've also tried using 127.0.0.1 instead of localhost which as I read will use the tcp protocol. But no luck.
I've tried the latest MYSQL Driver (8) for the connection as well as the MySQL for 5.1 version.
The error I get is the following(though the password and username are triple checked, and I am able to connect through the terminal):
The specified database user/password combination is rejected:
[28000][1045] Access denied for user 'root'#'localhost' (using
password: YES)
Any help or guidance would be much appreciated.

Access denied for user MySql

The problem is my localhost Laravel project just won't connect to MySQL, I get the following error:
Access denied for user 'root'#'localhost' (using password: YES)
OS: macos high sierra
Browser: Chrome;
MySql version: 8.0.12
Laravel version: 5.6
Homestead Version: 7.0
Things I have tried to fix it:
Checked that there is an instance of MySql running - It's running.
Check the credentials in the .env file and config/database.php - The credentials are correct (Mysql root user password has been change from the one generated on installation)
I checked if I could connect via terminal to double check that the credentials are correct - I can and they are correct
Tried creating a new MySql user with all root privileges. - same error.
I can run php artisan migrate in the terminal and the tables are created. which I thought was strange as the site is denied.
I completely removed MySql 3 times. (following this guide: https://gist.github.com/vitorbritto/0555879fe4414d18569d) - same error
So then I started from the beginning destroyed the vagrant box and Laravel project and started from the beginning - Same error.
Fought the urge to punch my computer.
.env (Updated)
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=homestead
DB_USERNAME=homestead
DB_PASSWORD=secret
yaml:
---
ip: "192.168.10.10"
memory: 2048
cpus: 1
provider: virtualbox
authorize: ~/.ssh/id_rsa.pub
keys:
- ~/.ssh/id_rsa
folders:
- map: ~/Sites
to: /home/vagrant/Sites
sites:
- map: site.test
to: /home/vagrant/Sites/sitetest/public
databases:
- homestead
/etc/hosts
##
##
# Host Database
#
# localhost is used to configure the loopback interface
# when the system is booting. Do not change this entry.
##
127.0.0.1 localhost
255.255.255.255 broadcasthost
::1 localhost
127.0.0.1 site.test
The default password for homestead is not something.
According to laravel docs it is secret.
A homestead database is configured for both MySQL and PostgreSQL out
of the box. For even more convenience, Laravel's .env file configures
the framework to use this database out of the box.
To connect to your MySQL or PostgreSQL database from your host
machine's database client, you should connect to 127.0.0.1 and port
33060 (MySQL) or 54320 (PostgreSQL). The username and password for
both databases is homestead / secret.
Docs at: https://laravel.com/docs/5.6/homestead
Update:
You can also grant your user the permissions to play with the database with:
GRANT ALL PRIVILEGES ON database_name.* TO 'username'#'localhost';
In the hosts file, when running Homestead, you'll have to change 127.0.0.1 site.test to 192.168.10.10 site.test
Of course that will only work after vagrant up
You can solve your problem by caching your config:
php artisan config:cache
Cd into your Homestead directory
run vagrant ssh
run php artisan migrate
try this
first inside in mysql run sudo mysql -u root -p
next execute this command :
use mysql;
update user set plugin='' where User="root";
flush priviliges;
exit

Access denied for mysql docker image in bamboo

I've got this configuration for a MySQL Docker image:
mysqldata:
image: busybox
volumes:
- /var/lib/mysql
mysql:
image: mysql:5.6
ports:
- "8203:3306"
volumes_from:
- mysqldata
environment:
- "MYSQL_ALLOW_EMPTY_PASSWORD=yes"
- "MYSQL_USER=root"
and I lift it up with docker-compose up -d mysql, and I can run commands against the DB in the image, access it without problems, etc.
Then I setup a docker image to be lifted in Bamboo:
But it fails when running commands against the DB in that image, with the error:
ERROR 1045 (28000): Access denied for user 'root'#'localhost' (using password: NO)
From the build logs of the test run I can see that the env variables are applied:
/usr/bin/docker run --workdir /data --detach --name mysql-user-service -p 8203:3306 -e MYSQL_ALLOW_EMPTY_PASSWORD=yes -e MYSQL_USER=root mysql:5.6
But still no success.
Anyone knows how to overcome this problem?
Where are you connecting from? The host, another container?
Did you give permissions to the user#localhost MySQL user so it has access to the database? That error usually means the user you are connecting with doesn't have access to the db, and you need to grant the permissions.
If you do a docker ps you will see the name and the ID of the container you started for MySQL. Take that name or ID and run
docker exec -it <name or id> sh
That will get you into the container and you can run your MySQL commands to grant access something like this.
GRANT ALL ON *.* TO 'root'#'localhost
Since you are using compose you can do something like this as well
docker-compose run mysql GRANT ALL ON *.* TO 'root'#'localhost
You might also have to create the database of there isn't one already, and you would use the same steps just change the sql that is run