Unable to connect to MAMP MySQL database using Wakanda's remote connection - mysql

I'm trying to connect to a MAMP MySQL database from Wakanda 11.
I tried connecting to the localhost database using Connect to Remote Datastore but I keep getting a Connection failed response. I've also tried using port 127.0.0.1:8081 which it connects to but not when attempting to use port:3306 which is where I have the MySQL database configured on the MAMP server. What am I doing wrong?
I've tried the following script...
model.addSQLCatalog("mysqldb", {
hostname: '127.0.0.1',
port: 3306,
user: 'root',
password: 'xxxxxxxx',
database: 'my_database_name',
ssl: false,
dbType: 'mysql'
});
...but this gives me the following error:
TypeError: JSON.stringify cannot serialize cyclic structures.
How can I fix and make it work on port:3306 so I can see my database structures?

If you are using Wakanda Enterprise Edition 11 or higher there is a MySQL Connector Pro.
Here is an example of connecting with this:
model.mergeSQLCatalog(localName, {
hostname: string 'host name',
port: number remote_port_number,
user: string 'userName',
password: string 'password',
database: string 'SQL database name',
jsFile: string 'configuration JavaScript file',
ssl: boolean true or false,
dbType: string 'mysql' } )
If you are on an older version of Wakanda Enterprise Edition but still using version 7 or higher then there is a Wakanda/MySQL connector.
Here is an example of connecting to MySQL with the connector:
var sql = require('waf-sql');
//use port 3306 and do not use SSL
var dbconn = sql.connect('mysql','192.168.0.21', 'john', 'x54?hsf5x!','arts',3306,false);
var rs = dbconn.update("people", {
name: "smith",
age: 42
}, {
id: 1
});
var rs = dbconn.select("*", "people", {
id: 1
});
var row = rs.getNextRow(); // get the first row
dbcon.close(); // close connection
Here is an example of the available parameters:
var params = {
hostname: [your host name or IP address],
user: [the user name of your DB],
password: [the user password],
database: [the DB name],
port: [the port number of the MySQL Server, by default 3306],
ssl: false,
dbType : 'mysql'
};

If I'm correct your issue has been solved? Does it work for both Windows & Mac ?
To resume , to use ProCOnnector you'll need :
The Enterprise Version of Wakanda
For the current v11 version of Wakanda, you need to use in the model.js file the addSQLCatalog() API.
The parameters accepted are described in the doc
Please note in the next version of Wakanda we 'll provide to wizzard to connect to other DBs instead of the addSQLCatalog(). This will help and ease the process.

Related

Can't add new command when connection is in closed state (express.js + mysql2 + mysql2/promise + clearDB + heruko)

i am facing thi error whenever i make a second call to the api i created using mysql2+expressjs+clearDB(on HERUKO)+heruko deployment server
this is my code ....
const [rows,fields]= await db.execute(MYQUERY,[myarguments])
i am calling the mysql server like this with asyn/await functionality which mysql2 provides
import mysql from 'mysql2/promise'
after that i create the the connection
let db = await mysql.createconnection({
host: 'localhost',
user: "root",
password: "asdzxcasdzxc123123",
database: "doctorapp"
})
export { db }
Any sollution to this error...???
i was facing this error in mysql2/promise
Reason for this error
The actual problem is with mysql2/promise .
when you create your connection with mysql database with mysql2 npm package
this thing is causing the error...
Sollution to this error
i solved this error by creating my connection with mysql.creatPool(yourCredentials)
creat your db config file like this
import mysql from 'mysql2'
let db = mysql.createPool({
host: 'Enter your host here',
user: "enter user name here",
password: "enter you password",
database: "enter the database name",
waitForConnections: true,
connectionLimit: 10,
queueLimit: 0
})
export { db }
Use of db in your contollers or router should be like this
const promise = db.promise()
const select_user_query=`
select *
from users
`
const [rows,fields]= await promise.execute(select_user_query)
return res.status(200).json({users:rows})
One thing to note===>
you have to create
const promise= db.promise()
in all the contollers ... so it will automatically handles all the required connnection release or other things required to make the connection working perfectly

Connect to RDS MySQL programatically (NodeJs, Java) - ER_ACCESS_DENIED_ERROR: Access denied for user

