# Using mysql:require(’mysql’) does not function any more - any suggestions why

**URL:** https://discourse.nodered.org/t/using-mysql-require-mysql-does-not-function-any-more-any-suggestions-why/57746
**Category:** General
**Tags:** database
**Created:** [3 February 2022 22:16 UTC](https://discourse.nodered.org/t/using-mysql-require-mysql-does-not-function-any-more-any-suggestions-why/57746 "2022-02-03T22:16:28Z")
**Posts on this page:** 14
**Page:** 1

<div class="post-metadata">

### Author: ![Boja](https://avatars.discourse-cdn.com/v4/letter/b/3be4f8/32.png) [@Boja](https://discourse.nodered.org/u/Boja)
#### Post date: [3 February 2022 22:16 UTC](https://discourse.nodered.org/t/using-mysql-require-mysql-does-not-function-any-more-any-suggestions-why/57746/1 "2022-02-03T22:16:28Z")

</div>

To give function nodes access to a local MariaDB I'm used to adding mysql:require(’mysql’)  
to functionGlobalContext (in config/node-red/settings.js).

I have used this method for a number of years, last time was about a year ago but when installing Node-red on a new hassio yesterday, it no longer seems to work.

I run Node-red on Hassio ( Raspberry.py )

Any suggestions.

---

<div class="post-metadata">

### Author: ![knolleary](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/knolleary/32/3_2.png) [@knolleary](https://discourse.nodered.org/u/knolleary)
#### Post date: [3 February 2022 22:38 UTC](https://discourse.nodered.org/t/using-mysql-require-mysql-does-not-function-any-more-any-suggestions-why/57746/2 "2022-02-03T22:38:33Z")

</div>

Do you get any error messages? What version of the `mysql` npm module have you installed?

---

<div class="post-metadata">

### Author: ![Boja](https://avatars.discourse-cdn.com/v4/letter/b/3be4f8/32.png) [@Boja](https://discourse.nodered.org/u/Boja)
#### Post date: [3 February 2022 23:00 UTC](https://discourse.nodered.org/t/using-mysql-require-mysql-does-not-function-any-more-any-suggestions-why/57746/3 "2022-02-03T23:00:26Z")

</div>

The error occurs when Node-Red is trying to start. The same actually happens when I add fs:require(’fs’) to functionGlobalContext.

The following error is seen in the log file :  
node $NODE\_OPTIONS node\_modules/node-red/red.js "--settings" "/etc/node-red/config.js"  
Error loading settings file: /etc/node-red/config.js

-- What version of the `mysql` npm module have you installed  
I use the default in Hassio, version 1.0.0

---

<div class="post-metadata">

### Author: ![knolleary](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/knolleary/32/3_2.png) [@knolleary](https://discourse.nodered.org/u/knolleary)
#### Post date: [3 February 2022 23:06 UTC](https://discourse.nodered.org/t/using-mysql-require-mysql-does-not-function-any-more-any-suggestions-why/57746/4 "2022-02-03T23:06:23Z")

</div>

It definitely helps to provide details of any errors you are seeing when asking why something isn't working. Otherwise we have no information to go on.

If it fails when you try adding `require('fs')` as well, then this isn't related to `mysql`.

The error means you have a syntax error in your settings file. Double check you have added the property correctly.

---

<div class="post-metadata">

### Author: ![Boja](https://avatars.discourse-cdn.com/v4/letter/b/3be4f8/32.png) [@Boja](https://discourse.nodered.org/u/Boja)
#### Post date: [4 February 2022 11:19 UTC](https://discourse.nodered.org/t/using-mysql-require-mysql-does-not-function-any-more-any-suggestions-why/57746/5 "2022-02-04T11:19:40Z")

</div>

Year, maybe I should look into home assistant instead.

---

<div class="post-metadata">

### Author: ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)
#### Post date: [4 February 2022 11:22 UTC](https://discourse.nodered.org/t/using-mysql-require-mysql-does-not-function-any-more-any-suggestions-why/57746/6 "2022-02-04T11:22:10Z")

</div>

Curious as to why you do not simply install node-red directly without having it as a subsystem of Hassio or HA?

---

<div class="post-metadata">

### Author: ![Boja](https://avatars.discourse-cdn.com/v4/letter/b/3be4f8/32.png) [@Boja](https://discourse.nodered.org/u/Boja)
#### Post date: [4 February 2022 11:32 UTC](https://discourse.nodered.org/t/using-mysql-require-mysql-does-not-function-any-more-any-suggestions-why/57746/7 "2022-02-04T11:32:20Z")

</div>

It's because I also use other parts of hassio on the Raspberry.

---

<div class="post-metadata">

### Author: ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)
#### Post date: [4 February 2022 12:02 UTC](https://discourse.nodered.org/t/using-mysql-require-mysql-does-not-function-any-more-any-suggestions-why/57746/8 "2022-02-04T12:02:39Z")

</div>

Not being familiar with hassio myself...

Isn't it possible to install node-red and communicate with hassio without installing it as an add on of hassio?

---

<div class="post-metadata">

### Author: ![knolleary](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/knolleary/32/3_2.png) [@knolleary](https://discourse.nodered.org/u/knolleary)
#### Post date: [4 February 2022 12:07 UTC](https://discourse.nodered.org/t/using-mysql-require-mysql-does-not-function-any-more-any-suggestions-why/57746/9 "2022-02-04T12:07:12Z")

</div>

> [@Boja](#):
>
> , maybe I should look into home assistant instead.

Alternatively, if you share with us exactly what changes you've made to the settings file we may be able to spot the possible syntax error you have.

---

<div class="post-metadata">

### Author: ![Boja](https://avatars.discourse-cdn.com/v4/letter/b/3be4f8/32.png) [@Boja](https://discourse.nodered.org/u/Boja)
#### Post date: [4 February 2022 13:09 UTC](https://discourse.nodered.org/t/using-mysql-require-mysql-does-not-function-any-more-any-suggestions-why/57746/10 "2022-02-04T13:09:36Z")

</div>

This is how my "old" setting is (with the mysql line added) :

functionGlobalContext: {  
mysql:require('mysql'),  
// os:require('os'),  
// jfive:require("johnny-five"),  
// j5board:require("johnny-five").Board({repl:false}),  
},

Uncommenting os:require('os'), actually works.  
Maybe support for mysql:require('mysql') has been removed or has been renamed, I don't know.

I also have to double check that all needed HA nodes is installed.

---

<div class="post-metadata">

### Author: ![UnborN](https://avatars.discourse-cdn.com/v4/letter/u/4491bb/32.png) [@UnborN](https://discourse.nodered.org/u/UnborN)
#### Post date: [4 February 2022 13:44 UTC](https://discourse.nodered.org/t/using-mysql-require-mysql-does-not-function-any-more-any-suggestions-why/57746/11 "2022-02-04T13:44:23Z")

</div>

> [@Boja](#):
>
> -- What version of the `mysql` npm module have you installed  
> I use the default in Hassio, version 1.0.0

possibly you were relying on the npm module that the node **node-red-node-mysql** was installing  
that was in turn using the `mysql` library .. thats why you had access to it and could require it.  
and because of the update of the **node-red-node-mysql** node 1.0.0 to a different library `mysql2` the old library got uninstalled.

1. Have you ever manually installed in Node-red the `mysql` library in order to use it ?
2. If my assumptions are correct .. do you also have **node-red-node-mysql** installed ?

---

<div class="post-metadata">

### Author: ![Boja](https://avatars.discourse-cdn.com/v4/letter/b/3be4f8/32.png) [@Boja](https://discourse.nodered.org/u/Boja)
#### Post date: [4 February 2022 18:12 UTC](https://discourse.nodered.org/t/using-mysql-require-mysql-does-not-function-any-more-any-suggestions-why/57746/12 "2022-02-04T18:12:51Z")

</div>

I think I have found the problem. At least I'm now able to start NR and the DB access seems to be available again. I just need to test it proberly.

It looks like newer installations of Hassio no longer have the mysql directory in /config/node-red/node\_modules. Now there is a mysql2 directory present - even though the node-red-node-mysql module is still specified as beeing version 1.0.0 in Manage palette.

NR now starts if I use mysql:require(’mysql2’) instead of the usual mysql:require(’mysql’).

/ Thanks for all your feedback.

---

<div class="post-metadata">

### Author: ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)
#### Post date: [4 February 2022 21:21 UTC](https://discourse.nodered.org/t/using-mysql-require-mysql-does-not-function-any-more-any-suggestions-why/57746/13 "2022-02-04T21:21:27Z")

</div>

ah - so are relying on th library installed by the node-red mysql node... this change to mysql2 when we moved the node to version 1.0 - if you are just referencing node modules from a function node you need to make sure you also install the needed node module yourself into the ~/.node-red directory. I assume you didn't do that yourself so when we upgraded the module you were left referencing the old one.

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)
#### Post date: [5 April 2022 21:22 UTC](https://discourse.nodered.org/t/using-mysql-require-mysql-does-not-function-any-more-any-suggestions-why/57746/14 "2022-04-05T21:22:21Z")

</div>

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.
