When in the Python shell I type:
import MySQLdb
Con = MySQLdb.Connect(user='testuser', password='password', db='test')
And I get this:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Users\Nickey\AppData\Local\Programs\Python\Python36\lib\site-packages\MySQLdb\__init__.py", line 86, in Connect
return Connection(*args, **kwargs)
File "C:\Users\Nickey\AppData\Local\Programs\Python\Python36\lib\site-packages\MySQLdb\connections.py", line 204, in __init__
super(Connection, self).__init__(*args, **kwargs2)
_mysql_exceptions.OperationalError: (2059, <NULL>)
And no description of the error at all. Please, I am waiting for help. Thanks.
UPDATE: In case somebody will be having this problem, it appears to be connected with the new mysql_auth_plugin, with its new Strong Password Encryption for Authentication. I just switched to old_password_plugin(Legacy Authentication Method) in the configuration of MySQL Server and now [All works!].
According to the docs, password is not a keyword argument like you entered, instead it's passwd as you can see --> here
Related
I make a telegram bot using python and MySQL. I can enter the database in terminal, but when I run my python code, it says I have no permission.
ilyacherne#vh289 ~ $ python3 /home/i/ilyacherne/public_html/cgi-bin/bot.py
Traceback (most recent call last):
File "/home/i/ilyacherne/.local/lib/python3.8/site-packages/mysql/connector/connection_cext.py", line 239, in _open_connection
self._cmysql.connect(**cnx_kwargs)
_mysql_connector.MySQLInterfaceError: Access denied for user 'ilyacherne'#'77.222.61.25' (using password: YES)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/i/ilyacherne/public_html/cgi-bin/bot.py", line 3, in <module>
import config
File "/home/i/ilyacherne/public_html/cgi-bin/config.py", line 8, in <module>
database = mysql.connect(
File "/home/i/ilyacherne/.local/lib/python3.8/site-packages/mysql/connector/__init__.py", line 272, in connect
return CMySQLConnection(*args, **kwargs)
File "/home/i/ilyacherne/.local/lib/python3.8/site-packages/mysql/connector/connection_cext.py", line 85, in __init__
self.connect(**kwargs)
File "/home/i/ilyacherne/.local/lib/python3.8/site-packages/mysql/connector/abstracts.py", line 1009, in connect
self._open_connection()
File "/home/i/ilyacherne/.local/lib/python3.8/site-packages/mysql/connector/connection_cext.py", line 241, in _open_connection
raise errors.get_mysql_exception(msg=exc.msg, errno=exc.errno,
mysql.connector.errors.ProgrammingError: 1045 (28000): Access denied for user 'ilyacherne'#'77.222.61.25' (using password: YES)
I checked the password, host name, database name and user.
I connect with this code:
database = mysql.connect(
host = '77.222.61.25',
user = 'ilyacherne',
passwd = 'CENSORED',
database = 'ilyacherne'
)
support said that MySql 5.7 connects to socket by default and i connect just with 'sudo mysql', and then they reccomended me try this:
ALTER USER 'root'#'localhost' IDENTIFIED WITH mysql_native_password BY 'Current-Root-Password'; FLUSH PRIVILEGES;
but it says:
ERROR 1227 (42000): Access denied; you need (at least one of) the CREATE USER privilege(s) for this operation
ERROR 1227 (42000): Access denied; you need (at least one of) the RELOAD privilege(s) for this operation
Pip install mysql-connector-python
Then import mysql-connector.
I am currently trying to send data to my database that is hosted on the web using python. There are no MySql errors being thrown however running in ninja I get this output:
Traceback (most recent call last):
File "/home/nekasus/tryme.py", line 8, in <module>
port = "3306") # name of the data base
File "/usr/lib/python2.7/dist-packages/MySQLdb/__init__.py", line 81, in Connect
return Connection(*args, **kwargs)
File "/usr/lib/python2.7/dist-packages/MySQLdb/connections.py", line 187, in __init__
super(Connection, self).__init__(*args, **kwargs2)
TypeError: an integer is required
This is my code:
import fakevalues
import MySQLdb
fakevalues.randomnumber()
db = MySQLdb.connect(host="sql8.freemysqlhosting.net",
user="sql8167767",
passwd="placeholder",
db="sql8167767",
port = "3306")
cur = db.cursor()
try:
cur.execute("INSERT INTO hydroponics (ph, electricalconductivity, nutrientsolutiontemperature, nutrientsolutiondepth) VALUES (1, 1, 1, 1)")
except MySQLdb.Error as e:
print(e)
db.close()
You are missing the commit.
db.commit()
port needs to be an integer, not a string.
When I run my script it won't connect to mysql database, I can't find my host name from godaddy I just tried mysq.mydomain.com and mydomain.com. the login details for the database are correct.
Traceback (most recent call last):
File "mysql.py", line 6, in <module>
conn = MySQLdb.connect(host="?",user="?",passwd="?",db="?")
File "/usr/lib/python2.7/dist-packages/MySQLdb/__init__.py", line 81, in Connect
return Connection(*args, **kwargs)
File "/usr/lib/python2.7/dist-packages/MySQLdb/connections.py", line 187, in __init__
super(Connection, self).__init__(*args, **kwargs2)
_mysql_exceptions.OperationalError: (1045, "Access denied for user 'official_autotes'#'104.156.228.189' (using password: YES)")
------------------
my code
from threading import Thread
import urllib
import re
import MySQLdb
conn = MySQLdb.connect(host="?",user="?",passwd="?",db="?")
query = "INSERT INTO tutorial (symbol) values ('AAPL')"
x = conn.cursor()
x.execute(query)
row = x.fetchal()
Grand privilage to the user and ip trying to access the MySQL table using the Python code. To do the same, execute the following commands in the mysql shell.
GRANT <privileges> ON database.* TO 'user'#'ip' IDENTIFIED BY 'password';
flush privileges;
Running this command in the terminal with the correct values I get connected and can read the data base:
mysql -h mysql.lyon...fr -u user --password=passworld
I have to do this in a python script, I tried few functions like:
import MySQLdb as mysql
print '======================================================================================'
print 'Connextion to the database'
print '======================================================================================'
# mysql -h mysql.lyon....fr -u XXuser --password=XXpasswd
import MySQLdb as mdb
con = mdb.connect(host='mysql....grid5000.fr' , user='XXuser', passwd='XXpasswdread oar2')
======================================================================================
Connextion to the database
======================================================================================
Traceback (most recent call last):
File "process.py", line 14, in <module>
con = mdb.connect(host='mysql.lyon......fr' , user='user name ', passwd='......')
File "/usr/lib/python2.7/dist-packages/MySQLdb/__init__.py", line 81, in Connect
return Connection(*args, **kwargs)
File "/usr/lib/python2.7/dist-packages/MySQLdb/connections.py", line 187, in __init__
super(Connection, self).__init__(*args, **kwargs2)
_mysql_exceptions.OperationalError: (1045, "Access denied for user 'oarreader'#'flyon.lyon.grid5000.fr' (using password: YES)")
How can I define the arguments in the connect function to connect to the server knowing its address?
You are not using the same user that in the terminal, in the terminal you use -u user and using python you use oarreader
>>> db=MySQLdb.connect(passwd="king123",db="thangs",host="localhost",port=3306,user="user")
Traceback (most recent call last):
File "<pyshell#6>", line 1, in <module>
db=MySQLdb.connect(passwd="king123",db="thangs",host="localhost",port=3061,user="user")
File "C:\Python27\lib\site-packages\MySQLdb\__init__.py", line 81, in Connect
return Connection(*args, **kwargs)
File "C:\Python27\lib\site-packages\MySQLdb\connections.py", line 187, in __init__
super(Connection, self).__init__(*args, **kwargs2)
OperationalError: (2003, "Can't connect to MySQL server on 'localhost' (10061)")
I am running it on right port , still it give me error. Can anyone give me any idea please
If you can't see this port that means mysql is not running in which case the error makes sense. Please see this on how to turn on the mysql server.