f_dbI am trying to connect to mysql database using a python script. My code to do so is the following:
`db = MySQLdb.connect(host="xxx.xx.xx.xx", # your host, usually localhost
port = xxxx,
user="chrathan", # your username
passwd="...", # your password
db="f_db") # name of the data base`
I ve open the database from mysql workbench. However, I am not able to open it from python I am getting the following error:
_mysql_exceptions.OperationalError: (1044, "Access denied for user 'chrathan'#'%' to database 'f_db'"). Basically I am receiving `Traceback (most recent call last):
File "D:\_WORKSPACE\mysql\fashion_db.py", line 7, in <module>
db = 'f_db') mysql_exceptions.OperationalError: (1044, "Access denied for user 'chrathan'#'%' to database 'f_db'")`
enter this command on mysql terminal
$> mysql
GRANT ALL PRIVILEGES ON f_db.* TO 'chrathan'#'%' identified by 'secret'
for add user to database in mysqlworkbench look at this page How to Create a MySQL Database with MySQL Workbench
maybe you should check db name whether is same, the same problem occour on me, finally i found mysqlclient db name is not same as i use in python
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 trying to establish a connection with a MySQL database in a python program
import mysql.connector
cnx = mysql.connector.connect(
host='localhost',
user='admin',
password='admin1234',
database='meu_banco'
)
cnx.close()
print(cnx)
but keep getting the following error:
mysql.connector.errors.ProgrammingError: 1045 (28000): Access denied for user 'admin'#'localhost' (using password: YES)
Im am pretty sure that the username is admin and that I've setted 'admin1234' as the password. Anyone knows what might be happening?
Notes:
-I've also tried to use 'passwd' and 'db' instead of 'password' and 'database' keyword arguments.
-I'm using MySQL that comes with XAMPP version 8.0.2 / PHP 8.0.2 for Linux.
You are connecting to the database and afterwards you are closing the connection.
Only use cnx.close() when you want to close the database connection, it may cause an error.
If that's not the problem, you may have the user wrong, try to use the default username that MySQL Workbench has, it is root.
I have saved the DB2 username and DB2 password as 'DB2_USER' and 'DB2_PASS' in .bashrc(linux). And, I'm trying to invoke them in my python program to connect to DB2 database.
.bashrc content:
export DB2_USER="my_username"
export DB2_PASS="my_password"
My python code snippet:
db_user = os.environ.get('DB2_USER')
db_password = os.environ.get('DB2_PASS')
conn = ibm_db.connect('DRIVER={IBM DB2 ODBC DRIVER};DATABASE=<my_db>;HOSTNAME=<my_hostname>;PORT=50000;PROTOCOL=TCPIP;UID=db_user;pwd=db_password','','')
while executing the above code , I'm getting the below error. May I know for any other alternative ways?
Traceback (most recent call last): File "test.py",
line 38, in
conn = ibm_db.connect('DRIVER={IBM DB2 ODBC DRIVER};DATABASE=<my_db>;HOSTNAME=<my_hostname>;PORT=50000;PROTOCOL=TCPIP;UID=db_user;pwd=db_password','','')
Exception: [IBM][CLI Driver] SQL30082N Security processing failed
with reason "24" ("USERNAME AND/OR PASSWORD INVALID"). SQLSTATE=08001
SQLCODE=-30082
My earlier code literally took db_user & db_pass as username and password. Constructing the connection string using concatenation helped.
conn = ibm_db.connect('DRIVER={IBM DB2 ODBC DRIVER};DATABASE=<my_db>;HOSTNAME=<my_hostname>;PORT=50000;PROTOCOL=TCPIP;'+';UID='+db_user+';pwd='+db_pass,'','')
I have a database in mysql and I want to connect to it. I am trying to use this module from Python called MySQLdb. I created an user (called abc) and password (abc) for this database (abc) that has one table and it is connecting ok (when I connect by mysql command line).
But when I run my python script there is an error in the connection.
My script is:
#!/usr/bin/python
import MySQLdb
# Open database connection
db = MySQLdb.connect("localhost","abc","abc","abc")
# prepare a cursor object using cursor() method
cursor = db.cursor()
# execute SQL query using execute() method.
cursor.execute("SELECT VERSION()")
# Fetch a single row using fetchone() method.
data = cursor.fetchone()
print "Database version : %s " % data
# disconnect from server
db.close()
My error is:
Traceback (most recent call last):
File "./test.py", line 8, in <module>
db = MySQLdb.connect("localhost","abc","abc","abc")
File "/usr/local/lib/python2.7/dist-packages/MySQLdb/__init__.py", line 81, in Connect
return Connection(*args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/MySQLdb/connections.py", line 193, in __init__
super(Connection, self).__init__(*args, **kwargs2)
_mysql_exceptions.OperationalError: (1044, "Access denied for user 'abc'#'localhost' to database 'abc'")
What is wrong? My script or something in my mysql?
I changed my localhost to 127.0.0.1 (as suggested in another post, but did not solve my issue.
I also checked my permissions for this mysql user:
SHOW GRANTS;
+------------------------------------------------------------------------------+
| Grants for abc#localhost |
+------------------------------------------------------------------------------+
| GRANT USAGE ON *.* TO 'abc'#'localhost' |
| GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, INDEX, CREATE VIEW ON `abc`.* TO 'abc'#'localhost' |
+------------------------------------------------------------------------------+
You might need to restart the mysql daemon for the privileges to take affect. Or use the flush privileges command. https://dev.mysql.com/doc/refman/5.7/en/privilege-changes.html
Hi i have a requirement where i need to connect to remote mysql server. My application shall be running on local machine and my mysql will be running on remote server.I have tried the following code:
DB = 'gts'
DB_HOST = 'ps95074.dreamhost.com'
DB_USER = 'root'
DB_PASSWORD = 'dbadminpassword'
conn = MySQLdb.Connection(db=DB, host=DB_HOST, user=DB_USER,passwd=DB_PASSWORD)
cursor = conn.cursor()
But i am getting the following error
OperationalError: (2005, "Unknown MySQL server host 'ps95074.dreamhost.com' (1)")
Instead if i use
DB_HOST='localhost'
Everything works fine. How can same be possible with remote host.Any help shall be appreciated.
Check your firewall. That server is online and available from any machines:
> mysql -h ps95074.dreamhost.com
ERROR 1045 (28000): Access denied for user 'myuser'#'myhost' (using password: NO)
However, even if you can connect chances are good that your database user only allows local connections.
Update: I just tried it again and now it also fails using the commandline client. So clearly something is wrong with your server.