简体   繁体   English

收到错误:使用MySQL对Node.js的访问被拒绝

[英]Getting an Error: access denied for Node.js with mysql

I'm trying to get a node.js app that uses mysql to work. 我试图获得一个使用mysql来工作的node.js应用程序。 I run sudo node app.js and I get this error: 我运行sudo节点app.js并收到此错误:

Express server listening on port 80 in development mode

events.js:48
        throw arguments[1]; // Unhandled 'error' event
                       ^
Error: Access denied for user 'root'@'localhost' (using password: YES)
    at cmd.process_packet (/Users/.../Documents/Code/.../node_modules/mysql-native/lib/mysql-native/command.js:35:15)
    at SocketClient.dispatch_packet (/Users/.../Documents/Code/.../node_modules/mysql-native/lib/mysql-native/socketclient.js:105:32)
    at Socket.<anonymous> (/Users/.../Documents/Code/.../node_modules/mysql-native/lib/mysql-native/socketclient.js:59:18)
    at Socket.emit (events.js:67:17)
    at TCP.onread (net.js:362:31)

I set up a secure user and password for mysql but it's not asking me for a password besides one for sudo. 我为mysql设置了安全的用户名和密码,但是除了sudo之外,没有要求我输入密码。 I'm a beginner with both node.js and especially mysql so any help would be appreciated. 我是node.js尤其是mysql的初学者,因此可以提供任何帮助。

So I contacted someone who had done this before and he helped me through it. 因此,我联系了曾经做过此事的人,他帮助了我。 Basically I connected to mysql with mysql -u root -p, entered in my password, created the database and put use that database and entered in all the database information. 基本上,我使用mysql -u root -p连接到mysql,输入密码,创建数据库并使用该数据库,并输入所有数据库信息。 Then in api.js under db.auth, in parenthesis I put the database name, my username and the password, each as strings separated by commas. 然后,在db.auth下的api.js中,在括号中,我将数据库名称,用户名和密码分别作为字符串,并用逗号分隔。 In a separate terminal tab I then ran the node.js application and it worked. 然后,在一个单独的终端选项卡中,我运行了node.js应用程序,它开始工作了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM