php mysql数据库1045访问被拒绝

时间:2016-06-12 18:50:41

标签: php mysql database mysqli

  

警告:mysqli :: mysqli():( HY000 / 1045):拒绝访问用户' root' @' localhost' (使用密码:YES)在第6行的C:\ wamp \ www \ mctr \ db.php中**

我试图在config.inc进行更改,互联网上的人确实已经修复但没有为我提供帮助。

尝试建立连接和创建表时出现此错误。

我的数据库连接

<?php
    $servername = "localhost";
    $username = "root";
    $password = " ";

    $conn = new mysqli($servername, $username, $password);

    if ($conn->connect_error) {
        die("1: " . $conn->connect_error);
    } 
    echo "2";
?>

我的创建表格文件

<?php
    require_once "db.php";
    $t = "CREATE TABLE uyeler (
        id INT(7) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
        isim VARCHAR(16) NOT NULL,
        kullanici_adi VARCHAR(15) NOT NULL,
        sifre VARCHAR(16) NOT NULL,
        email VARCHAR(50) NOT NULL,
        skype VARCHAR(20) NULL,
        uye_tipi enum('Üye','Yönetici','Kurucu') NOT NULL default 'Üye',
        UNIQUE KEY email (email),
        UNIQUE KEY kullanici_adi (kullanici_adi),
        tolpam_indirilme INT(7) NULL,
        aylik_indirilme INT(7) NULL,
        kayit_tarihi TIMESTAMP
    )";

    $querySonucu = mysql_query($t);

    if ($querySonucu === TRUE) {print "Basarili!";} else {print "Hata!";}
    mysql_close();
?>

我的config.inc.php

<?php
    /* Servers configuration */
    $i = 0;

    $cfg['blowfish_secret'] = 'a8b7c6d'; //What you want

    /* Server: localhost [1] */
    $i++;
    $cfg['Servers'][$i]['verbose'] = 'Local Databases';
    $cfg['Servers'][$i]['host'] = '127.0.0.1';
    $cfg['Servers'][$i]['extension'] = 'mysqli';
    $cfg['Servers'][$i]['auth_type'] = 'cookie';
    $cfg['Servers'][$i]['user'] = '';
    $cfg['Servers'][$i]['password'] = '';

    // Hidden databases in PhpMyAdmin left panel
    // $cfg['Servers'][$i]['hide_db'] = '(information_schema|mysql|performance_schema|sys)';

    // Allow connection without password
    $cfg['Servers'][$i]['AllowNoPassword'] = true;

    // Suppress Warning about pmadb tables
    $cfg['PmaNoRelation_DisableWarning'] = true;

    // To have PRIMARY & INDEX in table structure export
    $cfg['Export']['sql_drop_table'] = true;
    $cfg['Export']['sql_if_not_exists'] = true;

    $cfg['MySQLManualBase'] = 'http://dev.mysql.com/doc/refman/5.7/en/';
    /* End of servers configuration */
?>

2 个答案:

答案 0 :(得分:1)

在您的数据库连接文件中。确保您的密码设置为

$password = "";

而不是

$password = " ";

答案 1 :(得分:0)

您是否检查过密码?看来你正在使用&#34; &#34;,即一个空格。例如,对于标准配置的xampp,密码为空&#34;&#34;