I am trying create app by Shopify tutorial Template Nodejs. This example app use SQLite but I want to use MySQL database. How to change SQLite to MySQL database? Thank you very much
Hi @AndyHung
This is Kate from PageFly - Landing page builder, I’d like to suggest this idea:
To use MySQL instead of SQLite in your Shopify app, you will need to make a few changes in your code.
Install the MySQL library for Node.js:
npm install mysql2
Replace the SQLite code in your app with the following code to connect to your MySQL database:
const mysql = require('mysql2');
const connection = mysql.createConnection({
host: 'your-host-name',
user: 'your-mysql-username',
password: 'your-mysql-password',
database: 'your-mysql-database'
});
Modify the SQL queries in your app to use the MySQL library instead of the SQLite library. For example, instead of using the sqlite3.Database object, you will use the connection.query method to execute queries.
Finally, make sure to close the connection when you are done with it:
connection.end();
Hello @PageFly-Kate ,
Thank you so much for your help. I will try it
you can check my git repo:
https://github.com/phg-pih/shopify–example-app–qr-code–remix–ts–mysql
change file sample.env to .env & update its config.
this one follows the Shopify sample QR code app.