Error connecting to database through Docker - laravel

I have a mysql service running on port 3308 using docker. However on table plus when I try to access this using “127.0.0.1” as the Host and Port “3308”, enter the user, password and database name if I test the connection it shows an error:
Lost connection to MySQL server at 'reading initial communication packet', system error: 0
Also If I run php artisan migrate I get:
Illuminate\Database\QueryException
SQLSTATE[HY000] [1045] Access denied for user 'root'#'localhost' (using password: NO) (SQL: select * from information_schema.tables where table_schema = project and table_name = migrations and table_type = 'BASE TABLE')
at vendor/laravel/framework/src/Illuminate/Database/Connection.php:712
708▕ // If an exception occurs when attempting to run a query, we'll format the error
709▕ // message to include the bindings with SQL, which will make this exception a
710▕ // lot more helpful to the developer instead of just the database's errors.
711▕ catch (Exception $e) {
➜ 712▕ throw new QueryException(
713▕ $query, $this->prepareBindings($bindings), $e
714▕ );
715▕ }
716▕ }
If I use the port 3306 on tableplus I can connect to the database but still get the issue with the php artisan command. But it's strange because in docker is configured with port 3308.
The .env file is like this:
DB_CONNECTION=mysql
DB_HOST=host.docker.internal
DB_PORT=3308
DB_DATABASE=project
DB_USERNAME=root
DB_PASSWORD=pass
Do you know what can be the issue?

Are both container, php-fpm and the database-service-container, in the same network? Did you change the database config in .env? The config parameter DB_HOST should not show an ip, instead set it to the name of your mysql container/Service. Eg.G DB_HOST=database

Related

Lumen, laravel and pgsql SQLSTATE[HY000] [2002] No such file or directory

I was created rest API with Lumen and pgsql in my localhost then its running perfect when I test to call my API with postman, then I run php artisan migrate on server production in cloud and run success. But when I call my API in cloud it show error like this
{
"code": "500",
"message": "SQLSTATE[HY000] [2002] No such file or directory (SQL: select `id`, `payment` from `myDb` where `client_id` = xxxxx and `client_secret` = xxxxxxx limit 1)",
"data": null
}
Please someone can help me.
Thanks advance

can someone help me after i run the composer install

config file
enter image description here
#my appService provider
enter image description here
can someone tell me about this problem after I input composer install that problem says and now I cant migrate
[Illuminate\Database\QueryException] Database (C:\xampp\htdocs\shop2\database\db.sqlite) does not exist. (SQL: PRAGMA foreign_keys=1)
when I run php artisan migrate this problem show
[Illuminate\Database\QueryException]
SQLSTATE[HY000] [1049] Unknown database 'config/database.php' (SQL: select * from information_schema.tables where t
able_schema = config/database.php and table_name = migrations)
[Doctrine\DBAL\Driver\PDOException]
SQLSTATE[HY000] [1049] Unknown database 'config/database.php'
[PDOException]
SQLSTATE[HY000] [1049] Unknown database 'config/database.php'
Create an empty file with name of db.sqlite in your database folder of the app. Then, run php artisan migrate, It will be filled by the app.

SQLSTATE[HY000] [1698] Access denied for user 'hadi'#'localhost'

currently I install laravel 8 in my Linux operating system without any error, so I started working on a simple blog-post application, and when I run php artisan migrate I get the following error.
Illuminate\Database\QueryException
SQLSTATE[HY000] [1698] Access denied for user 'hadi'#'localhost' (SQL: select * from information_schema.tables where table_schema = blog and table_name = migrations and table_type = 'BASE TABLE')
at vendor/laravel/framework/src/Illuminate/Database/Connection.php:671
667▕ // If an exception occurs when attempting to run a query, we'll format the error
668▕ // message to include the bindings with SQL, which will make this exception a
669▕ // lot more helpful to the developer instead of just the database's errors.
670▕ catch (Exception $e) {
➜ 671▕ throw new QueryException(
672▕ $query, $this->prepareBindings($bindings), $e
673▕ );
674▕ }
675▕
+34 vendor frames
35 artisan:37
Illuminate\Foundation\Console\Kernel::handle()
I search for my problem here and other sites but I can't find an exact solution.
Hope to get one
Check your file .env. Make sure its correctly.
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=your_database_name
DB_USERNAME=your_username
DB_PASSWORD=your_password
In case, you put correct credential but it still not work you can:
Delete Cache Files From root/boostrap/chache/files and Run The App

How to do configuration of PostgreSQL database in DHIS2?

I've downloaded and executed DHIS-2 in the Windows operating system. I want to connect with a PostgreSQL database. I'm trying the below configuration settings in the dhis.conf file but it's not working.
connection.dialect = org.hibernate.dialect.PostgreSQLDialect
connection.driver_class = org.postgresql.Driver
connection.url = jdbc:postgresql:dhis2
connection.username = dhis
connection.password = dhis
connection.schema = update
encryption.password = abcd
It's showing me following error message.
HTTP ERROR: 503
Problem accessing /. Reason:
Service Unavailable
Please verify that the database name, username and password is correct.
You can test this on the command line / terminal with the following command:
psql -d dhis2 -U dhis -p
Then enter your password. If you cannot connect, one or more of database name, username and password are incorrect.

Hortonworks Hive Username password configuration

I am attempting to get a connection to the hive server and keep getting:
HiveAccessControlException Permission denied: user [hue] does not have [CREATE] privilege on [default/testHiveDriverTable]
Not sure what username/password combination I should use.
I have Hortonworks running on a virtual machine. The code I am attempting to use to connect to the Hive server is:
Connection con = DriverManager.getConnection(“jdbc:hive2://192.168.0.6:10000/default”, “hue”, “”);
I have also tried connecting via the "root", "Hadoop" username, password configuration.
By the look of the error message, the Connection is OK, but you lack privileges to execute the Statement just below... because that "testHiveDriverTable" label smells like you did a copy/paste on some dummy code example such as:
Connection con = DriverManager.getConnection("jdbc:hive://10.0.2.15:10000/default", "", "");
Statement stmt = con.createStatement();
String tableName = "testHiveDriverTable";
stmt.executeQuery("drop table " + tableName);
stmt.executeQuery("create table " + tableName + " (key int, value string)");
The "no [CREATE] privilege on [default/testHiveDriverTable]" message is a good fit for a create table testHiveDriverTable attempt in database default.
Bottom line: congratulations, you actually could connect to Hive. Now you can work on how to configure the "default" database so that you can actually create tables :-)
Have you tried connecting without giving username and password? I have the following connection string on my cloudera virtualbox which works
Connection con = DriverManager.getconnection(jdbc:hive2://localhost:10000/default,"","");
Here default is the DB name.

Resources