PHPMyAdmin 是一个基于 Web 的 MySQL 数据库管理工具。要正确配置 PHPMyAdmin 连接 MySQL,请按照以下步骤操作:
编辑配置文件:
config.inc.php
,通常位于:
/etc/phpmyadmin/config.inc.php
(Linux)C:\xampp\phpMyAdmin\config.inc.php
(Windows XAMPP)设置认证方式:
$cfg['Servers'][$i]['auth_type'] = 'cookie'; // 推荐使用cookie认证
配置MySQL连接:
$cfg['Servers'][$i]['host'] = 'localhost'; // MySQL服务器地址
$cfg['Servers'][$i]['connect_type'] = 'tcp'; // 连接类型
$cfg['Servers'][$i]['compress'] = false; // 是否使用压缩协议
$cfg['Servers'][$i]['AllowNoPassword'] = false; // 是否允许空密码登录
$cfg['Servers'][$i]['auth_type'] = 'config';
$cfg['Servers'][$i]['user'] = 'root'; // MySQL用户名
$cfg['Servers'][$i]['password'] = 'your_password'; // MySQL密码
$cfg['Servers'][$i]['auth_type'] = 'cookie';
// 用户将在登录页面输入凭据
$cfg['Servers'][$i]['host'] = 'remote.mysql.server.com';
$cfg['Servers'][$i]['port'] = '3306'; // 指定端口
$i++;
$cfg['Servers'][$i]['host'] = 'second.mysql.server';
$cfg['Servers'][$i]['port'] = '3306';
$cfg['Servers'][$i]['auth_type'] = 'cookie';
确保MySQL用户有足够的权限:
GRANT ALL PRIVILEGES ON *.* TO 'username'@'localhost' IDENTIFIED BY 'password';
FLUSH PRIVILEGES;
完成配置后,通过浏览器访问PHPMyAdmin的URL(通常是 http://your-server/phpmyadmin
)即可使用。