Member-only story

Connect MySQL Database From Electron Application

I Wayan Aditya Wiguna
4 min readJan 29, 2024

--

When developing desktop application maybe sometime best database we can use is sqlite, because it simple and also easy to implement, in my case found one problem where sqlite is unstable.

For the information now i’m developing the application using MacOs and also windows, in my MacOs sqlite running very well but on my windows laptop they can showing error message like.

windows sqlite crashpad_client_win.cc(844)

based on this case, i decide to change my database to mysql for current project development, i installing XAMPP or Laragon on my client device and also as mysql server, let’s to step by step by step how to implement it.

For infomation for my project i use vite-electron-react by following https://electron-vite.org/guide/

  1. Install MySQL pluggin

To use mysql sql on we can use mysql2 plugin and install only by one command

npm install --save mysql2

// typescript
npm install --save-dev @types/node

2. Configure Database Connection

create one file in electron/database.config.ts

export default {
HOST: "localhost",
USER: "root",
PASSWORD: undefined,
DATABASE: "database",
};

--

--

I Wayan Aditya Wiguna
I Wayan Aditya Wiguna

Written by I Wayan Aditya Wiguna

Website Developer at Dinas Komunikasi, Informatika Dan Statistik Provinsi Bali with expertise in NestJS, MySQL, Django and Laravel.

Responses (1)

Write a response