I am trying to connect to my RDS (AWS MySQL database) using NodeJs mysql library.
const mysql = require('mysql');
var connection;
connection = mysql.createConnection({
host: 'xxx.us-east-1.rds.amazonaws.com',
port: 3306,
user: "username",
password: "MyPassword",
database: "DbName",
});
I was also trying mysql2 and sequelize. All of them got me the same result:
{
error: ER_ACCESS_DENIED_ERROR: Access denied for user 'username'#'myhost,
code: 'ER_ACCESS_DENIED_ERROR',
errno: 1045,
sqlState: '28000'
}
However, this remote database is set to public and I am able to connect to it with mysql command:
mysql -u username -pMyPassowrd -h xxx.us-east-1.rds.amazonaws.com
I am also able to connect to it with MySQL Workbench.
Also, the problem is not in NodeJs, because I am able to connect to my local database:
connection = mysql.createConnection({
host: 'localhost',
user: 'root',
password: 'root',
database: 'test',
});
In conclusion, my AWS database is publicly available and I can connect to it, just not using NodeJs for some reason.
I have not found a useful answer yet. Did anyone encounter this problem ?
UPDATE:
Trying to connect in Java with simple Connection returns the same result as well:
final Connection con = DriverManager.getConnection("jdbc:mysql:/xxx.us-east-1.rds.amazonaws.com:3306/DbName", "username", "MyPassword");
UPDATE 2:
I was missing one slash for Java code. I needed to use jdbc:mysql:// instead of jdbc:mysql:/. But NodeJs implementation is still one big mystery.
The answer was rather simple, just add an ssl option with true value
connection = mysql.createConnection({
host: 'xxx.us-east-1.rds.amazonaws.com',
port: 3306,
user: "username",
password: "MyPassword",
database: "DbName",
ssl: true //this does the trick
});

Error in sql connector configuration when connecting using Ballerina MYSQL Client

I'm trying to comment using Ballerina Mysql client.(Ballerina version - 0.990.2 ,MySQL JDBC driver-5.1.6) But I'm getting error as
error: error in sql connector configuration:Failed to initialize pool: Unknown initial character set index '255' received from server. Initial client character set can be forced via the 'characterEncoding' property.:Unknown initial character set index '255' received from server. Initial client character set can be forced via the 'characterEncoding' property. {}
mysql:Client testDB = new({
host: "localhost",
port: 3306,
name: "users",
username: "root",
password: "password",
poolOptions: { maximumPoolSize: 5 },
dbOptions: { useSSL: false }
});
I found the solution for the error. This is due to the mismatch in the mysql version and MySQL connector version. I downloaded the suitable version from http://central.maven.org/maven2/mysql/mysql-connector-java/

Sequelize ORM: How to connect to MYSQL on localhost, using the 'host' property?

I'm trying to connect to my local MYSQL(ran by XAMPP) through Sequelize:
const sequelize = new Sequelize(process.env.MYSQL_DB, 'root', '', {
host: process.env.CLEARDB_DATABASE_URL,
dialect: 'mysql',
logging: false
});
The process.env.CLEARDB_DATABASE_URL variable is set to "localhost", just like the documentation says(i'm using this specific variable because i want to deploy to Heroku later)
I'm getting the following error:
getaddrinfo ENOTFOUND localhost'; localhost';:3306
The process.env.MYSQL_DB variable is just the name of my database.
It all worked when i was using the "short way" to connect:
var sequelize = new Sequelize(process.env.MYSQL_DB , "root", "", {
dialect:'mysql',
logging: false
});
Can someone tell me what might be wrong with my setup?
EDIT: if anybody is interested, the problem was that i put a semicolon after the variable deceleration in my .env file.......

Acces database from appfog's node.js server (Database settings)

I'm trying to connect to a database using a node.js server both hosted on appfog.com using these settings:
var client = mysql.createConnection({
host: 'mysql-node01.eu-west-1.aws.af.cm',
user: '****#gmail.com',
password: '*******',
database: 'd2dc10d6a450048b587114fa9b11756ed',
port: 3306
});
I'm pretty sure the host, database and maybe port are incorrect but I don't know which values to use, i.e. should I use localhost?
Use the db credentials from the VCAP_SERVICES environment var and do not hard code them. The credentials are provided when the app is started on AppFog. See the Appfog Node Docs
var env = JSON.parse(process.env.VCAP_SERVICES);
var creds = env['mysql-5.1'][0]['credentials']; # grabs the creds for the first mysql database
var client = mysql.createConnection({
host: creds.hostname || 'localhost',
user: creds.username,
password: creds.password,
database: creds.name,
port: creds.port || 3306
});
I created a npm package to help facilitate getting production and development credentials. See AppFog Env
How to use it:
First set a local env var with your local dev database credentials:
export DEV_DB_CREDS='{ "username": "root", "name": "dev-db-name" }'
Then get the creds in the app:
var service = appfog.getService('mysql-db-name', process.env.DEV_DB_CREDS)
var creds = service.credentials
This method allows the same code to work locally and in production.