What's the conncetion URL for mysql in sqlalchemy while connecting to google app engine ??
I know it's
mysql+gaerdbms:///<dbname>?instance=<my cloud instance name>
But where to specify user, password and host. I get below error while connecting with above string.
947, in MakeRequest raise _ToDbApiException(response.sql_exception) OperationalError: (OperationalError) (1045, u"Access denied for user 'root'#'localhost' (using password: NO)") None None
The mysql+gaerdbms:// is deprecated. Please use the mysql+mysqldb:// instead. The format of the connection URI is:
mysql+mysqldb://root#/<dbname>?unix_socket=/cloudsql/<projectid>:<instancename>
Note that the above only works in App Engine prod. The recommended way to connect from dev_appserver is to request an IP and use that to connect.
Reference: http://docs.sqlalchemy.org/en/latest/dialects/mysql.html?highlight=appengine#module-sqlalchemy.dialects.mysql.gaerdbms
Related
I am getting the following error while trying to run a python application that uses the following regex entry
database:
host: 127.0.0.1
name:
password:
port: 3306
user:
I am getting the following error on console.log when I am trying to run the application using the database.
super().__init__(*args, **kwargs2)
sqlalchemy.exc.OperationalError: (MySQLdb._exceptions.OperationalError) (1045, "Access denied for user 'ahmed'#'localhost' (using password: NO)")
(Background on this error at: https://sqlalche.me/e/14/e3q8)
I am pretty new to command line based MySQL and ubuntu itself
If we fail to provide a username and password to the MySQL dialect then the drivers (mysqldb and pymysql, at least) attempt to log into the MySQL server without a password using the current username from the OS.
import sqlalchemy as sa
engine = sa.create_engine(
sa.engine.URL.create(
"mysql+pymysql",
host="192.168.0.199",
database="test",
)
)
with engine.connect() as conn:
"""
sqlalchemy.exc.OperationalError: (pymysql.err.OperationalError)
(1045, "Access denied for user 'gord'#'192.168.0.179' (using password: NO)")
"""
You will either need to provide SQLAlchemy with a valid username and password for the MySQL server, or create a MySQL user named "ahmed" without a password that has permission to access the database for your application.
I am hosting my flask website on ubuntu 18.04 server but I am using Flask SQLAlchemy to connect to my database previously (30-45 days ago) I connected it successfully but now I am getting this error -
sqlalchemy.exc.OperationalError: (MySQLdb._exceptions.OperationalError) (1045, "Access denied for user 'root'#'localhost' (using password: NO)")
I am using the following code to connect to the database from my flask website -
app.config['SQLALCHEMY_DATABASE_URI'] = "mysql://root:helloworld#localhost/vit"
app.config['MYSQL_HOST'] = "localhost"
app.config['MYSQL_USER'] = "root"
app.config['MYSQL_PASSWORD'] = "helloworld"
app.config['MYSQL_DB'] = "vit"
app.config['MYSQL_CURSORCLASS'] = "DictCursor"
I tried to create a new user in MySQL by native password, I tried to grant all privileges to root, I tried to also change the password of the root, I also tried to use mysql+pymysql in SQLALchemy URI. But no one method is working.
Kindly suggest to me any solution to this problem.
Click to see RDS settings
Im trying to connect to a MYSQL server on Amazons Web Service, specifically the RDS- using SQLAlchemy in python (Pycharm).
I've already installed drivers for pymysql to include in the connection string for the engine (engine = create_engine("mysql+pymysql://...).
I've tried setting the CIDR security group inbound and outbound rules to allow any IP.
I can connect to the AWS-RDS just fine from MYSQL Workbench suing the Endpoint, Port and credentials.
I was able to connect to a local instance of MYSQL using SQLAlchemy and create_engine(...) without any issues too.
I've tried including and excluding the port from the URL.
try: # exception handling for database creation/ existence
engine = create_engine(link_to_db, pool_pre_ping=True, pool_recycle=3600) # Access the DB Engine
connection = engine.connect()
print("Database conn 1 successful")
except Exception as e:
logging.exception(e)
print("error connecting to db")
where link_to_db is "mysql+pymysql://{RDS USERNAME}:{RDS PASSWORD}#
{RDS ENDPOINT}:3306/{DATABASE NAME}"
The expected result is
"Database conn 1 successful"
printed to the output.
Errors :
sqlalchemy.exc.OperationalError: (pymysql.err.OperationalError) (2003, "Can't connect to MySQL server on '{RDS URL}' ([Errno 11001] getaddrinfo failed)")
(Background on this error at: http://sqlalche.me/e/e3q8)
Kindly check the below things.
1) Check your rds is publicly accessible to YES. if its in private subnet check connectivity between your source(office/home/etc) to destination(RDS).
2) open 3306 in the security group.
3) check master user credentials.
# telnet {rds end-point} 3306
I found that it was as simple as changing from a multiline string """ {link} """ to single quotes '{link}'.
I am using
db = MySQLdb.connect(host="machine01", user=local_settings.DB_USERNAME, passwd=local_settings.DB_PASSWORD, db=local_settings.DB_NAME)
to connect to a DB, but I am doing this from machine02 and I thought this would still work, but it does not. I get
_mysql_exceptions.OperationalError: (1045, "Access denied for user 'test_user'#'machine02' (using password: YES)")
as a result. However, if I simply ssh over to machine01 and perform the same query, it works just fine. Isn't the point of host to be able to specify where the MySQL db is and be able to query it from any other host instead of having to jump on there to make the query?
Make sure your firewall isn't blocking port 3306.
The error tells you that 'test_user' at machine 'machine02' is not allowed. Probably user 'test_user' is on 'mysql.user' table registered with 'localhost' as connection's host. Check it using a query like this: select host, user from mysql.user;
Best regards,
Oscar.
I am new to python and network programming.
Recently I am having trouble accessing my online database.
The problem is that I want to write a code and execute it on my computer to acces my online data base, and the only thing I want to do is to access the informaion in my database and do some change.
The first question is that I don't know what to use as parameters.
here is what show up on my online database, which I can access using internet browser:
173.201.136.195
Server version: 5.0.96-log
Server: 173.201.136.195 via TCP/IP
User: user123123#72.167.233.37
MySQL charset: UTF-8 Unicode (utf8)
I don't understand which ip should I use when i connect to it, '173.201.136.195' or '173.201.136.195' and which username should I use. 'user123123' or 'user123123#72.167.233.37'
This is the code I use:
conn = pymysql.connect(host='173.201.136.195',user='user123123',passwd="123123123",db='TestData')
phthon shell shows that:
File "F:\Program Files\Python33\lib\pymysql\connections.py", line 819, in _connect 2003, "Can't connect to MySQL server on %r (%s)" % (self.host, e))
pymysql.err.OperationalError: (2003, 'Can\'t connect to MySQL server on \'173.201.136.195\' ((1045, "Access denied for user \'user123123\'#\'142.151.201.116\' (using password: YES)"))')
What on earth is 142.151.201.116 ?
the error means that access to the server 173.201.136.195 is denied to the user user123123 at ip 142.151.201.116. When you give access to a user on mysql database you specify the ip or wildcads for multiple ips. So access to the database for user is per ip.
example:
GRANT ALL PRIVILEGES ON *.* TO 'username'#'%' IDENTIFIED BY 'password' WITH GRANT OPTION;
will give access to username on all hosts. but this:
GRANT ALL PRIVILEGES ON *.* TO 'username'#'10.20.30.40' IDENTIFIED BY 'password' WITH GRANT OPTION;
will give access to username at ip 10.20.30.40
this information is on mysql.user table