mysql router connection with php

Viewed 480

I have created Innodb cluster environment of mysql Ver 8.0.21 for Linux on x86_64 (MySQL Community Server - GPL) with 1 Read / Wirte and 2 read only for load balancing and performance, Also installed mysql router. Databases and cluster management is ok through putty on mysql router. Problem is that what will be the connection string in database.php for PHP 7.0.33. How to define php database connection for mysql router or is there any other way to use this cluster environment with php. I am unable to find any stuff on internet.

1 Answers

When you installed the mysql router it gave you the host and port for several types of connections, something like this:

the cluster 'myCluster' can be reached by connecting to:

MySQL Classic protocol

  • Read/Write Connections: localhost:6446
  • Read/Only Connections: localhost:6447

MySQL X protocol

  • Read/Write Connections: localhost:64460
  • Read/Only Connections: localhost:64470

If you are just playing with the stuff use the one for Read/Write Connections on MySQL Classic protocol, so:

$mysql_host = "localhost:6446"; 

(in my example, yours could differ, also the host could be remote, just put the ip or hostname instead of localhost.)

Use the username and password of the mysql admin account you created when you first ran the dba.configureLocalInstance(); script, if you elected to use root user for the instance, use "root" with its password then.

I made all three the same exact username and passwords so I just used those, If yours are different for each instance you can try with the ones you have for the instance that is the master at the moment, you can see which one is the master with cluster.status(), it is the one with R/W mode.

Related