Flutter mysql1 got packets out of order - mysql

I have some troubles in setting up a connection with my VPS with the library mysql1 on flutter. I get this error Unhandled Exception: Error 1156 (08S01): Got packets out of order when I perform a query.
MySQL server version: 8.0.28
This is my service in which I perform the connection with my database.
var settings = ConnectionSettings(
host: 'MY_ADDRESS',
port: 3306,
user: 'root',
password: 'MY_PASSWORD',
db: 'MY_DATABASE'
);
Future connect() async {
return await MySqlConnection.connect(settings);
}
And then I try to retrieve users information in another method in this way:
var connection = await mysqlService.connect();
var res = await connection.query('select name from users');
await connection.close();
The problem is in the connection.query function which generate the error:
[VERBOSE-2:ui_dart_state.cc(209)] Unhandled Exception: Error 1156 (08S01): Got packets out of order
#0 Handler.checkResponse
package:mysql1/…/handlers/handler.dart:77
#1 QueryStreamHandler.processResponse
package:mysql1/…/query/query_stream_handler.dart:50
#2 ReqRespConnection._handleData
package:mysql1/src/single_connection.dart:349
#3 ReqRespConnection._handleHeader
package:mysql1/src/single_connection.dart:318
<asynchronous suspension>
#4 ReqRespConnection._readPacket
package:mysql1/src/single_connection.dart:303
<asynchronous suspension>
I Am not sure if it is a problem with the database that I have on my VPS or is something else.

This package appears to have problems with MySQL 8.
Try to use mysql_client, this one helped me.
https://pub.dev/packages/mysql_client

Related

Express app getting disconnected right after the connection

I created a rest api with Express. on my server.js the i have my mysql connection.. though the connection is made at first. It's working on my local machine properly but when i deployed on AWS EC2 service then i am facing this problem..
server.js
var mysql = require('mysql');
var connection = mysql.createConnection({
host: 'localhost',
user: 'myusername',
password: 'mypassword',
database: 'mydatabasename'
});
connection.connect(function (err) {
if (err) throw err;
console.log('connected!');
});
module.exports = connection;
i tried pm 2 handledisconnect() following other project function none worked.getting following error...
restapi#0.0.0 start /home/bcs_quiz_console/bcs-preparation-backend/restapi
npm start
connected!
events.js:180
throw er; // Unhandled 'error' event
^
Error: Connection lost: The server closed the connection.
at Protocol.end (/home/bcs_quiz_console/bcs-preparation-backend/restapi/node_modules/mysql/lib/protocol/Protocol.js:112:13)
at Socket. (/home/bcs_quiz_console/bcs-preparation-backend/restapi/node_modules/mysql/lib/Connection.js:97:28)
at Socket. (/home/bcs_quiz_console/bcs-preparation-backend/restapi/node_modules/mysql/lib/Connection.js:525:10)
at Socket.emit (events.js:208:15)
at endReadableNT (_stream_readable.js:1168:12)
at processTicksAndRejections (internal/process/task_queues.js:77:11)
Emitted 'error' event at:
at Connection._handleProtocolError (/home/bcs_quiz_console/bcs-preparation-backend/restapi/node_modules/mysql/lib/Connection.js:426:8)
at Protocol.emit (events.js:203:13)
at Protocol._delegateError (/home/bcs_quiz_console/bcs-preparation-backend/restapi/node_modules/mysql/lib/protocol/Protocol.js:398:10)
at Protocol.end (/home/bcs_quiz_console/bcs-preparation-backend/restapi/node_modules/mysql/lib/protocol/Protocol.js:116:8)
at Socket. (/home/bcs_quiz_console/bcs-preparation-backend/restapi/node_modules/mysql/lib/Connection.js:97:28)
[... lines matching original stack trace ...]
at processTicksAndRejections (internal/process/task_queues.js:77:11) {
fatal: true,
code: 'PROTOCOL_CONNECTION_LOST'
}
Thank anyone who can help in advance..

"mysql_clear_password" plugin error when using knex but not when using mysql2

