Yii2 Read Write splitting couldn't connect slave server in master slave configuration - yii2

Have done Master Slave configuration as per official Yii2 documentation. Below is actual configuration look like,
'db' => [
'class' => 'yii\db\Connection',
'dsn' => 'mysql:host=1.1.1.1;dbname=master_db',
'username' => 'user',
'password' => 'password',
'charset' => 'utf8',
'enableSchemaCache' => true,
'schemaCacheDuration' => 10,
'schemaCache' => 'cache',
'slaveConfig' => [
'username' => 'slave_user',
'password' => 'slave_password',
'charset' => 'utf8',
'attributes' => [
// use a smaller connection timeout
PDO::ATTR_TIMEOUT => 10,
],
'enableSchemaCache' => true,
'schemaCacheDuration' => 10,
'schemaCache' => 'cache',
],
'slaves' => [
['dsn' => 'mysql:host=2.2.2.2;dbname=slave_db']
],
],
It always connect master database even if slave server is up and reachable.
Surprisingly replacing current master config with slave one works, moreover if try to connect slave database from command line it get connected in a moment but unable to achieve same with above configuration.
Wondering if there is any parameters missing in configuration or any other way to get things working like ideal read write splitting?

issue was resolved by adding connection class in the slaveConfig,
'class' => 'yii\db\Connection'

Related

TYPO3: Access denied to database after moving installation

I have migrated successfully my TYPO3 v10 site under mampp. Now I get this exception:
Doctrine\DBAL\Exception\ConnectionException An exception occurred in driver: Access denied for user 'dbxx'#'localhost'
My configuration entry is the following:
'DB' => [
'Connections' => [
'Default' => [
'charset' => 'utf8mb4',
'dbname' => 'mysite_f10',
'driver' => 'mysqli',
'host' => 'localhost',
'password' => 'root',
'tableoptions' => [
'charset' => 'utf8mb4',
'collate' => 'utf8mb4_unicode_ci',
],
'user' => 'root',
],
],
],
Is it possible, that TYPO3 stores still my old database values in a cache? And if, how can I clear my cache manually?
Database credentials are not cached anywhere. I assume that you changed the values in LocalConfiguration.php. You should check your installation if there is a file called AdditionalConfiguration.php in the same directory as LocalConfiguration.php. All values in that file overwrite values from LocalConfiguration.php.

How can I use an existing database with the advanced template of Yii2?

I installed the yii2 advanced template, and I'm now at migration point where I should create a new database and migrate the app to it.
but I already have a database full of data and I want to use it with yii2 without modifying anything
Open the file
common/config/main.php
and add the parameters for your database connection
<?php
return [
'components' => [
'db' => [
'class' => 'yii\db\Connection',
'dsn' => '',
'username' => '',
'password' => '',
'charset' => 'utf8',
],
],
];

Master Slave Configuration in Laravel 5.5

How to configure Laravel 5.5 with master slave MySQL replication ?
I want to make write operations and read operations in master and slave respectively .
Optional: Is there any way to do connection pooling and max / min no of open connections in ideal conditions. ?
Just change your config/database.php file to include read (slave) and write (master) hosts like so like the Laravel docs suggest:
'mysql' => [
'read' => [
'host' => '192.168.1.1',
],
'write' => [
'host' => '196.168.1.2'
],
'sticky' => true,
'driver' => 'mysql',
'database' => 'database',
'username' => 'root',
'password' => '',
'charset' => 'utf8mb4',
'collation' => 'utf8mb4_unicode_ci',
'prefix' => '',
],

Does yii2 have persistent connection options?

I can't find documentation about Yii2 persistent connection.
I have problems with Yii2 behavior. It always opens the connection and closes it after executing the query. I think creating a persistent connection is the answer to my problems.
How to do that?
See the following github issue:
'db' => array(
'class' => 'yii\db\Connection',
'dsn' => 'mysql:host=localhost;dbname=dbname',
'username' => 'root',
'password' => '',
'tablePrefix' => '',
'charset' => 'utf8',
'attributes'=>[
PDO::ATTR_PERSISTENT => true
]
),

Setting up a database for Yii 2

I need to install an app written in Yii 2 on my local computer. I installed composer and initiated the app with:
php /path/to/yii-application/init
Now I need to "create a new database and adjust the components['db'] configuration in common/config/main-local.php accordingly."
I have no clue how to do that.
1) Create database on your server.
2) Open common/config/main-local.php
Edit components to:
'components' => [
'db' => [
'class' => 'yii\db\Connection',
'dsn' => 'mysql:host=localhost;dbname=DATABASE_NAME',
'username' => 'DATABASE_USER',
'password' => 'DATABASE_PASSWORD',
'charset' => 'utf8',
],
If using MAMP with mac then edit dsn line to :
'dsn' => 'mysql:unix_socket=/Applications/MAMP/tmp/mysql/mysql.sock;dbname=DATABASE_NAME'