来源:http://www.ido321.com/1246.html
XAMPP(Apache+MySQL+PHP+PERL)是一个功能强大的建 XAMPP 软件站集成软件包,轻巧,用起来很方便。它提供了强大的phpmyadmin数据库管理工具,让使用者对数据库的使用和管理得心应手。对于不能在本地打开 phpmyadmin的问题,我的解决方案如下:
MySQL有一个默认的专用端口:3306,所以,如果你之前独立安装了MySQL,那么3306端口已经被占用。安装XAMPP集成的MySQL时,必须重新设置独立的端口,否则是不能访问phpmyadmin的,我收到的报错信息见图:
修改方法也很方便,打开XAMPP的控制面板,找到mysql右侧的config,点击,会出现my.ini的选择项,这个就是mysql的配置文件了,如图:
当然只是修改端口,我还是访问不了。还要去修改phpmyadmin的配置文件,这里有两个途径:
一、访问phpmyadmin出错的解决方案
1、打开xampp目录(默认的安装目录,如果修改,请找到xampp的安装目录),打开phpmyadmin的目录,在该目录下找到config.inc.php,我的默认配置:
<span><?php <span>/*</span> <span> * This is needed for cookie based authentication to encrypt password in</span> <span> * cookie</span> <span> */</span> $cfg[<span>'blowfish_secret'</span>] = <span>'xampp'</span>; <span>/* YOU SHOULD CHANGE THIS FOR A MORE SECURE COOKIE AUTH! */</span> <span>/*</span> <span> * Servers configuration</span> <span> */</span> $i = 0; <span>/*</span> <span> * First server</span> <span> */</span> $i++; <span>/* Authentication type and info */</span> $cfg[<span>'Servers'</span>][$i][<span>'auth_type'</span>] = <span>'config'</span>; $cfg[<span>'Servers'</span>][$i][<span>'user'</span>] = <span>'username'</span>; //mysql用户名 $cfg[<span>'Servers'</span>][$i][<span>'password'</span>] = <span>'password'</span>; //mysql密码 $cfg[<span>'Servers'</span>][$i][<span>'extension'</span>] = <span>'mysqli'</span>; //扩展配置,若访问出现没有配置mysqli等错误,加上这个。默认是有的 $cfg[<span>'Servers'</span>][$i][<span>'AllowNoPassword'</span>] = <span>true</span>; $cfg[<span>'Lang'</span>] = <span>''</span>; <span>/* Bind to the localhost ipv4 address and tcp */</span> $cfg[<span>'Servers'</span>][$i][<span>'host'</span>] = <span>'127.0.0.1'</span>; $cfg[<span>'Servers'</span>][$i][<span>'connect_type'</span>] = <span>'tcp'</span>; <span>/* User for advanced features */</span> $cfg[<span>'Servers'</span>][$i][<span>'controluser'</span>] = <span>'pma'</span>; $cfg[<span>'Servers'</span>][$i][<span>'controlpass'</span>] = <span>''</span>; <span>/* Advanced phpMyAdmin features */</span> $cfg[<span>'Servers'</span>][$i][<span>'pmadb'</span>] = <span>'phpmyadmin'</span>; $cfg[<span>'Servers'</span>][$i][<span>'bookmarktable'</span>] = <span>'pma_bookmark'</span>; $cfg[<span>'Servers'</span>][$i][<span>'relation'</span>] = <span>'pma_relation'</span>; $cfg[<span>'Servers'</span>][$i][<span>'table_info'</span>] = <span>'pma_table_info'</span>; $cfg[<span>'Servers'</span>][$i][<span>'table_coords'</span>] = <span>'pma_table_coords'</span>; $cfg[<span>'Servers'</span>][$i][<span>'pdf_pages'</span>] = <span>'pma_pdf_pages'</span>; $cfg[<span>'Servers'</span>][$i][<span>'column_info'</span>] = <span>'pma_column_info'</span>; $cfg[<span>'Servers'</span>][$i][<span>'history'</span>] = <span>'pma_history'</span>; $cfg[<span>'Servers'</span>][$i][<span>'designer_coords'</span>] = <span>'pma_designer_coords'</span>; $cfg[<span>'Servers'</span>][$i][<span>'tracking'</span>] = <span>'pma_tracking'</span>; $cfg[<span>'Servers'</span>][$i][<span>'userconfig'</span>] = <span>'pma_userconfig'</span>; $cfg[<span>'Servers'</span>][$i][<span>'recent'</span>] = <span>'pma_recent'</span>; $cfg[<span>'Servers'</span>][$i][<span>'table_uiprefs'</span>] = <span>'pma_table_uiprefs'</span>; <span>/*</span> <span> * End of servers configuration</span> <span> */</span> ?></span>
然后在$cfg['Lang'] = ”后加入以下代码:
<span>$cfg[<span>'Servers'</span>][$i][<span>'port'</span>] = <span>'3307'</span></span>
保存,重启apache,在地址栏输入localhost/phpmyadmin,就可以直接进入phpmyadmin的管理界面了
这种方式不太安全,没有验证,谁都可以进入phpmyadmin管理数据库了。重新回到配置文件,找到如下代码:
<span>$cfg[<span>'Servers'</span>][$i][<span>'auth_type'</span>] = <span>'config'</span></span>
将上述代码的config改为cookie,或者http,就会出现验证界面了(cookie和http对应的验证界面在windows上还不一样),我把它改成了cookie,出现如图验证界面
2、这种方式也是修改phpmyadmin的配置文件,不过路径不一样了,在phpmyadmin/libraries找到config.default.php文件,里面包含了服务器的各种配置参数
<span>$cfg[<span>'Servers'</span>][$i][<span>'port'</span>] = <span>''</span>;</span>
找到这一行代码,我的在132行,这个是配置端口的,值为空则是默认的3306,将其值改为3307后,保存,重启apache,同样可以访问phpmyadmin了
二、phpmyadmin配置文件详解
打开在phpmyadmin/libraries找到config.default.php文件,常用参数配置如下
<span>$cfg[<span>'PmaAbsoluteUri'</span>] = <span>''</span>; <span>//phpmyadmin的访问网址 ,默认就行</span> $cfg[<span>'TranslationWarningThreshold'</span>] = 80; <span>//服务器端口</span> $cfg[<span>'Servers'</span>][$i][<span>'host'</span>] = <span>'localhost'</span>;<span>//mysql主机ip,如果mysql和该phpmyadmin在同一服务器,则按默认localhost</span> $cfg[<span>'Servers'</span>][$i][<span>'port'</span>] = <span>'3307'</span>; <span>//mysql端口,默认3306,保留为空即可</span> $cfg[<span>'Servers'</span>][$i][<span>'user'</span>] = <span>'root'</span>; <span>//mysql用户名</span> $cfg[<span>'Servers'</span>][$i][<span>'password'</span>] = <span>''</span>;<span>//密码</span> $cfg[<span>'Servers'</span>][$i][<span>'auth_type'</span>] = <span>'cookie'</span>; <span>//认证方式</span> <span>/*端口、用户名、认证方式等也可以再config.inc.php中配置,并且优先级高</span> <span>*$cfg['Servers'][$i]['auth_type'] = 'config'; 这个是在config.inc.php的</span> <span>*配置,若不修改这个值,仍然可以直接访问phpmyadmin</span> <span>*/</span> $cfg[<span>'DefaultLang'</span>]=<span>'zh'</span>; <span>//设置默认语言</span> </span>
对于认证方式$cfg['Servers'][$i]['auth_type'] = ‘cookie'; 的值有四个:cookie,http,HTTP,config
config方式即输入phpmyadmin的访问网址即可直接进入,无需输入用户名和密码,是不安全的,不推荐使用。
当该项设置为cookie,http或HTTP时,登录phpmyadmin需要数据用户名和密码进行验证,,具体如下:
PHP安装模式为Apache,可以使用http和cookie;
PHP安装模式为CGI,可以使用cookie .
另外,在cookie模式下,还可以设置$cfg['blowfish_secret'] = ”; (短语密码) ,至于设置为什么密码,由您自己决定,也可以不用理会。(没测试过,这一点来自文档说明,我觉得不用理会就行了)
下一篇:怎么用PHP在HTML中生成PDF文件