i have my localhost configured with and other port, i'm trying to use this in the 'yii\db\Connection'
'dsn' => 'mysql:host=192.168.1.5;dbname=db_empresa_juridico',
'username' => 'db_user_jurid',
'password' => '[removed]',
'charset' => 'utf8',
but Yii2 still loading, don't show nothing how i can connecting to the db? using local ip?
i need to shared my db at lan
Missing the port=3306 in
'dsn' => 'mysql:host=192.168.1.5;dbname=db_empresa_juridico;port=3306',
Related
So I have 3 docker containers, one with PHP+PhalconPHP, one with MySQL and another with the webserver. Now on my host system I can connect to the MySQL in the docker container and I can also connect with PDO using the following code
new PDO('mysql:host=mysql;port=1024;dbname=database', 'root', 'password');
But for some reason the phalcon framework is unable to connect to the MySQL database using the config.php file like so
return new \Phalcon\Config([
'database' => [
'adapter' => 'mysql',
'port' => 1024,
'host' => 'mysql',
'username' => 'root',
'password' => 'password',
'dbname' => 'database',
'charset' => 'utf8',
],
]);
In this case, for some reason I am getting a Can't connect to MySQL server on 'mysql' (111 "Connection refused) even though I am 100% sure I can actually connect (as proven before with the PDO connection). I also tried hardcoding the actual MySQL container ip address but no luck either.
Any ideas?
So it appeared to be kind of a stupid "mistake" but here's the solution.
Apparently when you use the Phalcon Developer Tools to scaffold your project, it does not initialize the database with the port configuration as it outright ignores it. You can easily fix this by going into the app/config/services.php file and changing the db service to also include the port configuration.
$connection = new $class([
'host' => $config->database->host,
'port' => $config->database->port,
'username' => $config->database->username,
'password' => $config->database->password,
'dbname' => $config->database->dbname,
'charset' => $config->database->charset
]);
This question already has answers here:
Can't connect to local MySQL server through socket '/var/mysql/mysql.sock' (38)
(43 answers)
Closed 6 years ago.
I tried hosting my Laravel App using Laravel Version 4 On Godaddy and it worked wel, but when I tried logging in, I got this error message:
Can't connect to local MySQL server through socket '/var/mysql/mysql.sock' (38)
NOTE A DUPLICATE: All the Answers there kept pointing to Installing MySQL and mostly referring to this issue on a localhost/System while mine is on a Live server and has nothing to do with MySQL
Okay I finally found the issue, If you ever encounter this on Godaddy, kindly check your Database configuration file in database.php, instead of localhost for the Host, you have to use Godaddy's Host for your Database.
So instead of this:
'mysql' => array(
'driver' => 'mysql',
'host' => 'localhost',
'database' => 'revailment',
'username' => 'revailment',
'password' => 'password',
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
),
Your configuration should be like this:
'mysql' => array(
'driver' => 'mysql',
'host' => 'revailment.db.9860920.hostedresource.com',
'database' => 'revailment',
'username' => 'revailment',
'password' => 'password',
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
),
Am hoping that this will also be of help to anyone who may encounter such issue in the Future.
I just have a database issue on my project/app/config/database.php. I want to my application can change its database when detecting its database environment. For example, if application is develop in local database, the database setting are all local parameter. If it detect that the database is on the remote server, it changes into remote database settings.
'mysql' => array(
'driver' => 'mysql',
'host' => $_ENV['DB_HOST'],
'database' => $_ENV['DB_NAME'],
'username' => $_ENV['DB_USER'],
'password' => $_ENV['DB_PASSWORD'],
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => 'laravel_',
),
I've solved the problem, however, not by adding local folder in to config folder as the document said.
I check the article Working with Configuration in Laravel 4, it is useful if you use .env.local.php to protect you local database configuration.
I need my Laravel project to use a database that is on a virtual machine on another network.
I know there's two database configuration on
app/config
app/config/local
I'm using MySql, how should I configure the database.php file?
Right now is configured to my local:
'mysql' => array(
'driver' => 'mysql',
'host' => 'localhost',
'database' => 'db_name',
'username' => 'root',
'password' => 'the_password',
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
),
You should specify remote MySQL server host IP address in database.php configuration.
Also you need to make sure you have enable remote connection to your MySQL database (normaly most MySQL servers are restricted to connections only from localhost). For this purpose you will need to create new database user with the following command
GRANT ALL PRIVILEGES ON *.* TO 'USERNAME'#'IP' IDENTIFIED BY 'PASSWORD';
Where you put IP of the server where you laravel installation is located.
Also after that you must execute
FLUSH PRIVILEGES;
And the you can connect to remote database.
I am having issues trying to work with a Cloud SQL instance and Laravel. I was able to do local dev work on a Cloud SQL instance with Python but I can't seem to get it with PHP.
Here is the error I get:
SQLSTATE[HY000] [2002] Can't connect to local MySQL server through socket '/cloudsql/project:instance-db'
Here is my app/config/database.php:
<?php
return array(
'fetch' => PDO::FETCH_CLASS,
'default' => 'mysql',
'connections' => array(
'mysql' => array(
'driver' => 'mysql',
'unix_socket' => '/cloudsql/my-project:instance-id',
'host' => '',
'database' => 'my_database',
'username' => 'root',
'password' => '',
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
),
),
'migrations' => 'migrations',
);
It all works when deployed just not locally.
You cannot connect to CloudSQL from your local machine right now. For testing you should use a local MySQL instance the CloudSQL instance when running in production.
You should be able to assign an IP address to your Cloud SQL instance and allow your own network to access the instance in the management console.
Assigning an IP address will cost extra.