Skip to content

changeUser return err #482

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
freedaxin opened this issue May 10, 2013 · 9 comments
Closed

changeUser return err #482

freedaxin opened this issue May 10, 2013 · 9 comments

Comments

@freedaxin
Copy link
Contributor

// ... connect and query
connection.changeUser({}, function (err) {
console.log(err);
});

callback err:

{ [Error: ER_UNKNOWN_COM_ERROR: Unknown command] code: 'ER_UNKNOWN_COM_ERROR', fatal: true }

my mysql version is 5.1.42, which should have support change user command.

@felixge
Copy link
Collaborator

felixge commented May 10, 2013

Can you post the output when setting debug: true for the connection?

@freedaxin
Copy link
Contributor Author

var mysql      = require('/data0/npm/node_modules/mysql');

var connection = mysql.createConnection({
  host     : '10.75.19.79',
  port     : 9601,
  user     : 'maya',
  password : 'maya123456',
  database : 'test',
  debug    : true,
});

connection.connect();

connection.query('SELECT 1 + 1 AS solution', function(err, rows, fields) {
  if (err) throw err;

  console.log('The solution is: ', rows[0].solution);
});

//connection.changeUser({}, function (err) {
  console.log('err:', err);
});

connection.end();

output:

<-- HandshakeInitializationPacket
{ protocolVersion: 10,
  serverVersion: '5.1.42-log',
  threadId: 10148466,
  scrambleBuff1: <Buffer 64 3e 48 2f 50 27 6e 75>,
  filler1: <Buffer 00>,
  serverCapabilities1: 63487,
  serverLanguage: 33,
  serverStatus: 2,
  serverCapabilities2: 0,
  scrambleLength: 0,
  filler2: <Buffer 00 00 00 00 00 00 00 00 00 00>,
  scrambleBuff2: <Buffer 26 57 63 6d 7b 42 76 4b 52 3b 6e 39>,
  filler3: <Buffer 00>,
  pluginData: undefined,
  protocol41: true }

--> ClientAuthenticationPacket
{ clientFlags: 193487,
  maxPacketSize: 0,
  charsetNumber: 33,
  filler: undefined,
  user: 'maya',
  scrambleBuff: <Buffer 23 83 02 c5 b3 1a 90 a2 d2 7f 99 ec db 41 03 55 da 86 c8 29>,
  database: 'test',
  protocol41: true }

<-- OkPacket
{ fieldCount: 0,
  affectedRows: 0,
  insertId: 0,
  serverStatus: 2,
  warningCount: 0,
  message: '',
  protocol41: true,
  changedRows: 0 }

--> ComQueryPacket
{ command: 3, sql: 'SELECT 1 + 1 AS solution' }

<-- ResultSetHeaderPacket
{ fieldCount: 1, extra: undefined }

<-- FieldPacket
{ catalog: 'def',
  db: '',
  table: '',
  orgTable: '',
  name: 'solution',
  orgName: '',
  filler1: <Buffer 0c>,
  charsetNr: 63,
  length: undefined,
  type: 8,
  flags: 129,
  decimals: 0,
  filler2: <Buffer 00 00>,
  default: undefined,
  zeroFill: false,
  protocol41: true,
  fieldLength: 3 }

<-- EofPacket
{ fieldCount: 254,
  warningCount: 0,
  serverStatus: 2,
  protocol41: true }

<-- RowDataPacket
{ solution: 2 }

<-- EofPacket
{ fieldCount: 254,
  warningCount: 0,
  serverStatus: 2,
  protocol41: true }

The solution is:  2
--> ComChangeUserPacket
{ command: 17,
  user: 'maya',
  scrambleBuff: <Buffer 23 83 02 c5 b3 1a 90 a2 d2 7f 99 ec db 41 03 55 da 86 c8 29>,
  database: 'test',
  charsetNumber: 33 }

<-- ErrorPacket
{ fieldCount: 255,
  errno: 1047,
  sqlStateMarker: '#',
  sqlState: '08S01',
  message: 'Unknown command' }

err: { [Error: ER_UNKNOWN_COM_ERROR: Unknown command] code: 'ER_UNKNOWN_COM_ERROR', fatal: true }

@dougwilson
Copy link
Member

Are you able to use any of the GRANT commands on that server? Typically I have seen the change user command return Unknown command if the server is started with --skip-grant-tables.

@freedaxin
Copy link
Contributor Author

to dougwilson:
I can use grant on the connection, but still error.

@freedaxin
Copy link
Contributor Author

I've run the same test with php mysqli_change_user(), and it works, so there's no problem with mysql.

@freedaxin
Copy link
Contributor Author

I read the mysql protocol:
http://dev.mysql.com/doc/internals/en/text-protocol.html#packet-COM_CHANGE_USER

and found that character-set should be 2 bytes, but in ComChangeUserPacket.js it's 1 byte.
I changed it to 2:

    writer.writeUnsignedNumber(2, this.charsetNumber);

And run the test again, it seems ok now:

{ command: 17,
  user: 'root',
  scrambleBuff: <Buffer 4e 62 44 33 f7 8f 73 2c 2b 70 1d b5 7a 73 9a 61 d8 cb f8 01>,
  database: 'test',
  charsetNumber: 33 }

<-- OkPacket
{ fieldCount: 0,
  affectedRows: 0,
  insertId: 0,
  serverStatus: 2,
  warningCount: 0,
  message: '',
  protocol41: true,
  changedRows: 0 }

Can you confirm and fix it?
Thanks very much!

@felixge
Copy link
Collaborator

felixge commented May 20, 2013

@freedaxin I think you're right. If you send a patch, I'd be happy to merge it.

@felixge
Copy link
Collaborator

felixge commented May 21, 2013

Should be fixed by #498 now.

@freedaxin
Copy link
Contributor Author

ok

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

3 participants