本文档旨在解决 phpMyAdmin 中无法显示多个服务器的问题。通过修改 config.inc.php 文件,利用循环结构配置多个服务器连接,并提供详细的配置示例,确保用户能够在登录界面选择不同的数据库服务器,从而方便地管理多个数据库实例。
phpMyAdmin 允许您管理多个 MySQL 或 MariaDB 服务器。默认情况下,它可能只配置为连接到一个服务器。要启用服务器选择下拉列表,您需要编辑 phpMyAdmin 的配置文件 config.inc.php。
步骤 1: 找到 config.inc.php 文件
该文件的位置取决于您的 phpMyAdmin 安装方式和操作系统。常见的路径包括:
立即学习“PHP免费学习笔记(深入)”;
步骤 2: 编辑 config.inc.php 文件
使用文本编辑器打开 config.inc.php 文件。您需要添加或修改 $cfg['Servers'] 数组来定义您的服务器。
配置方法:使用循环
推荐使用循环来配置多个服务器,这使得配置更加简洁和易于维护。以下是一个示例配置:
<?php $i = 0; $hosts = [ '172.18.0.1:3307', 'localhost' ]; foreach($hosts as $host) { $i++; $cfg['Servers'][$i]['host'] = $host; $cfg['Servers'][$i]['port'] = ''; // 留空使用默认端口 $cfg['Servers'][$i]['socket'] = ''; // 留空使用默认 socket $cfg['Servers'][$i]['connect_type'] = 'tcp'; $cfg['Servers'][$i]['extension'] = 'mysqli'; $cfg['Servers'][$i]['compress'] = FALSE; $cfg['Servers'][$i]['controluser'] = 'pma'; // phpMyAdmin 控制用户 $cfg['Servers'][$i]['controlpass'] = 'pmapass'; // phpMyAdmin 控制用户密码 $cfg['Servers'][$i]['auth_type'] = 'cookie'; // 认证类型,可选 'cookie', 'config', 'http' 等 $cfg['Servers'][$i]['user'] = ''; // MySQL 用户名,如果 auth_type 为 'config',则必须设置 $cfg['Servers'][$i]['password'] = ''; // MySQL 密码,如果 auth_type 为 'config',则必须设置 $cfg['Servers'][$i]['only_db'] = ''; // 限制用户只能访问的数据库 $cfg['Servers'][$i]['verbose'] = 'Server ' . $i; // 服务器的显示名称 $cfg['Servers'][$i]['pmadb'] = 'phpmyadmin'; // phpMyAdmin 数据库 $cfg['Servers'][$i]['bookmarktable'] = 'pma_bookmark'; $cfg['Servers'][$i]['relation'] = 'pma_relation'; $cfg['Servers'][$i]['table_info'] = 'pma_table_info'; $cfg['Servers'][$i]['table_coords'] = 'pma_table_coords'; $cfg['Servers'][$i]['pdf_pages'] = 'pma_pdf_pages'; $cfg['Servers'][$i]['column_info'] = 'pma_column_info'; $cfg['Servers'][$i]['history'] = 'pma_history'; $cfg['Servers'][$i]['designer_coords'] = 'pma_designer_coords'; } ?>
配置项说明:
步骤 3: 调整权限(如果需要)
确保 phpMyAdmin 能够读取 config.inc.php 文件。如果遇到权限问题,您可能需要更改文件的所有者或权限。
步骤 4: 重启 Web 服务器
为了使配置生效,请重启您的 Web 服务器(例如 Apache 或 Nginx)。
步骤 5: 验证配置
打开 phpMyAdmin,您应该看到一个服务器选择下拉列表,其中包含您配置的所有服务器。
注意事项:
总结:
通过修改 config.inc.php 文件,并使用循环结构配置多个服务器,您可以轻松地在 phpMyAdmin 中管理多个 MySQL 或 MariaDB 服务器。记住要关注安全性,并确保正确配置了所有必要的参数。
以上就是配置 phpMyAdmin 显示多个服务器的详细内容,更多请关注php中文网其它相关文章!
PHP怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号