MySQL Connector/MXJ: authentication issue - mysql-connector

I would like to get started with MySQL Connector/MXJ. I am not sure how the authentication works. Where do I specify the actual user/password pair before connecting to mysqld?
I tried the following URL connection to no avail:
jdbc:mysql:mxj://localhost:3336/bignibouTest?server.basedir=/home/julien/tmp&createDatabaseIfNotExist=true&server.initialize-user=true&server.initialize-user-name=root&server.initialize-user-password=root
I systematically get "java.sql.SQLException: Access denied for user 'root'#'localhost' (using password: YES)".
Maybe it if someone could let me know how not to use a password, it would work.

One satisfactory workaround I found it to specify server.initialize-user=false and use:
user:"root"
password:""
in other words, MySQL's default password for root seems to be an empty string.
As far as unit tests are concerned this is OK.

Related

MongoserverError: bad auth: authentication failed problem

I correctly use the username and password in the url of vs code for my server side but in the cmd i find the error of mongodb authentication fail. why this is happening?
rewrite the uri again and give the username and password again. sometimes connection fails. that's why it happens. hope problem will be solved.

How do I stop DBI connect from adding #localhost to my username?

This is a newbie question - don't overthink it!
I'm trying to make a connection from perl to a remote server's MySQL database that I can connect to just fine from PHP or from TOAD, so I know clearly what my host, dbname, username and password are.
But when I try to do this from my new installation of Strawberry Perl using the Padre IDE, something somewhere ( probably some config file ?) keeps insisting on adding '#localhost' to my username.
Oh, I'm using perl, v5.10.1 (*) built for MSWin32-x86-multi-thread.
I'm trying:
my $DBHOST = "50.88.64.41";
my $DBNAME = "keystrokes";
my $DBUSER = "wade\#'50.88.64.41'";
...
# MySQL database configuration
my $dsn = "DBI:mysql:database=$DBNAME,host=$DBHOST,port=3306";
So I get this output ( slightly sanitized for privacy):
DBI connect('database=keystrokes,host=50.88.64.41,port=3306','wade#50.88.64.41',...) failed: Access denied for user 'wade#50.88.64.41'#'localhost' (using password: YES) at C:\Bitnami\wampstack-8.0.8-0\apache2\htdocs\perl\firstscript.pl line 2.
Whether I put in my username as "wade" or as "wade#50.88.64.41" or "wade#'50.88.64.41'" SOMETHING then adds "#'localhost' to it, then tries to use that as the username, which of course fails, because I'm not on that machine and it is not my localhost.
Any ideas how to fix this? I couldn't find any explicit answers in this forum.
Thank you!
I think your problem is the exact opposite of what you think it is. MySQL is doing the right thing by adding '#localhost' to your username. What you don't need is the `#50.88.64.41' that you add. I've been connecting Perl programs to MySQL databases for fifteen years and I've never needed to add something like that to a username.
The '#host' that you'll see in MySQL connection messages is added by the MySQL client library when making the connection - by looking at the IP address that the connection request is coming from.
So just change your code to:
my $DBUSER = 'wade';
and it should work.
Traditionally, you'll see two rows for each user in the mysql.user table. One with a host of localhost and the other with a host of % (which means "any other host"). That makes it easier to control access to the database - it's common that you would only allow access to users who are on the same server as database.

Connecting to MongoDB database on mLab fails authentication

