如何禁用对 PhpMyAdmin 的 root 登录访问
如果您计划定期使用phpmyadmin通过网络(或更糟糕的是通过互联网!)来管理数据库,则您不想使用root 帐户。这不仅适用于 phpmyadmin,也适用于任何其他基于 Web 的界面。
在 /etc/phpmyadmin/config.inc.php
中,查找以下行并确保 AllowRoot
指令设置为 FALSE:
$cfg['Servers'][$i]['AllowRoot'] = FALSE;
在 Ubuntu/Debian 中,您需要添加如下两行:
/* Authentication type */
$cfg['Servers'][$i]['auth_type'] = 'cookie';
$cfg['Servers'][$i]['AllowRoot'] = false;
保存更改并重新启动 Apache。
------------- On CentOS/RHEL Systems -------------
systemctl restart httpd.service
------------- On Debian/Ubuntu Systems -------------
systemctl restart apache2.service
然后按照上述提示中概述的步骤进入 phpmyadmin 登录页面 (https://
) 并尝试以 root 身份登录:
然后通过命令提示符连接到您的 MySQL/MariaDB 数据库,并使用 root 凭据,根据需要创建多个帐户以访问每个数据库。在本例中,我们将创建一个名为 jdoe 的帐户,密码为 jdoespassword:
mysql -u root -p
Enter password:
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 24
Server version: 10.1.14-MariaDB MariaDB Server
Copyright (c) 2000, 2016, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]> CREATE USER 'jdoe'@'localhost' IDENTIFIED BY 'jdoespassword';
Query OK, 0 rows affected (0.04 sec)
MariaDB [(none)]> GRANT ALL PRIVILEGES ON gestion.* to 'jdoe'@'localhost';
Query OK, 0 rows affected (0.00 sec)
然后让我们使用上述凭据登录。如您所见,该帐户只能访问一个数据库:
恭喜!您已禁用对 phpmyadmin 安装的 root 访问权限,现在可以使用它来管理您的数据库。
我强烈建议您使用 .htaccess 密码保护为 phpmyadmin 安装添加额外的安全层,并设置 HTTPS(SSL 证书)以避免发送用户名和密码 通过网络以纯文本格式。