skip to Main Content

I am deploying a Laravel app to Azure (Web App + Mysql), so far I did the following steps :

1- Activated Mysql In App

2- Connected to BitBucket repository and made sure code was synced

3- Created .env file and set database variables as follows

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=port form Mysql connection string
DB_DATABASE=localdb
DB_USERNAME=azure
DB_PASSWORD=password form Mysql connection string

4- Ran php artisan config:cache

The Problem :

Running php artisan migrate returns this error :


  SQLSTATE[HY000] [1045] Access denied for user 'azure'@'localhost' (using pa  

  ssword: YES) (SQL: select * from information_schema.tables where table_sche  

  ma = localdb and table_name = migrations and table_type = 'BASE TABLE')      

Strange thing is,I ran SHOW GRANTS FOR CURRENT_USER In PhpMyadmin and it returned :
GRANT ALL PRIVILEGES ON *.* TO 'azure'@'localhost'

P.s : I got DB credentials from Kudu Debug Console and made sure there are no spaces before/after password or username

3

Answers


  1. change it from

    DB_CONNECTION=mysql
    DB_HOST=127.0.0.1
    DB_PORT=port form Mysql connection string
    DB_DATABASE=localdb
    DB_USERNAME=azure
    DB_PASSWORD=password form Mysql connection string
    

    to

    DB_HOST=localhost
    

    and test again

    Login or Signup to reply.
  2. This is a problem in Laravel version 7.9.* with the variable DB_PASSWORD in your .env file.
    If your password contains "#" Laravel will comment on every character after this symbol. For example, if your password is DB_PASSWORD = 85SF#G52a@ Laravel interprets it as DB_PASSWORD = 85SF ignoring the rest of the characters.

    SOLUTION
    Wrap the value of the DB_PASSWORD variable in double quotes like this:

    DB_PASSWORD="85SF#G52a@"
    

    It took me 2 days to found out the problem, I hope this could be helpful for someone who encounters the same problem.

    Login or Signup to reply.
  3. I encountered the same problem and while searching online, I came across your question. You can connect to the database using the user root instead of azure. The password for the user root is ‘password’. If you still want to grant all privileges to the user azure, you can do that using the credentials for the user root.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search