I have a Parse app, and I'm trying to migrate my app's database to a MongoDB instance on mLab.
I already have a fork of Parse Server set up on Heroku, and I'm using Heroku's mLab MongoDB add-on.
I have a database on mLab called heroku_1ksph3jj, and I should be able to connect to it with the following template:
mongodb://<dbuser>:<dbpassword>#ds047124.mlab.com:47124/heroku_1ksph3jj
However, each attempt returns:
Server returned error on SASL authentication step: Authentication failed.
I'm unsure what to replace <dbuser> and <dbpassword> with. I have a database user with the same name as my database: heroku_1ksph3jjz, so I used that. And I used the password for that user in place of <dbpassword>. Should I have used something else here?
You can get the dbuser and dbpass with:
heroku config | grep MONGODB_URI
Grab the dbuser (example_user) and dbpass (example_pass) from the response:
MONGOLAB_URI: mongodb://example_user:example_pass#mlab.com:12345/db
As of March 2016, mLab.com only supports mongo 3.0+ (as per a conversation with support), because of their new onerous authentication requirements.
This was not on the website, but I hope it helps someone here!
There's a message to create a user for the specific database:
A database user is required to connect to this database. To create one now, visit the 'Users' tab and click the 'Add database user' button
I'm so sorry that this may seem obvious but, you have to remove this characters <> for the migration to work
In your example would look like this:
mongodb://dbuser:dbpassword#ds047124.mlab.com:47124/heroku_1ksph3jj
Check your mongo client version. If it is in older major version (probably 2.x), update it to 3.x
For future visitors - don't use special characters in password .Even if you change the special character to ascii or unicode it wont work for mLab using mongoose.
Also don't use mLab credential , use db user credentials . I created a new user.
Eg. For me a password containing # character was replaced with ascii value %40 in URI , which worked when using native mongodb driver.
But on using mongoose, i was always getting Authentication Failed .
I removed special characters and db was authenticated via mongoose.
It looks like it was the password that was incorrect, which I'm assuming was set up by Heroku's mLab add-on. There was no obvious way to reset this in the mLab UI, so in the end I created another database user (with a new username and password) and was able to connect with that just fine.
Just go to your Heroku dashboard and check your settings.
Under the name field there's a big button "Reveal Config Vars". Click it and you'll see a MONGODB_URI var with a uri to your db. It'll look something like this:
mongodb://heroku_user:PASSWORDyourLOOKINGfor#ds2238985.mlab.com:63295/heroku_user
Your password is right after the semicolon after the heroku user name.
I know I am too late, just for information.
For getting the info of mLab account that got auto created when mLab addon got added to the application in your heroku account, try the below command.
heroku config:get MONGODB_URI
Ref:
http://algebra.sci.csueastbay.edu/~grewe/CS6320/Mat/NodeJS/Heroku/Heroku_MLabMongoDB.html

Force postgres_fdw to use password?

I have two databases set up as part of the same Postgresql 9.4 database cluster, and I'm trying to access a table in one of them from the other using a postgres_fdw. I have it all set up and working as a superuser, however when I try to access the foreign table as a normal user, I get the following error:
ERROR: password is required
DETAIL: Non-superuser cannot connect if the server does not request a password.
HINT: Target server's authentication method must be changed.
Now I understand that this is because I have the server set up with trust authentication for certain subnets, including Its own. However, in the 1 USER MAPPING I created, I did specify a password, with the hope that doing so would force it to use password authentication. No such luck apparently.
As such, my question is if there is any way around this somewhat onerous requirement? Is there a way to force this connection, or a specific user, or the like to use password authentication? Or some way to disable the requirement? Or is my only option to change the configuration to require passwords, and deal with whatever that breaks?
As Nick Barnes pointed out in a comment, pg_hba allows different authentication rules for specific users. As such, the solution to this issue was to simply create a user specifically for these FDW connections, and set that user in the pg_hba.conf to require a password. That way my trusted web apps on the trusted network can continue connecting as usual, but the FDW can get the password request it requires.
You can't force FDW to use a password: the server on the other end must request the password. the usual default for local socket connections is no password.
Try connecting via TCP instead of using local sockets: add host=localhost to the connection parameters, that will usually fix it.

What do I need to specify to get .pgpass to work?

Can someone point me to a piece of documentation that specifies the matching rules psql applies to the .pgpass file? I always spend a few extra keystrokes trying to find the right combination of host, port, database, username to get it to connect.
Some things are obvious (i.e. if my linux username is not the same as my postgres username than I need to specify it) but based on what I've seen there is some non-obvious behavior.
Here is the documentation you are probably looking for. It explains the rules pretty well.
Just so this isn't a link-only answer, here are the rules:
Each .pgpass entry is on its own line and has the following format:
hostname:port:database:username:password
You can use a wildcard (*) for each field except password
If you use wildcards, put more specific entries first
You can use for instance localhost:*:*:foo:password to specify password for user foo on your local machine regardless of the database you are connecting to or the port the Postgres is actually running on.