Skip to content

localhost is automatically converted to 127.0.0.1 #734

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
vlad-shatskyi opened this issue Feb 17, 2014 · 7 comments
Closed

localhost is automatically converted to 127.0.0.1 #734

vlad-shatskyi opened this issue Feb 17, 2014 · 7 comments

Comments

@vlad-shatskyi
Copy link

...which in some situations causes ER_ACCESS_DENIED_ERROR.

@dougwilson
Copy link
Member

Hi! Can you show an example of when this happens (and include the output with debug: true when the connection to the database is made)?

localhost is resolved by your DNS (usually to 127.0.0.1) and then a TCP connection is made to the port on 127.0.0.1. The authentication packet itself does not include the hostname used to connect to the MySQL server, so if you have a user setup for authentication as'user'@'127.0.0.1' vs 'user'@'localhost', then conversion from 127.0.0.1 -> localhost for that is actually done on the MySQL server. You may also want to check the setting skip-name-resolve on your MySQL server to make sure it is not set.

@vlad-shatskyi
Copy link
Author

{ [Error: ER_ACCESS_DENIED_ERROR: Access denied for user 'dukecare_duke'@'127.0.0.1' (using password: YES)]
  code: 'ER_ACCESS_DENIED_ERROR',
  errno: 1045,
  sqlState: '28000',
  fatal: true }
Error: ER_ACCESS_DENIED_ERROR: Access denied for user 'dukecare_duke'@'127.0.0.1' (using password: YES)
    at Handshake.Sequence._packetToError (/home/dukecare/www.dukecareers.com/public_html/node/node_modules/mysql/lib/protocol/sequences/Sequence.js:32:14)
    at Handshake.ErrorPacket (/home/dukecare/www.dukecareers.com/public_html/node/node_modules/mysql/lib/protocol/sequences/Handshake.js:67:18)
    at Protocol._parsePacket (/home/dukecare/www.dukecareers.com/public_html/node/node_modules/mysql/lib/protocol/Protocol.js:186:24)
    at Parser.write (/home/dukecare/www.dukecareers.com/public_html/node/node_modules/mysql/lib/protocol/Parser.js:62:12)
    at Protocol.write (/home/dukecare/www.dukecareers.com/public_html/node/node_modules/mysql/lib/protocol/Protocol.js:36:16)
    at Socket.ondata (stream.js:51:26)
    at Socket.EventEmitter.emit (events.js:117:20)
    at Socket.<anonymous> (_stream_readable.js:746:14)
    at Socket.EventEmitter.emit (events.js:92:17)
    at emitReadable_ (_stream_readable.js:408:10)
    --------------------
    at Handshake.Sequence (/home/dukecare/www.dukecareers.com/public_html/node/node_modules/mysql/lib/protocol/sequences/Sequence.js:15:20)
    at new Handshake (/home/dukecare/www.dukecareers.com/public_html/node/node_modules/mysql/lib/protocol/sequences/Handshake.js:9:12)
    at Protocol.handshake (/home/dukecare/www.dukecareers.com/public_html/node/node_modules/mysql/lib/protocol/Protocol.js:41:50)
    at Connection.connect (/home/dukecare/www.dukecareers.com/public_html/node/node_modules/mysql/lib/Connection.js:73:18)
    at Connection._implyConnect (/home/dukecare/www.dukecareers.com/public_html/node/node_modules/mysql/lib/Connection.js:214:10)
    at Connection.query (/home/dukecare/www.dukecareers.com/public_html/node/node_modules/mysql/lib/Connection.js:129:8)
    at Object.exports.query (/home/dukecare/www.dukecareers.com/public_html/node/lib/database.js:17:16)
    at Object.exports.getChunk (/home/dukecare/www.dukecareers.com/public_html/node/lib/user.js:24:8)
    at sendInChunks (/home/dukecare/www.dukecareers.com/public_html/node/send.js:76:10)
    at null._onTimeout (/home/dukecare/www.dukecareers.com/public_html/node/send.js:70:9)

@vlad-shatskyi
Copy link
Author

We connect with CakePHP using the same credentials, and everything is alright. Besides, mysql console tool also accepts them.

@dougwilson
Copy link
Member

You may be connecting to your local MySQL over a UNIX socket instead of over TCP. Can you try running this mysql command on the box (make sure you keep the -h 127.0.0.1 part there, because it forces TCP connections), and let me know if it works or not?

mysql -h 127.0.0.1 -u <user> -p <pass>

@vlad-shatskyi
Copy link
Author

Nope, it doesn't work. The same error.

@dougwilson
Copy link
Member

OK, that means you are connecting to MySQL over a UNIX socket from PHP, so you need to do the same here. You can do this by removing the host and port from the configuration and setting socketPath to the output from mysql_config --socket

@vlad-shatskyi
Copy link
Author

Thank you very much, it helped.

dveeden pushed a commit to dveeden/mysql that referenced this issue Jan 31, 2023
* Fix prepared statement

When there are many args and maxAllowedPacket is not enough,
writeExecutePacket() attempted to use STMT_LONG_DATA even for
0byte string.
But writeCommandLongData() doesn't support 0byte data. So it
caused to send malfold packet.

This commit loosen threshold for using STMT_LONG_DATA.

* Change minimum size of LONG_DATA to 64byte

* Add test which reproduce issue 730

* TestPreparedManyCols test only numParams = 65535 case

* s/as possible//
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants