0

I'm trying to connect my website with a database using PHP. My website is currently displaying this error:

SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES)

This is my .env file config:

DB_DRIVER=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_NAME=my_db_name
DB_USER=root
DB_PASS=my_db_password
DB_CHARSET=utf8mb3
DB_COLLATION=utf8mb3_general_ci

I created that database manually with MySQL command line and I can establish connection with it with navicat 15 using the credentials I established in MySQL command line. But for some reason my website cant connect to the database. I want it to be able to connect to the database so my website is usable. Thanks in advance

Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197
  • 1
    A lot of modern MySQL installations will not allow `root` connections from non-`sudo` requests. It would be better to create an account — even if it has full admin permissions — and use that to connect. – matigo Aug 29 '21 at 03:31
  • Please [edit] your question to include the content of the query `SELECT host, user, plugin FROM mysql.user`, which will show the user accounts you have. Also show how your PHP script is using these variables to connect to your MySQL database. It looks like it uses a TCP/IP login, but you have only configured a MySQL user account which uses pipe/socket for the login. – Progman Aug 29 '21 at 07:46
  • Does this answer your question? [Are Users 'User'@'%' and 'User'@'localhost' not the same?](https://stackoverflow.com/questions/11634084/are-users-user-and-userlocalhost-not-the-same) – Progman Aug 29 '21 at 07:47

0 Answers0