phpmyadmin connects databases on multiple servers at the same time

Keywords: phpMyAdmin MySQL PHP Database

1. Scenarios for use

In general, there are test environments and formal environments for our development.Of course, databases are also separate.If you could use phpmyadmin to directly access mysql on both servers.This is the need.

2. Solutions

1. Find under the phpmyadmin folderConfig.sample.inc.php, renamedConfig.inc.php.

2. OpenConfig.inc.phpAnd we'll see that there are some basic configurations that connect to localhost.

3. How to connect to a single remote server

//Test Server Database Profile
$cfg['Servers'][$i]['auth_type'] = 'config';
$cfg['Servers'][$i]['host'] = 'Long-range ip';
$cfg['Servers'][$i]['user'] = 'username';
$cfg['Servers'][$i]['password'] = 'pwd';
$cfg['Servers'][$i]['extension'] = 'mysqli';
$cfg['Servers'][$i]['AllowNoPassword'] = true;
$cfg['Lang'] = '';

I achieve the purpose of connecting remotely locally by writing remote ip etc. directly in the configuration file.

4. How to connect to multiple remote servers

//Here you stitch the username, password, etc. of the remote server into a multidimensional array
$connect_hosts = array(
  '1'=>array(
    "host"   => "localhost",  //Local Server
    "user"   => "root",
    "password" => ""
  ),
  '2' => array(
    "host"   => "The server IP", //Server 1
    "user"   => "username",
    "password" => "pwd"
  ),
  '3' => array(
    "host"   => "The server ip", //Server 2
    "user"   => "username",
    "password" => "pwd"
  )
);

for ($i=1;$i<=count($connect_hosts);$i++) {

  /* Authentication type */
  $cfg['Servers'][$i]['auth_type'] = 'cookie';
  /* Server parameters */
  $cfg['Servers'][$i]['host'] = $connect_hosts[$i]['host'];   //Modify host
  $cfg['Servers'][$i]['connect_type'] = 'tcp';
  $cfg['Servers'][$i]['compress'] = false;
  /* Select mysqli if your server has it */
  $cfg['Servers'][$i]['extension'] = 'mysql';
  $cfg['Servers'][$i]['AllowNoPassword'] = true;
  $cfg['Servers'][$i]['user'] = $connect_hosts[$i]['user'];  //Modify User Name
  $cfg['Servers'][$i]['password'] = $connect_hosts[$i]['password']; //Password
  /* rajk - for blobstreaming */
  $cfg['Servers'][$i]['bs_garbage_threshold'] = 50;
  $cfg['Servers'][$i]['bs_repository_threshold'] = '32M';
  $cfg['Servers'][$i]['bs_temp_blob_timeout'] = 600;
  $cfg['Servers'][$i]['bs_temp_log_threshold'] = '32M';

}

Note here:
(1) for loop, i should start from 1, do not start from 0 (2) There is a'i = 0'in the configuration file, remember to comment it out.That is, comment out unrelated code

3. Result Display

1. Local input: localhost/phpmyadmin

Here we select the server we want to connect to.

2. Switch between server databases after login

OK, now our phpmyadmin can connect to more than one database.

Reference link: http://blog.51yip.com/mysql/1250.html
end

Posted by jpaloyo on Wed, 15 Jul 2020 08:48:28 -0700