NodeJS mysql - Managing Multiple MySQL DB with 1 connection - mysql

I want to use multiple db with 1 connection to MySQL server with a user. I am making a web server but it will get connections from multiple hostnames like example.com example2.com and they will have a panel to manage their page. Then they will have these credentials to connect: username, password and db name. So they can integrate to other things they want. But while we are creating a pool we specify a database and I want to optimize db connection so I don't want to create multiple connections. I am using mysql2 with multiple db connections for now.
Thanks!

It worked when I used a query like this:
SELECT value FROM databaseName.tableName WHERE name="something"

Related

Outsystems: configuring a connection to access a MySQL database

I'm using Outsystems Service Studio to develop a web application. I need to configure a connection to access a local server database. I get "Connection String test failed: Unable to connect to any of the specified MySQL hosts." I just figured out I can't connect using "localhost", because the Outsystems server is not local, but I'm not able to find a solution. what is wrong? Other details:
MySQL Server is up and running
I selected MySQL in DBMS
Inserted my schema name
Inserted the username (with all privileges granted)
Inserted the user password
Tried both basic and advanced configuration. I inserted j"dbc:mysql://127.0.0.1:3306/mydb?user=outsystems2" as connection string parameters and I get "Connection String test failed: Keyword not supported.Parameter name: mysql://127.0.0.1:3306/mydb?user". I know this connection string can't work , but I'm not able to find a functioning one. I've read many guides about this configuration, but no solution was found. Thank you all for your time and help, feel free to ask for more details
Luciano,
Is your OutSystems environment on-premises or in the cloud? Either way, you need to make sure that this server is able to reach - it as connectivity - to your MySQL database server. Using localhost or 127.0.0.1 is pretty much the same thing as this is an address for the machine where the request is running, which is, in this case, the OutSystems server. Do you have the MySQL database on your local machine? This is not a good approach as you will need to have an address that won't change otherwise the connection won't be stable and you'd have to reconfigure it all the time.
Regards

How to know where my MySQL database is being hosted and how can I access it?

I have the following information to a SQL database
Server : MyUserName.mysql.db
User : MyUserName
Password : MyPassWord
I am a little noob in this context, so I have some questions:
How to know where is hosted my database? Is it in mysql domain? (Isn't that the type of database?)
How can I access it and visualize it?
To begin with, you need a CLIENT to be able to access your database. For MySQL, you can use either Workbench or MySQL CLIENT (the last giving you command-line level access).
Second, and according to your information, the server is MyUserName.mysql.db so if you try to PING that server you should get some response.
Third, MySQL has a default port number so you need to configure your client to access that server though that port (if I'm not mistaking, 3306).
You will also need access credentials to your database.
Your DB administrator should be able to provide all the information you need.
Contact your database administrator.
If you're trying to acess/visualize sql server database on your local computer install ssms to connect to your local database , similarly you can access any other database through ssms.

Multiple server cluster setup. How do I track which server is connecting to the parent mysql?

I have a setup of 12 download servers, they all have their ip and login details in a mysql database on my database server.
The database has a dlserver_details table with following fields:
id, server name, location, domain, ip address, additional ips
Each row in this table has a specific server's records.
How do I find out which server is connecting to the mysql so that mysql can send the correct server's information?
For example if Server A is connecting to mysql through remote sql, there is no way of knowing which row belongs to Server A.
The solution I came up with 4 years ago was to assign each server an id manually and save it in a file called config.php
When the server wants to fetch its details from the mysql db, it sends query like:
$serverid = 4;
SELECT * from dlserver_details where id = $serverid
Which works perfectly fine.
But the problem is that this solution is not very efficient as we are scaling up. Whenever we add servers to the cluster, we have to modify some files and the database. This slows things down as the files are synced automatically to all the download servers then I have to manually assign the correct server id and update its records in the database.
Is there a proper solution to this? Like Can I track with mysql which host is connecting to it for the query so that it can look for the correct record for that host on its own?
Something like:
lets say mysql ip is 1.1.1.1 and client server ip is 2.2.2.2
row in the table:
id = 4
ip = 2.2.2.2
servername = Server A
Query: SELECT * FROM dlserver_details WHERE ip = CONNECTING_HOST_IP
Would that work?
Ended up doing it with:
... WHERE ip = (Select SUBSTRING_INDEX(host, ':', 1) From information_schema.processlist WHERE ID = connection_id())

Alter MySQL auto_increment with Heroku ClearDB addon

My Rails app is hosted on Heroku. I have a problem with MySQL incrementing by 10: Large Auto Increment IDs
I really want to change it to 1, and I have found the SQL command for that. However, I cannot figure out how to connect to mysql via Heroku to perform it. Is there a workaround? Is it even possible?
You can connect to the database hosted by ClearDB using your local mysql command line client application. First you'll need to check your database URL to get the necessary connection details, so run heroku config and you should see a line that looks something like this:
CLEARDB_DATABASE_URL: mysql://abcdef01234567:9876543#us-cdbr-iron-east-01.cleardb.net/heroku_fedcba76543210?reconnect=true
The URL contains the username, password, host and database name in the format:
mysql://username:password#host/database?reconnect=true
With those four pieces of information you can connect to your database. Using the (made up) example database URL as an example:
mysql --user=abcdef01234567 --password9876543 --host=us-cdbr-iron-east-01.cleardb.net heroku_fedcba76543210

Find the number of active connections per database in MySQL

I have a drupal application that uses the database named db1. Each time a drupal request is sent, a new connection to database will be established.So after a certain number of conneections has reached the site turns offline showing the following error:
User db1 already has more than 'max_user_connections' active connections.
So my aim is to close the database connection and thereafter avoiding the offline error. For this I need to find the number of active connections made to my database.I have tried with the SHOW PROCESSLIST command. But it is not showing the number of connections.
Is there any method to find the number of database connections made to a mysql database?
Thanks,
SHOW STATUS LIKE 'threads_connected';
Although if your Drupal (or the webserver to be precise) is not closing connections automatically after each request, there's probably something that is not configured correctly.