Laravel - Migrations work but post requests throw "Access denied for user 'root'@'localhost'"

sqlstate(hy000) (1698)
unable to connect to zm db sqlstate hy000 1698 access denied for user 'zmuser'@'localhost
1698 - access denied for user 'root'@'localhost
mysqli_real_connect(): (hy000/1698): access denied for user 'root'@'localhost
could not connect to pdo sqlstate hy000 1698 access denied for user root localhost
mediawiki cannot access the database real_connect hy000 1698 access denied for user root localhost

I'm trying to put a project to production. I'm getting an access error when running an Axios post request to the Laravel API. (I'm not getting this error on the local machine)

[2019-01-28 12:18:04] local.ERROR: SQLSTATE[HY000] [1698] Access denied for user 'root'@'localhost' (SQL: select * from `oauth_clients` where `id` = 2 limit 1) {"exception":"[object] (Illuminate\\Database\\QueryException(code: 1698): SQLSTATE[HY000] [1698] Access denied for user 'root'@'localhost' (SQL: select * from `oauth_clients` where `id` = 2 limit 1) at /var/www/html/RemApp/vendor/laravel/framework/src/Illuminate/Database/Connection.php:664, PDOException(code: 1698): SQLSTATE[HY000] [1698] Access denied for user 'root'@'localhost' at /var/www/html/RemApp/vendor/laravel/framework/src/Illuminate/Database/Connectors/Connector.php:68)

I'm not getting an error when running migrations. Below is my .env file. (I have not changed the config/database.php)

  1. Tried clearing cache with:

    php artisan cache:clear
    php artisan config:clear
  2. Removed quotes from DB_PASSWORD

  3. The credentials are correct. (Can login and run queries using mysql -u -p)

Turns out this was related to: SQLSTATE[HY000] [1698] Access denied for user 'root'@'localhost'. Tried everything

For some reason a mysql root user cannot be used. To solve this you would need to create a new user. Below are the commands to create a new user and grant root privileges.

mysql -u root -p
CREATE USER 'username'@'localhost' IDENTIFIED BY 'password';
GRANT ALL PRIVILEGES ON *.* TO 'username'@'localhost';
service mysql restart

Now edit your .env to match the new user credentials. To be on the safe side you can reboot the server.

Error Handling - Laravel, Sometimes you may need to report an exception but continue handling the current request. The report helper function allows you to quickly report an exception  Each migration file name contains a timestamp, which allows Laravel to determine the order of the migrations. {tip} Migration stubs may be customized using stub publishing The --table and --create options may also be used to indicate the name of the table and whether or not the migration will be creating a new table.

If the db password is empty, don't put an empty string, leave it blank, as such, change:




otherwise, it passes those quotes as your password.

Edit #1

If you do have a password, then unquote it if it is quoted.

Making Requests, Getting Started · Query Builder · Pagination · Migrations · Seeding · Redis To make requests, you may use the get , post , put , patch , and delete methods. Laravel's HTTP client wrapper does not throw exceptions on client or server errors If you would like to fake a sequence of responses but do not need to specify a  Fix laravel migrations when migrating to sql server (dropColumn with default value) [6.0] Fix laravel migrations when migrating to sql server (dropColumn with default value) Jan 27, 2020 oranges13 mentioned this pull request Jan 27, 2020

First of all, using the root with empty password on production is dangers. You need to use a separate user with strong password or at least use strong password for root.

and clear cache on production

php artisan cache:clear
php artisan config:clear

All Post Method in laravel throwing 302, DO. everything configured but all POST requests are throwing 302 Found. Its working here but not here 165.227. I haven't been working with Laravel for some time, so I'm afraid I won't have any valuable input on migration atomicity. I do hope this will get fixed eventually though. @taylorotwell 's suggestion on making migrations more granular seems like a good workaround though.

Just set up correct Database credentials:

DB_DATABASE=        // Your Database Name
DB_USERNAME=       // Yout Database Username
DB_PASSWORD=      // Your Database Password

If no password is set on the database, clear it DB_PASSWORD, empty space must also be removed

After completion of .env edit, You can clear the configuration cache with the following artisan command: php artisan config:cache

you need also restart your server after changing your .env file values.

Laravel API Tutorial: Building & Testing a RESTful API, In this Laravel API tutorial, we explore the ways to build — and test — a robust The -m option is short for --migration and it tells Artisan to create one for our model. return Article::find($id); }); Route::post('articles', function(Request $​request) { return It's not perfect, but it's flexible enough to let you work around its issues. With the Laravel 5.6, you can specify maximum number of requests based on the attribute of authenticated User’s model, using the feature of dynamic rate limiting. Prerequisites. For the purpose of this tutorial, I assume that you have a Laravel application installed on a web server. My setup is: Laravel 5.5; PHP 7.1; MySQL; Node.js with NPM

Error on create resource · Issue #55 · laravel/nova-issues · GitHub, GitHub is home to over 50 million developers working together to host and review code, manage I try to reinstall a fresh laravel app but the result it's the same Just create Post resource and threw the same error. php artisan make:model Post -m (m parameter for migration) Linked pull requests. Once CSRF protection has been initialized, you should make a POST request to the typical Laravel /login route. This /login route may be provided by the laravel/ui authentication scaffolding package.

HTTP Clients, This will use your schema for the post to serialize the record for the JSON API body This will use your schema to work out the resource type and id for the request. API client will throw a exceptions if a HTTP 400 or 500 response is received. The retry method accepts two arguments: the number of times the request should be attempted and the number of milliseconds that Laravel should wait in between attempts: $response = Http::retry (3, 100)->post (); If all of the requests fail, an instance of Illuminate\Http\Client\RequestException will be thrown.

Developing RESTful APIs with Lumen (A PHP Micro-framework), The creator of Laravel crafted a micro-framework off the giant full-stack web framework, Laravel. For this tutorial, you can use MySQL straight from the terminal, but if you'd Each migration file name contains a timestamp, which allows Lumen to For example, if you make a POST request to /api/authors API endpoint, the  If you would like to obtain an instance of a PSR-7 request instead of a Laravel request, you will first need to install a few libraries. Laravel uses the Symfony HTTP Message Bridge component to convert typical Laravel requests and responses into PSR-7 compatible implementations: composer require symfony/psr-http-message-bridge composer require

  • I'm using a digital ocean ubuntu droplet if this helps.
  • Is your production database not password protected ? You can run this .env on both environments and it would still connect to 2 different databases
  • Don't deploy a application to a production environment on your own if you don't have system administration experience. I doubt this problem is programming related.
  • I removed the password just for stack overflow. I have it in the original .env
  • @Vova is your password quoted? If so, don't quote it.
  • Can you even explain why exactly it is "dangers" and how that comment solves the original problem?
  • The comment about using strong password is a recommendation.
  • So, your answer is a recommendation that does not solve the problem?
  • My answer includes recommendation regarding a security issue and solution for the problem.
  • I removed the password just for stack overflow. I have it in the original .env
  • @Vova please clear cache: php artisan config:cache
  • @Vova If all possible solution is not working for you then please provide some more information. make sure have you a default username(root) in the installation of MySQL ?
  • I understand that it is difficult to adopt an answer while the question has changed, and surely one should appreciate that you try to find a new solution. But regardless of the question, "try this"-answers without an explanation are not as good as those which contain an explanation
  • Okay, thanks for your time @NicoHaase , I will take care of it next time :)