Warning: mysqli_connect(): (HY000/1045): Access denied for user 'username'@'localhost' (using password: YES)

前端 未结 21 2144
春和景丽
春和景丽 2020-11-22 06:31

Warning: mysqli_connect(): (HY000/1045): Access denied for user \'username\'@\'localhost\' (using password: YES) in C:\\Users\\xampp\\htdocs\\PHP_Login_Script

相关标签:
21条回答
  • 2020-11-22 07:25

    Use this

    After setup this you will not receive this issue again

    SET PASSWORD FOR root@localhost = PASSWORD('your_root_password');
    

    I was stuck up in this issue after used this query everything was solved

    0 讨论(0)
  • 2020-11-22 07:25

    Try the above answers 90% of the time this will be you issue. For me my problem was that my database password had a $ in it.

    $servername = '127.0.0.1';
    $username = 'user_bob';
    $password = 'sdfasdf$B';
    
    $conn = mysqli_connect($servername, $username, $password, 'any_database');
    
    //DO NOT USE DOUBLE QUOTES;
    //$password = "sdfasdf$B"; 
    
    0 讨论(0)
  • 2020-11-22 07:26

    The question has been answered above, Just to make you feel comfortable using all four string at the same time in a connection

    <?php
      define("DB_HOST", "localhost");
      define("DB_USER", "root");
      define("DB_PASSWORD", "");
      define("DB_DATABASE", "databasename");
    
      $db = new mysqli(DB_SERVER, DB_USERNAME, DB_PASSWORD, DB_DATABASE);
      // you could test connection eventually using a if and else conditional statement, 
      // feel free to take out the code below once you see Connected!
      if ($db) {
        echo "Connected!";
      } else {
        echo "Connection Failed";
      }
    ?>
    
    0 讨论(0)
  • 2020-11-22 07:29
    $db = mysqli_connect(DB_SERVER,DB_USERNAME,DB_PASSWORD,DB_DATABASE);
    
    Put " DB_HOST " instead of " DB_SERVER " also 
    put " DB_USER " Instead of " DB_USERNAME " 
    

    than it working fine !

    0 讨论(0)
  • 2020-11-22 07:30

    If youre running wamp update

    define("DB_HOST", "localhost");
    

    To your machines ip address (mine is 192.168.0.25);

    define("DB_HOST", "192.168.0.25");
    

    You can find it on window by typing ipconfig in your console or ifconfig on mac/linux

    0 讨论(0)
  • 2020-11-22 07:31

    you defIne as DB_USER but use as DB_USERNAME. Also php says username@localhost cant access. Not root@localhost.

    Change your define or connect paramater.

    0 讨论(0)
提交回复
热议问题