配置phpmyadmin链接多实例MySQL

配置phpmyadmin链接多实例MySQL

步骤总结

  1. 下载phpmyadmin
  2. 配置phpmysql的配置文件
  3. 全部库有帐号经过远程链接MySQL(mysql的grant受权)
  4. 登陆测试(若是有作数据库的主从要检查用户受权,防止数据的不一致)

环境说明

Linux版本于内核号     CentOS release 6.5 (Final) 2.6.32-431.el6.x86_64
PHP版本             5.3.28
Phpmyadmin版本        phpMyAdmin-4.4.15-all-languages
MySQL多实例         192.168.0.200:3307和192.168.0.200:3308(其中3307为master 3308为slave)

具体操做

方法一

经过修改 phpmyadmin/libraries/config.default.php 大概在805行的$cfg['AllowArbitraryServer'] = true; # allow login to any user entered server in cookie based authentication,效果以下图: 
 
进行登陆,固然这种方式依然得方法一中第四步的受权,这里就不在赘述。(此方法测试未成功,继续关注)php

总结

缺点:登录操做比较繁琐,并且切换服务器时须首先退出当前所登录的服务器mysql

方法二

1. 下载phpmyadmin

https://www.phpmyadmin.net/downloads/下载phpMyAdmin-4.4.15-all-languages,解压到网站根目录下重命名为phpmyadminsql

2. 编辑配置文件

cp config.sample.inc.php config.inc.php 复制根目录下的config.sample.inc.phpconfig.inc.php,使用 sed -i '22,34s#^#//#g' config.inc.php使用sed命令注释掉以前相关行并编辑这个文件,添加一个$hosts数组和一个for循环,以下:数据库

// /*
//  * First server
//  */
// $i++;
// /* Authentication type */
// $cfg['Servers'][$i]['auth_type'] = 'cookie';
// /* Server parameters */
// $cfg['Servers'][$i]['host'] = 'localhost';
// $cfg['Servers'][$i]['connect_type'] = 'tcp';
// $cfg['Servers'][$i]['compress'] = false;
// /* Select mysql if your server does not have mysqli */
// $cfg['Servers'][$i]['extension'] = 'mysqli';
// $cfg['Servers'][$i]['AllowNoPassword'] = false;

$hosts = array(
'1'=>array('host'=>'192.168.0.200','user'=>'phpmyadmin','password'=>'phpmyadmin','port'=>3307),
'2'=>array('host'=>'192.168.0.200','user'=>'phpmyadmin','password'=>'phpmyadmin','port'=>3308)
);

for($i=1,$j=count($hosts);$i<=$j;$i++){
    /* Authentication type */
    $cfg['Servers'][$i]['auth_type'] = 'cookie';
    /* Server parameters */
    $cfg['Servers'][$i]['host'] = $hosts[$i]['host'];   //修改host
    $cfg['Servers'][$i]['port'] = $hosts[$i]['port']; 
    $cfg['Servers'][$i]['connect_type'] = 'tcp';
    $cfg['Servers'][$i]['compress'] = false;
    /* Select mysqli if your server has it */
    $cfg['Servers'][$i]['extension'] = 'mysqli';
    $cfg['Servers'][$i]['AllowNoPassword'] = true;
    $cfg['Servers'][$i]['user'] = $hosts[$i]['user'];  //修改用户名
    $cfg['Servers'][$i]['password'] = $hosts[$i]['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';
}

更改完成后刷新登陆页面,发现是否是多了些什么?咱们能够选择不一样的服务器(或者不一样的端口)进行登陆了。以下图: 
数组

3. 登陆到服务器受权不一样的登陆帐号

因为这边192.168.0.200:3307为master,咱们在3307端口上进行受权: 
grant all privileges on *.* to 'phpmyadmin'@'192.168.0.%' identified by 'phpmyadmin' WITH GRANT OPTION; 
若是3307和3308已经实现了主从同步,那么咱们能够经过用户名为phpmyadmin和密码为 phpmyadmin登陆了,可是这样受权是十分不安全的。建议在生产环境中不要这么粗暴的使用,另外咱们须要对slave实例进行回收权限,登陆192.168.0.3308,操做以下: 
REVOKE INSERT,ALTER,CREATE,DELETE,DROP,UPDATE ON *.* FROM 'phpmyadmin'@'192.168.0.%'安全

另能够经过show privileges;查看更多受权权限以及相关做用。 
效果以下: 
 
相关的增删改操做提示无权限,防止用户误操做引发的主从同步数据的不一致。(这里也能够配置mysql库的主从不一样步,而后分别在3307和3308端口上授予用户不一样的权限便可)。服务器

总结

优势:登录操做简便,登录后切换服务器无须退出当前链接。cookie

相关文章
相关标签/搜索