0

On my dev environment, I have installed MySQL 8.0 and built the app accordingly, But on the prod server, the MySQL version is 5.7 and my app fails to connect to the database.

I use the mysql2 package because I need the Async API (mysql2/promise) which is not available in mysql. I even tried to use mysql-await which was a port of mysql with added Async API, but after authenticating to the Database, it just fails to create tables.

What causes this? are there different authentication methods used in MySQL 8.0 and MySQL 5.7? If so, then what method is used by 5.7 and how could I configure the authentication method used in the mysql2 connection?

I connect to the Database like this:

db = await mysql.createConnection({
    host: mysql_host,
    user: mysql_user,
    password: mysql_pass,
    database: mysql_db
})

And create tables like this:

await db.query(
    "CREATE TABLE IF NOT EXISTS form (ID int NOT NULL AUTO_INCREMENT, \
    Name varchar(255), \
    Email varchar(255), \
    Phone varchar(15), \
    Address varchar(255), \
    Occupation varchar(50), \
    PRIMARY KEY (ID))")
Nalin Angrish
  • 317
  • 5
  • 17

1 Answers1

0

Yes, both have different authentication methods. And to solve this issue, the better choice is either to change the development MySQL 8 with MySQL 5.7 or change the production MySQL 5.7 with MySQL 8, otherwise, you may face some more bugs in production.

naeem1098
  • 123
  • 2
  • 9
  • 1
    I can use MySQL 5.7 on my local machine, but i feel it is too outdated (More than 2 versions, 3 years old) to use, but on the other hand, I cannot change the version on the Production environment because we are using a shared hosting package. Still thanks for trying, but we have already migrated our database system to use MongoDB. – Nalin Angrish Oct 11 '21 at 08:13