I have a MySQL database, which I wanna connect to my Node.js app. Right now my database is empty and I was wondering if there is any library or any standard way through which I could populate the database with test data from Node.js. I have never done this before and although I have been trying to find related answers on the internet, I havent been able to do so. Do you have any recommendations? Thanks in advance
Asked
Active
Viewed 942 times
-1
-
1This depends what data your database should contain - This does not seem to be a valid Stack Overflow question (sorry) but if your database is imported from somewhere then ask at that location, if you made the database yourself, only you know what sort of (test) data should go in to it.... – Martin Nov 07 '19 at 12:39
-
@Martin thanks for the answer man. So I have to write a script manually you think? There is not a library which could generate objects with MySQL data types like timestamp or char of length 20 for instance automatically? – hispaniccoder Nov 07 '19 at 12:55
-
maybe there might be...did you do any research yourself? But it would only generate complete nonsense data. If you want test data which will be meaningful in the context of your application (e.g. with realistic links between tables, realistic values, then you can test for things like performance with large datasets, or correct handling of certain types of data) then you probably need to consider how to generate your own. Once you've come up with such a script, you'll need to maintain it as and when your schema and reference data values change. – ADyson Nov 07 '19 at 13:19
1 Answers
0
Your best bet here: for each table create a CSV file containing test data. Then use the import facilities in some MySQL client (phpmyadmin, HeidiSQL, MySQL Workbench) to load your tables.
The benefits of this approach:
- ease of editing test data
- using an entirely separate software path for loading it. If you use similar code to your app for loading test data, you may create a bug-for-bug compatible test / production system.
It's not possible to help you decide what to put in the CSV files, because you told us nothing about your data. But know this: you can use your favorite search engine to find sites that will serve up a CSV file containing a few thousand fake persons complete with fake emails and phone numbers.

O. Jones
- 103,626
- 17
- 118
- 172