SQLSTATE[HY000] [1045] Access denied for user 'homestead'@'localhost' (using password: YES) (SQL: select * from `table`)

前端 未结 2 841
天涯浪人
天涯浪人 2021-01-14 19:05

I am using Laravel, and I have already configured .env file. When I make migration and I migrate, it affects the database, but when I try to read from same database I get th

相关标签:
2条回答
  • 2021-01-14 19:41

    if its a new instalation or new upgrade for wampserver or xampp, You need to include your port into connection,

    Because the default MySQL Port is 3306,

    But mariadb comes as default on default (3306) port so, when you try to connect MySQL its redirecting to mariadb.

    You need to correct your port it might be 3306 or 3307 or 3308 and use ip instead of localhost. your final codes:

    $host = '127.0.0.1';
    $db   = 'test';
    $user = 'root';
    $pass = '';
    $port = '3308';
    $charset = 'utf8mb4';
    
    mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);
    try {
        $mysqli = mysqli_connect($host, $user, $pass, $port, $db);
        mysqli_set_charset($mysqli, $charset);
    } catch (\mysqli_sql_exception $e) {
         throw new \mysqli_sql_exception($e->getMessage(), $e->getCode());
    }
    

    Solved question here

    For pdo and docker :

    See these answers

    0 讨论(0)
  • 2021-01-14 19:53

    You have to set the right permissions:

    $ mysql -u root -p
    $ <your-password>
    $ use mysql
    $ GRANT ALL ON *.* to 'homestead'@'localhost' IDENTIFIED BY '<your-password>';
    $ FLUSH PRIVILEGES;
    
    0 讨论(0)
提交回复
热议问题