Node uses Sequlize to connect to Mysql and reports the following error: Access denied for user 'xxx' @ 'localhost', sequlizemysql

Source: Internet
Author: User

Node uses Sequlize to connect to Mysql and reports the following error: Access denied for user 'xxx' @ 'localhost', sequlizemysql

Preface

Recently encountered problems at work:

Unhandled rejection SequelizeAccessDeniedError: Access denied for user 'lupeng'@'localhost' (using password: YES)

This error is returned when Node uses Sequlize to connect to Mysql data. The key is the error following the colon: Access denied. The key is the access denied error, which indicates that there is a problem with the database connection, database Connection access is denied, either because the database does not have the corresponding operation permission or the account password is incorrect.

In this way, the problem is located on the two sides of the access permission and Account Password error. Do not forget to look for the problem in other ways. This will only be a waste of time.

1. Questions about User Permissions

For permission issues, start with the database and check whether the permission list is refreshed after user authorization. That is, after using the Grant command to authorize a user, you should use the flush privileges command. This is a problem that many people will ignore.

If the user authorization is correct, restart the mysql server. Run the/etc/init. d/mysql restart command to restart the mysql server. The restart command may be different in different Linux versions. Here is the Debain system.

If the problem persists after the restart, it may not be a problem with database user permissions.

2. account and password Problems

The account password is incorrect. This problem may sound confusing, but many people will ignore it during development. Why? I am using the config-lite module to configure database parameters, because it will switch development in multiple system environments, the config-lite module can be configured through simple environment variables, to load different parameter files. For details, refer to the configuration file usage in different environments.

My problem occurs here. Open a terminal to run the project.npm run test, The package. json file is configured with the test running script.NODE_ENV=test supervisor --harmony -i views/ ./bin/www. Open another terminal and run the Database Synchronization command. The synchronization command is written in a separate js script, which references the data connection method (generic). The connection method is as follows:

Var sequencee = require ('sequencee'); // introduce the database configuration file var sqlConfig = require ('config-lite ') (_ dirname ). mysql; var sequencee = new sequencee (sqlConfig. database, sqlConfig. user, sqlConfig. password, {host: sqlConfig. host, dialect: 'mysql', pool: {max: 10, min: 0, idle: 10000}); module. exports = sequencee;

So when synchronizing the database, the title always reports an error, but I think it is correct. The problem is found only after the final check: The NODE_ENV environment variable in the test script is only valid under the current terminal, if you want to open another terminal to synchronize the database, you need to set the environment variable in another terminal. Otherwise, the loaded database parameters are inconsistent, that is, the username and password used to connect to the database are incorrect.

Summary

The above is all the content of this article. I hope the content of this article has some reference and learning value for everyone's learning or work. If you have any questions, please leave a message to us, thank you for your support.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.