In continuation to my previous question here (Fully details: connect Raspberry Pi 4 to a remote MySql database located on a server), I have been digging to find out what causing the error and why my Raspberry Pi 4
fails to connect to a remote MySql
database through JavaScript
but, it makes a perfect connection through Python
script.
I executed the following shelljs.exec()
command to know the cause (inspired from: how to run node shelljs in sync mode and get stdout and stderr) and I got the following output. I need help to know what this error mean and I need to do fix it.
My code and output:
>> var shell = require('shelljs');
>> const { stdout, stderr, code } = shell.exec(command, { silent: true })
>> console.log("Stdout: "+stdout+", Stderr: "+stderr+", Code: "+code)
# Output is
>> Stdout: , Stderr: /bin/sh: 1: mysql: not found, Code: 127
My understanding from above is, there is no output. But there is an error message called /bin/sh: 1: mysql: not found
and error code is 127
. I appreciate your help to understand what this error mean and what I need to do? Does it telling that my Raspberry Pi 4
is missing something, so it fails to connect to the remote MySql
through JavaScript
?
Update:
MySql
on the RPi
by referring https://pimylifeup.com/raspberry-pi-mysql/ The code is sudo apt install mariadb-server
pi@raspberrypi:~ $ /usr/bin/mysql -u fieldArduinoYUN -h aa.bb.cc.dd -p abcdf -e "use field_data; SELECT product FROM product_list WHERE product_id = 123;"
Enter password:
ERROR 1044 (42000): Access denied for user 'fieldArduinoYUN'@'%' to database 'abcdf'
pi@raspberrypi:~ $
Summarising the exchanges from the comments, there were the following issues and solutions.
The following error means that the shell (bash
/dash
/ash
etc) was unable to find the mysql
command:
/bin/sh: 1: mysql: not found
This normally results from the PATH
variable not being set to tell the shell where mysql
is located in the filesystem.
It transpired that, in this case, the reason was that the mysql
client was not installed. OP had thought that installing a Python module would provide a command-line MySQL client too.
The solution was to install the MYSQL client tools.
The second issue was that the password for the mysql
client tool wasn't being provided correctly which resulted in:
ERROR 1044 (42000): Access denied
This can be solved by providing the password immediately following the -p
option and without a space like this:
/usr/bin/mysql -u USER -h aa.bb.cc.dd -pPASSWORD -e "SOMECOMMAND"