Jump to content

Laravel and database issues

Joveice

Hello, I'm trying to run migrate and I'm getting this error

 

[Illuminate\Database\QueryException]
  SQLSTATE[HY000] [1045] Access denied for user 'user'@'ip'
  (using password: YES) (SQL: select * from information_schema.tables where t
  able_schema = database and table_name = migrations)



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

I have the name of the database, the password and the username in a txt document and I'm copying it to the .env file.

I can login using phpmyadmin just fine by copying it the same way and then I can edit the database just as I should be able to.

 

I have never used Laravel before and I'm currently trying to learn it. Using Laravel 5.4

Back-end developer, electronics "hacker"

Link to comment
Share on other sites

Link to post
Share on other sites

I think you renamed the user and ip address when you posted this. if the error really contains as user = user and ip = ip then thats wrong.

Else the user you try to login with has not the right privileges to the database you are connecting.

 

If you do a quick google search on "mysql 1045" you can see a bit how to troubleshoot this :)

Quote or mention me if not feel ignored 

Link to comment
Share on other sites

Link to post
Share on other sites

It might be the user Privileges!

Maybe update the Privileges!

~$ mysql -u root -p
mysql> grant all privileges on *.* to 'user'@'ip' identified by 'password' with grant option;

 

Business Management Student @ University St. Gallen (Switzerland)

HomeServer: i7 4930k - GTX 1070ti - ASUS Rampage IV Gene - 32Gb Ram

Laptop: MacBook Pro Retina 15" 2018

Operating Systems (Virtualised using VMware): Windows Pro 10, Cent OS 7

Occupation: Software Engineer

Link to comment
Share on other sites

Link to post
Share on other sites

2 hours ago, Cruorzy said:

I think you renamed the user and ip address when you posted this. if the error really contains as user = user and ip = ip then thats wrong.

Else the user you try to login with has not the right privileges to the database you are connecting.

 

If you do a quick google search on "mysql 1045" you can see a bit how to troubleshoot this :)

 

1 hour ago, leodaniel said:

It might be the user Privileges!

Maybe update the Privileges!


~$ mysql -u root -p
mysql> grant all privileges on *.* to 'user'@'ip' identified by 'password' with grant option;

 

But I can connect anywere else, it's just here it doesent work.

Back-end developer, electronics "hacker"

Link to comment
Share on other sites

Link to post
Share on other sites

14 minutes ago, Joveice said:

 

But I can connect anywere else, it's just here it doesent work.

I changed login stuff to the root, that also dident work. Might it be caused by that I use mariadb? some say that I shouldent need to configure to it as it's the same as mysql

Back-end developer, electronics "hacker"

Link to comment
Share on other sites

Link to post
Share on other sites

Its all running on one computer and not all in seperated VM's? 

MariaDB shouldnt be a problem since its a fork of MySQL.

 

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=DBNAME
DB_USERNAME=root
DB_PASSWORD=root

 

.env looks something like this?

Quote or mention me if not feel ignored 

Link to comment
Share on other sites

Link to post
Share on other sites

Just now, Cruorzy said:

Its all running on one computer and not all in seperated VM's? 

MariaDB shouldnt be a problem since its a fork of MySQL.

 

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=DBNAME
DB_USERNAME=root
DB_PASSWORD=root

 

.env looks something like this?

Yes, The database is running on the main server, and other applications that are both hosted outside the server or on it works just like they should, and the user I gave to it works just as it should too.

Back-end developer, electronics "hacker"

Link to comment
Share on other sites

Link to post
Share on other sites

But when you access the website you dont get an error, only when running migrate?

Quote or mention me if not feel ignored 

Link to comment
Share on other sites

Link to post
Share on other sites

Just now, Cruorzy said:

But when you access the website you dont get an error, only when running migrate?

I have not setup anything on the website as I'm not able to get it to use the database

Back-end developer, electronics "hacker"

Link to comment
Share on other sites

Link to post
Share on other sites

Mind getting a new laravel project with 

laravel new test

And setup the root account in the .env

Also check if there exists a root account with the wildcard "%" as host.

If you did mysql_secure_installation you might have removed some of the accounts that makes it possible to connect from anywhere.

 

You probably did this already, but atleast make a new laravel project just for testing.

Else you can PM me some screenshots atleast, maybe that helps! :D

Quote or mention me if not feel ignored 

Link to comment
Share on other sites

Link to post
Share on other sites

Okey so we tryed to create a new project and test again and no luck.

 

I tryed to login to the database from the server "mysql -u myuser -p" then giving the same password, and it worked.

 

Laravel = Did not work.

Normal PHP mysqli = Worked.

Direct login = Worked.

PhpMyAdmin = Worked.

 

Anyone else got any ideas?

Back-end developer, electronics "hacker"

Link to comment
Share on other sites

Link to post
Share on other sites

Okey, so I ran the commands under 3 times then it worked

 

php artisan cache:clear
php artisan config:clear

Then php artisan migrate

 

I'm keeping this post as unsolved as I have no idea what made this happen therfor I have no controll on this.

Back-end developer, electronics "hacker"

Link to comment
Share on other sites

Link to post
Share on other sites

Oh sjiet, i ran by that post on stack overflow and was like naaah that cant be it.

Derp. but nice :)

Quote or mention me if not feel ignored 

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×