I am trying to connect to MySQL server using the mysql_clear_password plugin. I set up the connection configuration for node-mysql2 as follows:
const connectionConfig = {
host: rwConfig.host,
user: rwConfig.user,
database: rwConfig.database,
ssl: {
ca: sslContent
},
password
}
Then to support the mysql_clear_password plugin I added the following (link of the reference i used: https://github.com/sidorares/node-mysql2/issues/438#issuecomment-255343793):
connectionConfig.authSwitchHandler = (data, cb) => {
console.log('In auth switch handler');
if (data.pluginName === 'mysql_clear_password') {
console.log(data);
console.log(data.pluginData.toString('utf8'));
console.log('In mysql clear password');
var tmppassword = connectionConfig.password + '\0';
var buffer = Buffer.from(tmppassword, 'base64');
cb(null, buffer);
}
};
This works when I attempt to connect to my database.
Now I try to do something similar using knexjs. I use the following configuration object:
const knexConfig = {
client: 'mysql2',
connection: connectionConfig,
pool: {
min: 0,
max: 20
},
acquireConnectionTimeout: 10000
};
The connectionConfig I passed in as the value for connection is the same object I used for connecting with node-mysql2. Then I create a knex connection:
const rwConnection = knex(knexConfig);
This for some reason throws this error:
{ Error: Client does not support authentication protocol requested by server; consider upgrading MySQL client
at Packet.asError (node_modules/mysql2/lib/packets/packet.js:703:13)
at ClientHandshake.Command.execute (node_modules/mysql2/lib/commands/command.js:28:22)
at Connection.handlePacket (node_modules/mysql2/lib/connection.js:515:28)
at PacketParser.onPacket (node_modules/mysql2/lib/connection.js:94:16)
at PacketParser.executeStart (node_modules/mysql2/lib/packet_parser.js:77:14)
at TLSSocket.<anonymous> (node_modules/mysql2/lib/connection.js:386:31)
at emitOne (events.js:96:13)
at TLSSocket.emit (events.js:188:7)
at readableAddChunk (_stream_readable.js:176:18)
at TLSSocket.Readable.push (_stream_readable.js:134:10)
at TLSWrap.onread (net.js:547:20)
code: 'ER_NOT_SUPPORTED_AUTH_MODE',
errno: 1251,
sqlState: '#08004' }
I don't know why this is giving me the error. In the knex documentation (http://knexjs.org/) it says:
The connection options are passed directly to the appropriate database client to create the connection, and may be either an object, or a connection string
Based on that I thought it would just pass the configuration through and make the connection using node-mysql2. Any help would be appreciated.
I figured out the issue and it works now. Knex was not passing on all the attributes to the msyql2 client.
Here is what I did for anyone else who might run into this problem. I modified the configurations that knex was passing to mysql2 in the node_modules/knex/lib/dialect/mysql2 and added authSwitchHandler to the configOptions array.

Error Connecting MySQL Database with Node.js in Angular Universal. TypeError: Cannot read property 'on' of undefined

I would like to connect to MySQL database through Node.js in my Angular Universal project.
Connection code is simple:
var mysql = require('mysql');
var connection = mysql.createConnection({
host : 'localhost',
user : 'root',
password : 'root',
database : 'dbname',
port: '8889'
});
connection.connect(function(err) {
if (err) {
console.log("Error connecting to DB: " + err);
throw err;
}
});
First I am getting the following error:
TypeError: Cannot read property 'on' of undefined
at Protocol._enqueue (/Applications/MAMP/htdocs/Angular2/myproject/node_modules/mysql/lib/protocol/Protocol.js:152:5)
...
Then after several seconds there is the following error:
Error connecting to DB: Error: Connection lost: The server closed the connection.
Advice me please what should be done in this case to fix the issue.
Thanks a lot.
If I change the version for zone.js in package.json to 0.7.4, everything works without problems.

'PDOException' with message 'SQLSTATE[HY000] [2002] zend framework

Any one plz tell me why i am getting this error ?? firstly my internet connection was good today its not good so i am getting this error.how can i fix this any idea plz??
Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[HY000] [2002] A
connection attempt failed because the connected party did not properly respond after a
period of time, or established connection failed because connected host has failed to
respond. ' in D:\SVN
data\WebClient_PHP\trunk\p\library\Zend\Db\Adapter\Pdo\Abstract.php:129
Stack trace: #0 D:\SVN
data\WebClient_PHP\trunk\p\library\Zend\Db\Adapter\Pdo\Abstract.php(129):
PDO->__construct('mysql:host=192....', 'root', 'root', Array) #1 D:\SVN
data\WebClient_PHP\trunk\p\library\Zend\Db\Adapter\Pdo\Mysql.php(109):
Zend_Db_Adapter_Pdo_Abstract->_connect() #2 D:\SVN
data\WebClient_PHP\trunk\p\library\Zend\Db\Adapter\Abstract.php(860):
Zend_Db_Adapter_Pdo_Mysql->_connect() #3 D:\SVN
data\WebClient_PHP\trunk\p\library\Zend\Db\Adapter\Abstract.php(930):
Zend_Db_Adapter_Abstract->quote('testing', NULL) #4 D:\SVN
data\WebClient_PHP\trunk\p\library\Zend\Auth\Adapter\DbTable.php(449): Zen
in D:\SVN
data\WebClient_PHP\trunk\p\library\Zend\Db\Adapter\Pdo\Abstract.php on line
144
this is my config.ini
[general]
db.adapter = PDO_MYSQL
db.params.host = 192.168.0.233
db.params.username = root
db.params.password = my_password
db.params.dbname = "mydatabasename"
some code from my index.php
$config = new Zend_Config_Ini(ROOT_DIR.'/application/config.ini', 'general');
$DB = Zend_Db::factory($config->db);
Zend_Db_Table::setDefaultAdapter($DB);
it seems that your code this portion is not working
[general]
db.adapter = PDO_MYSQL
db.params.host = 192.168.0.233
db.params.username = root
db.params.password = my_password
db.params.dbname = "mydatabasename"
either the IP is not correct if so go to cmd in windows and type ipconfig you will get your correct ip paste it here OR just simply write
db.params.host = localhost
if and only if you are using locally may be it works.
for the hostname/host try to use your credentials found in the Zend Server -> PHP Cloud tab -> Overview page -> User Parameters tab... then make the "host" part in the credentials like this:
[general]
db.adapter = PDO_MYSQL
db.params.host = CONTAINERNAME-db.my.phpcloud.com
db.params.username = ZEND_DB_USERNAME
db.params.password = ZEND_DB_USERNAME
db.params.dbname = ZEND_DB_DBNAME
Did you check your mysql database is up?
If you are sure it is, check that your adapters configuration is ok, maybe the host parameter is not properly configured.

connect ECONNREFUSED - node js , sql

I have the next code in a js file:
var mysql = require('mysql');
var TEST_DATABASE = 'nodejs_mysql_test';
var TEST_TABLE = 'test';
var client = mysql.createClient({
user: 'root',
password: 'root',
});
client.query('CREATE DATABASE '+TEST_DATABASE, function(err) {
if (err && err.number != mysql.ERROR_DB_CREATE_EXISTS) {
throw err;
}
});
But I get this error:
node.js:201
throw e; // process.nextTick error, or 'error' event on first tick
^
Error: connect ECONNREFUSED
at errnoException (net.js:632:11)
at Object.afterConnect [as oncomplete] (net.js:623:18)
As I understand it, this is a connection problem - but how do I solve it?
( I'm working on windows 7)
Thanks!!
I know two ways to solve it:
In mysql.conf, comment skip-networking.
Try to set the socket like this:
var client = mysql.createClient({
user: uuuu,
password: pppp,
host: '127.0.0.1',
port: '3306',
_socket: '/var/run/mysqld/mysqld.sock',});
I got this error when MySQL Server was not running.
I changed my configuration via Initialize Database in MySQL.PrefPane, the System Preferences tool for MySQL on OS X - to Use Legacy Password Encryption - to fix ER_NOT_SUPPORTED_AUTH_MODE.
This config change stopped MySQL Server and then I got ECONNREFUSED when I tried to connect to MySQL from node.js.
Fixed by restarting MySQL Server from the MySQL System Preferences tool.
Try to fix your defined port in mysql and your Node.js script.
You can define the mysqld port in the *.cnf file inside the mysql directory,
and you can define that port when you connect to MySQL in your Node.js script.
Something like this in the cnf file
port = 3306