DEV Community

Discussion on: How to get data from an MySQL database in React Native

Collapse
 
saulojoab profile image
Saulo Joab

Hello! Does your Terminal logs any errors? If all you get in the browser is "[]" it means that the query didn't return any values.

Collapse
 
saadazghour profile image
Azghour-Saad

i get error like ' Cannot read property 'query' of
undefined', it doesn't know query method when retrieving data from db

Thread Thread
 
saulojoab profile image
Saulo Joab

Are you sure that you installed the mysql module with:
npm install mysql

And imported it into the routes.js file with:

const mysql = require('mysql');

Also, make sure you create the connection with:

const connection = mysql.createPool({
  host     : 'localhost',
  user     : 'me',
  password : 'secret',
  database : 'my_db'
});
Thread Thread
 
saadazghour profile image
Azghour-Saad

I've done it all, the same problem.

Alt text of image

Alt text of image

Alt text of image

Thread Thread
 
saulojoab profile image
Saulo Joab

Huh. That's weird.

Try removing the comma after the database name. If that doesn't work, change mySql to lowercase (mysql). I really don't know what's wrong, maybe something with the npm installation?

Thread Thread
 
saadazghour profile image
Azghour-Saad

Absolutely, this is really weird, I can't figure out this, i'm doing all what you say but he doesn't work, with npm i have this three packages completely.

Alt text of image

Thread Thread
 
saulojoab profile image
Saulo Joab

Is your MySQL database working fine on the localhost? I really can't see the problem...

Thread Thread
 
saadazghour profile image
Azghour-Saad

Finally,
Problem solved !!

i have added these lines :

Alt text of image

and MySQL port of my Database: Alt text of image

then it's pop up another problem these: (ER_NOT_SUPPORTED_AUTH_MODE)
then it solved with just executing this command:

alter user 'root'@'localhost' identified with mysql_native_password by 'password'

inside Query file, finally all is well.

source :

stackoverflow.com/questions/449462...

Thread Thread
 
saulojoab profile image
Saulo Joab

That's awesome! I'm glad it worked out! Sorry I couldn't help you, that never happened to me...

Thread Thread
 
saadazghour profile image
Azghour-Saad

No problem, thank you a lot .