I'm developing a script in RStudio which connects to local MySQL Server using the R package RMariaDB (not RMySQL - for other reasons though the outcome is the same).
I can both connect via storing the password in the script like:
localuserpassword <- "password"
all_projectsDb <- dbConnect(RMariaDB::MariaDB(), user='user', password=localuserpassword, dbname='projects', host='localhost')
or by way of a .my.cnf using credentials:
[client]
[mygroup]
host=127.0.0.1
user=user
password=password
port=3306
database=projects
and R code as
settingsfile = '/Users/oscar_w/.my.cnf'
all_projectsDb <- dbConnect(RMariaDB::MariaDB(), default.file = settingsfile, group="mygroup", dbname = 'projects')
The above work just fine but if I want to connect with .mylogin.cnf created in mysql_config_editor and looks like
[client]
[mygroup]
user = user
password = *****
host = 127.0.0.1
port = 3306
with the R script code like
# define location of config file
settingsfile = '/Users/oscar_w/.mylogin.cnf'
all_projectsDb <- dbConnect(RMariaDB::MariaDB(), default.file = settingsfile, group="mygroup", dbname = 'projects', password = NULL, user = NULL)
I get the error
Error: Failed to connect: Access denied for user 'root'#'localhost' (using password: NO)
I have tried various combinations of arguments expressing null or otherwise. And have entered my password with mysql_config_editor with double quotes around it. In https://cran.r-project.org/web/packages/RMariaDB/RMariaDB.pdf it specifies the use of .mylogin.cnf but I cannot find a way to make it work. Does anyone know a solution to this or has the same issue? Thanks
It looks like you're trying to log in both with and without a password, which isn't allowed. The RMariaDB documentation says that if the password argument is NULL or omitted, only users without a password can log in.
Related
I can connect to mysql using cli like this:
mysql -u cwaugh -p******** -h example.com mydb
However, when I try to use python3 with the same parameters, I get an error: mysql.connector.errors.ProgrammingError: 1045 (28000): Access denied for user 'cwaugh'#'xxx.xxx.xxx.xxx' (with my ip where the x should be)
My code for python looks like this:
import mysql.connector
import datetime
thinknode = mysql.connector.connect(
host = "example.com",
user = "cwaugh",
passwd = "********",
db = "mydb")
The credentials also work in javascript, but only if I used ssl: "Amazon RDS" when I created the connection (the database is on AWS RDS).
What do I need to do to connect from python? I can connect from other applications on this same computer, so I can rule out AWS Security Groups and MySQL host limits. This seems to only happen with python. Does this have something to do with ssl like it did with javascript?
You need to add the ssl_ca argument to the mysql.connector.connect function. Eg.
thinknode = mysql.connector.connect(
host = "example.com",
user = "cwaugh",
passwd = "********",
db = "mydb",
ssl_ca = "./rds-combined-ca-bundle.pem")
I'm not sure why javascript wass able to use "Amazon RDS", and it would be a lot easier if python did too, but it doesn't.
On my Mac I'm trying to connect to databases with unixodbc (v. 2.3.7 from Homebrew).
odbcinst -j shows:
DRIVERS............: /usr/local/etc/odbcinst.ini
SYSTEM DATA SOURCES: /usr/local/etc/odbc.ini
FILE DATA SOURCES..: /usr/local/etc/ODBCDataSources
USER DATA SOURCES..: /Users/homer/.odbc.ini
SQLULEN Size.......: 8
SQLLEN Size........: 8
SQLSETPOSIROW Size.: 8
Partial contents of ~/.odbc.ini and /usr/local/etc/odbc.ini:
[mysql-local]
description = local server
Driver = MySQLDriver
SERVER = localhost
USER = testuser
PASSWORD = testpass
DATABASE = testdb
Partial contents of /usr/local/etc/odbcinst.ini
[MySQLDriver]
Driver = /usr/local/lib/libodbc.dylib
Setup = /usr/local/lib/libodbc.dylib
FileUsage = 1
The Driver/Setup file links to a file that links to actual driver: /usr/local/Cellar/unixodbc/2.3.7/lib/libodbc.2.dylib. I have set the perms on this file to 755.
Then I try to connect:
isql mysql-local testuser testpass -v
The result is:
[IM004][unixODBC][Driver Manager]Driver's SQLAllocHandle on SQL_HANDLE_HENV failed
[ISQL]ERROR: Could not SQLConnect
For some reason I have osql, which the Web tells me is used to connect to SQL Server. (Perhaps it comes with the Brew's unixodbc?) I can use it to verify that the .ini files are being parsed correctly. Thus
osql -I /usr/local/etc -S mysql-local -U testuser -P testpass
results in:
"" is NOT a directory, overridden by
"/usr/local/etc".
checking odbc.ini files
reading /Users/homer/.odbc.ini
[mysql-local] found in /Users/homer/.odbc.ini
found this section:
[mysql-local]
description = local server
Driver = MySQLDriver
Server = 127.0.0.1
USER = testuser
PASSWORD = testpass
DATABASE = testdb
looking for driver for DSN [mysql-local] in /Users/homer/.odbc.ini
found driver line: " Driver = MySQLDriver"
driver "MySQLDriver" found for [mysql-local] in .odbc.ini
found driver named "MySQLDriver"
"MySQLDriver" is not an executable file
looking for entry named [MySQLDriver] in /usr/local/etc/odbcinst.ini
found driver line: " Driver = /usr/local/lib/libodbc.dylib"
found driver /usr/local/lib/libodbc.dylib for [MySQLDriver] in odbcinst.ini
/usr/local/lib/libodbc.dylib is an executable file
"Server" found, not using freetds.conf
Server is "127.0.0.1"
looking up hostname for ip address 127.0.0.1
Configuration looks OK. Connection details:
DSN: mysql-local
odbc.ini: /Users/homer/.odbc.ini
Driver: /usr/local/lib/libodbc.dylib
Server hostname: localhost
Address: 127.0.0.1
Attempting connection as testuser ...
+ isql mysql-local testuser testpass -v
[IM004][unixODBC][Driver Manager]Driver's SQLAllocHandle on SQL_HANDLE_HENV failed
[ISQL]ERROR: Could not SQLConnect
sed: /tmp/osql.dump.44362: No such file or directory
Everything I try always comes down to the same error:
[IM004][unixODBC][Driver Manager]Driver's SQLAllocHandle on SQL_HANDLE_HENV failed
For good measure, here are the logs from isql mysql-local testuser testpass:
[ODBC][54953][1538867223.117217][__handles.c][460]
Exit:[SQL_SUCCESS]
Environment = 0x7f9829010400
[ODBC][54953][1538867223.117416][SQLAllocHandle.c][377]
Entry:
Handle Type = 2
Input Handle = 0x7f9829010400
[ODBC][54953][1538867223.117521][SQLAllocHandle.c][493]
Exit:[SQL_SUCCESS]
Output Handle = 0x7f982903e800
[ODBC][54953][1538867223.117601][SQLConnect.c][3721]
Entry:
Connection = 0x7f982903e800
Server Name = [mysql-local][length = 11 (SQL_NTS)]
User Name = [testuser][length = 8 (SQL_NTS)]
Authentication = [********][length = 8 (SQL_NTS)]
UNICODE Using encoding ASCII 'UTF-8' and UNICODE 'UCS-2-INTERNAL'
[ODBC][54953][1538867223.126854][SQLConnect.c][1380]Error: IM004
[ODBC][54953][1538867223.127046][SQLFreeHandle.c][290]
Entry:
Handle Type = 2
Input Handle = 0x7f982903e800
[ODBC][54953][1538867223.127191][SQLFreeHandle.c][339]
Exit:[SQL_SUCCESS]
[ODBC][54953][1538867223.127276][SQLFreeHandle.c][220]
Entry:
Handle Type = 1
Input Handle = 0x7f9829010400
Notes:
I have seen the same error discussed elsewhere, where odbc-mediated connections to other databases (e.g., SQL Server) are desired. Solutions proposed in those cases do not appear to apply to MySQL connections.
I am hoping to make the connections this with linuxodbc, as this is the instrument said to be required for maximum SQLintegration in the R Studio IDE.
On Linux I find that unixodbc works fine.
Much thanks in advance to anyone who can point me in the right direction.
Ok so im setting up a postfix sql connection and for some weird reason, the same account that is accessing the previous two maps is now refusing the connection to 127.0.0.1. Two Connections are already working with the same credentials.
The first file the one with the issue (111)
user = exampleadmin
password = bgfoenawox
hosts = 127.0.0.1
dbname = exampleserver
query = SELECT destination FROM virtual_aliases WHERE source='%s'
This gives me the following error in putty,
postmap: warning: connect to mysql server 127.0.0.1:Can't connect to MySQL server on '127.0.0.1' (111)
postmap: fatal: table mysql:/etc/postfix/mysql-virtual-alias-maps.cf: query error: Connection refused
Working virtual email maps.
user = exampleadmin
password = bgfoenawox
hosts = 127.0.0.1
dbname = exampleserver
query = SELECT 1 FROM virtual_users WHERE email='%s'
This gives me the following result in putty,
1
Working virtual domain maps
user = exampleadmin
password = bgfoenawox
hosts = 127.0.0.1
dbname = exampleserver
query = SELECT 1 FROM virtual_domains WHERE name='%s'
This gives me the following result in putty,
1
I am following this guide here. Postfix Guide
Answer!
Finally, that didnt take long.
If anyone is having this issue, please try this.
nano /etc/postfix/mysql-virtual-alias-maps.cf
Change the hosts to
From : 127.0.0.1 > HOSTNAME e.g. server54
This will enable the connection to the localhost. And show the correct postmap.
postmap -q youremailhere#email.com mysql:/etc/postfix/mysql-virtual-alias-maps.cf
Result?
Your email address (example#example.com)
import webapp2
import MySQLdb
import os
class MainPage(webapp2.RequestHandler):
def get(self):
if (os.getenv('SERVER_SOFTWARE') and
os.getenv('SERVER_SOFTWARE').startswith('Google App Engine/')):
db = MySQLdb.connect(unix_socket='/cloudsql/fluent-outlet-604:test-db' , db='guestbook', user='root',passwd='root')
# connect to the cloud SQL
else:
db = MySQLdb.connect(host='173.194.248.221', port=3306, db='guestbook', user='root',passwd='root')
cursor = db.cursor()
cursor.execute('SELECT guestName, content, entryID FROM entries')
data = cursor.fetchall()
db.close()
self.response.write(data)
application = webapp2.WSGIApplication([
('/',MainPage),
],debug=True)
when i deploy this app to the app engine i gain error says
"(1045, "Access denied for user 'root'#'localhost' (using password: YES)")
I had the same problem, and solved it.
This problem is on Google Cloud SQL.
In the prompt console, re-start Cloud SQL like below,
gcloud sql instances --project [app engine project name] restart [sql instance name]
You should not specify the root password (even if you have set), when connecting from AppEngine.
Remove the passwd param from line 9 of your code so that it looks like:
db = MySQLdb.connect(unix_socket='/cloudsql/fluent-outlet-604:test-db' , db='guestbook', user='root')
The example code in this article also shows this.
I saw this problem when I didn't specify the hostname in the database URI:
SQLALCHEMY_DATABASE_URI = (
'mysql+pymysql://<user-name>:<password>#/<database-name>'
'?unix_socket=/cloudsql/<connection_name>'
Changing it to the following fixed it:
SQLALCHEMY_DATABASE_URI = (
'mysql+pymysql://<user-name>:<password>#<host-name>/<database-name>'
'?unix_socket=/cloudsql/{connection_name}'
I installed SQL Server 2012 Express and I'm learning from a book on SQL Server administration. My task is to write a batch file to copy data from a table and export it to an Excel spreadsheet.
I've got the instance name right and my username but log in fails because of password. When I enter Management Studio and click connect I see my username but password is blank, I successfully connect to my databases this way. How do I set a password for my account? I think I can't log in using SQLCMD because I don't have this set. My username is the same as my windows username, using the password that I log on to windows with doesn't work.
SQLCMD -S CRAIG-PC\SQLExpress -U CRAIG-PC\Craig -P *********
-d AdventureWorks
-Q "SELECT * FROM Sales.SalesOrderDetail" -o C:\ExportDir\export.csv
This is the command in the batch file that I'm trying to connect and query the database. If I take out -P ******* SQL Server is waiting for a password. If I don't use a username or password connection is refused.
Remote connections are enabled using tcp, but this is a local install.
Use the '-E' switch to make your connection a trusted (Window's authentication) one, then you don't need user name and password at all (provided you have sufficient rights on your machine)
http://technet.microsoft.com/en-us/library/ms162773.aspx
Note in my python code below, I don't implement the user or password.
Hope that helps
_query = "CREATE DATABASE %s ON (FILENAME = '%s'), (FILENAME = '%s') FOR ATTACH;" %(_database, mdffilepath, logfilepath)
command_process = SubP.Popen(['sqlcmd','-b', '-E',
'-S', _server,
'-d', 'master',
'-q', _query],
stdin = SubP.PIPE,
stdout = SubP.PIPE,
stderr = SubP.STDOUT,
shell = True)
_stdOut, _stdError = command_process.communicate()
Check the name of the database, ie "AdventureWorks" should be "AdventureWorks2012"
sounds like you are using windows authentication you can remove the -u and -p. when those are not provided sqlcmd will use windows authentication.