0

i am trying to insert a row in my supermasters table by creatin a pool-

const { createPool } = require('mysql');

const pool = createPool({
    port: process.env.DB_PORT,
    host: process.env.Host,
    user: process.env.DB_USERNAME,
    password: process.env.DB_PASSWORD,
    database: 'users',
    connectionLimit: 8,
});

module.exports = pool;

My supermasters table has these columns:--

username varchar(10) PK 
password varchar(20) 
fullname varchar(20) 
email varchar(30) 
phoneNumber varchar(10) 

Specifically i am getting error in this part of code which creates connection:--

const pool = require('../../config/database');

module.exports = {
    create: (data, callback) => {
        const my_query = 'insert into supermasters(username,password,fullname,email,phoneNumber) values(?,?,?,?,?)';

        pool.query(my_query, [data.username, data.password, data.fullname, data.email, data.phoneNumber], (error, results, fields) => {

            if (error)
                return callback(error);
            else {
                return callback(null, results);
            }
        })
    }
}

And my error is:--

Server running at port 3000
D:\web-development\elite\server\node_modules\mysql\lib\protocol\Parser.js:437
      throw err; // Rethrow non-MySQL errors
      ^

RangeError [ERR_OUT_OF_RANGE]: The value of "sourceStart" is out of range. It must be <= 9. Received 13
    at _copy (buffer.js:240:11)
    at Buffer.copy (buffer.js:768:12)
    at Parser.parseBuffer (D:\web-development\elite\server\node_modules\mysql\lib\protocol\Parser.js:272:16)
    at HandshakeInitializationPacket.parse (D:\web-development\elite\server\node_modules\mysql\lib\protocol\packets\HandshakeInitializationPacket.js:34:37)
    at Protocol._parsePacket (D:\web-development\elite\server\node_modules\mysql\lib\protocol\Protocol.js:272:12)
    at Parser._parsePacket (D:\web-development\elite\server\node_modules\mysql\lib\protocol\Parser.js:433:10)
    at Parser.write (D:\web-development\elite\server\node_modules\mysql\lib\protocol\Parser.js:43:10)
    at Protocol.write (D:\web-development\elite\server\node_modules\mysql\lib\protocol\Protocol.js:38:16)
    at Socket.<anonymous> (D:\web-development\elite\server\node_modules\mysql\lib\Connection.js:88:28)
    at Socket.<anonymous> (D:\web-development\elite\server\node_modules\mysql\lib\Connection.js:526:10) {
  code: 'ERR_OUT_OF_RANGE'
}
[nodemon] app crashed - waiting for file changes before starting...
sayantan
  • 21
  • 6
  • Do you have any field in your Database table with name 'sourceStart'? – Amaranadh Meda Jul 31 '20 at 06:57
  • What port are you connecting to? What is running on that port? I'd guess it's something other than mysql or using TLS on a non tls port or maybe an old/unsupported version. – Matt Jul 31 '20 at 07:03
  • no i don't have any field name 'sourceStart'. My server is running on port 3000 and database on 3306. – sayantan Aug 04 '20 at 04:40

2 Answers2

2

What I found was that I was using the wrong port: '33060' instead of '3306', I would suggest that you ensure that your environment variables are all correct

Maybe try to hard code the createPool() inputs, while testing before delegating them to the environment variables

Tlotlo
  • 61
  • 4
0

The problem is solved- I ran this query in mysql workbench:-
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'password'

Which i found here:-

MySQL 8.0 - Client does not support authentication protocol requested by server; consider upgrading MySQL client

sayantan
  • 21
  • 6