phpMyAdmin无法连接到MySQL服务器。

4
我真的需要帮助来修复这个错误,因为下周一是我的毕业项目展示,请帮忙。我不知道该如何解决这个问题。
我已经尝试遵循此http://www.ishaanrawat.com/solved-wampserver-1045-access-denied-for-user-rootlocalhost-using-password-no/指示,但我收到了相同的错误。
几分钟前,我卸载了wamp server,希望重新安装后可以正常使用我的wamp server,但仍然出现了相同的错误。
以下是错误信息:
MySQL 说:文档

1045 - 用户'root'@'localhost'被拒绝访问(使用密码: NO)

phpMyAdmin试图连接MySQL服务器,但服务器拒绝了连接。您应该检查配置中的主机、用户名和密码,并确保它们与MySQL服务器管理员提供的信息相符。

2
你能给我们看一下你的连接字符串吗? - Thanos Markou
@ThanosMarkou:我不确定连接字符串在哪里,您想查看的是config.inc文件吗? - Jasmine Ziz
你使用的是哪个操作系统?是Ubuntu吗? - MrYo
你能否在命令行上使用root用户且不需要密码连接到数据库? - Jens
我正在使用Windows 7 @SanjayaPandey - Jasmine Ziz
显示剩余3条评论
7个回答

8

您可以观看以下视频以解决您的问题:
http://www.youtube.com/watch?v=BgcW4h6ZAro&t=7m21s
p/s:这是越南视频 :)
config.inc.php文件中,您需要编辑以下代码:

* First server
 */
$i++;
/* Authentication type */
$cfg['Servers'][$i]['verbose'] = 'mysql wampserver';
//uncomment this
$cfg['Servers'][$i]['auth_type'] = 'cookie';
//comment this
//$cfg['Servers'][$i]['auth_type'] = 'config';
$cfg['Servers'][$i]['user'] = 'root';
$cfg['Servers'][$i]['password'] = '';
/* Server parameters */
$cfg['Servers'][$i]['host'] = '127.0.0.1';
$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'] = true;

退出wampserver,重新打开wampserver,打开PHPMyadmin,您将看到登录表格 :)

将“auth_type”更改为“cookie”,并显示登录表单。但仍无法使用root用户登录。 - lazzy_ms

3

进入XAMPP或WAMPS服务器中的phpMyAdmin文件夹,打开config.inc.php文件。将用户名和密码更改为您在数据库中设置的内容。

 /* Authentication type and info */
$cfg['Servers'][$i]['auth_type'] = 'config';
$cfg['Servers'][$i]['user'] = 'root';
$cfg['Servers'][$i]['password'] = '';
$cfg['Servers'][$i]['extension'] = 'mysqli';
$cfg['Servers'][$i]['AllowNoPassword'] = true;
$cfg['Lang'] = '';

2

这对我很有用。在安装WAMP之前,我已经在我的电脑中安装了MySQL。打开MySQL命令行客户端所需的密码是“pw”。现在,在安装WAMP之后,当我试图打开phpMyAdmin时,它会给出与您相同的错误。如何解决:

  1. 打开C:\ wamp \ apps \ phpmyadmin4.1.14 \ config.inc.php
  2. 找到以下几行:

    $cfg ['Servers'] [$i] ['user'] ='root';
      $cfg ['Servers'] [$i] ['password'] ='';
      / *服务器参数 /
      $cfg ['Servers'] [$i] ['host'] ='127.0.0.1';
      $cfg ['Servers'] [$i] ['connect_type'] ='tcp';
      $cfg ['Servers'] [$i] ['compress'] = false;
      / 如果您的服务器没有mysqli,则选择mysql*/
      $cfg ['Servers'] [$i] ['extension'] ='mysqli';
      $cfg ['Servers'] [$i] ['AllowNoPassword'] = true;

  3. 将“ $cfg [ 'Servers'] [$i] ['AllowNoPassword'] = true;”更改为“ $cfg [ 'Servers'] [$i] ['AllowNoPassword'] = false;”。

  4. 将“ $cfg ['Servers'] [$i] ['password'] =''”更改为“ $cfg ['Servers'] [$i] ['password'] ='pw'”。(请记住用您的密码替换 'pw')。

  5. 重新启动WAMP中的所有服务,然后再次尝试打开phpMyAdmin。


1

首先在config.inc.php文件中把"AllowNoPassword"的值更改为false。 然后为root设置密码,最后登录phpMyAdmin。


在config.inc.php文件中,您应该定义“密码”,这是您为MySQL的root用户设置的密码。 - Sandeepa Rajoriya

0

解决方案是:

  1. 首先备份所有项目和数据库。

  2. 从您的系统(Ubuntu 16.04)中卸载 lampp

  3. 重新安装 lampp

  4. 打开 phpmyadmin。错误仍未被解决。

  5. 打开 phpmyadmin 文件夹下的 config.inc.php

  6. 更改以下行:

    /* Authentication type and info */
    $cfg['Servers'][$i]['auth_type'] = 'cookie';
    $cfg['Servers'][$i]['user'] = 'root';
    $cfg['Servers'][$i]['password'] = 'your password';
    
  • 现在保存文件(如果无法保存,则写入):

    sudo -H gedit /opt/lampp/phpmyadmin/config.inc.php
    
  • 重新启动您的 xampp 服务器。

  • 再次转到 localhost/phpmyadmin。尝试使用用户名 root 登录,并将密码字段留空。如果这不起作用,请使用您输入的密码登录。

  • 祝你好运!


    -2

    $cfg['Servers'][$i]['user'] = 'root'; $cfg['Servers'][$i]['password'] = 'root';

    使用默认的mySQL密码'root',这对我起作用了!!


    -3

    手动删除xampp并安装mysql、phpmyadmin、php5和apache2。

    1. sudo su
    2. apt-get install mysql-server mysql-client
    3. apt-get install apache2
    4. apt-get install php5 libapache2-mod-php5
    5. apt-cache search php5 根据需要选择并像这样安装: apt-get install php5-mysql php5-curl php5-gd php5-intl php-pear php5-imagick php5-imap php5-mcrypt php5-memcache php5-ming php5-ps php5-pspell php5-recode php5-snmp php5-sqlite php5-tidy php5-xmlrpc php5-xsl
    6. apt-get install phpmyadmin
    7. service apache2 restart
    8. 然后打开 http://127.0.0.1/phpmyadmin/

    这些命令将创建您的xampp服务器。它将快速解决您的问题并且运行非常平稳。 感谢相关文章:

    1. Ubuntu 14.10 LAMP服务器教程,包括Apache 2,PHP 5和MySQL(MariaDB)
    2. 如何更改Apache服务器的根目录?

    网页内容由stack overflow 提供, 点击上面的
    可以查看英文原文,
    原文链接