I can not connect to MYSQL with python

1

I'm using PyMySql . I just want to do a simple "Query": "SELECT * FROM python_1", I always get this error:

  

Traceback (most recent call last):     File "Alumnos.py", line 5, in       connection = pymysql.connect ('localhost', 'd3h', '', 'python')     File "/usr/local/lib/python3.4/dist-packages/pymysql/init.py", line 90, in Connect       return Connection (* args, ** kwargs)     File "/usr/local/lib/python3.4/dist-packages/pymysql/connections.py", line 706, in init       self.connect ()     File "/usr/local/lib/python3.4/dist-packages/pymysql/connections.py", line 932, in connect       self._request_authentication ()     File "/usr/local/lib/python3.4/dist-packages/pymysql/connections.py", line 1152, in _request_authentication       auth_packet = self._read_packet ()     File "/usr/local/lib/python3.4/dist-packages/pymysql/connections.py", line 1014, in _read_packet       packet.check_error ()     File "/usr/local/lib/python3.4/dist-packages/pymysql/connections.py", line 393, in check_error       err.raise_mysql_exception (self._data)     File "/usr/local/lib/python3.4/dist-packages/pymysql/err.py", line 107, in raise_mysql_exception       raise errorclass (errno, errval)   pymysql.err.OperationalError: (1045, "Access denied for user 'd3h' @ 'localhost' (using password: NO)")

I have reviewed the syntax several times and I do not see any problem. Here my code:

import pymysql.cursor
connection = pymysql.connect('localhost','d3h','','python')
try:
    with connection.cursor() as cursor:
        query = "SELECT * FROM python_1"
        cursor.execute(query)
    connection.commit()
finally:
    connection.close()

PD : This is my first question, forgive me if I write badly or is badly formulated. PD2 : I use c9.io

    
asked by Diego Auyón D3AH 09.07.2017 в 18:47
source

1 answer

2

Ok this is the way I use to declare the connector

connection = pymysql.connect(host='192.168.0.38',
                            user='root',
                            password='12345',
                            db='mi_basede_datos',
                            charset='utf8mb4',
                            cursorclass=pymysql.cursors.DictCursor)

but apparently the error is in the management of users, your user must have permission to modify and read the database and must also have password if or if it is a security method that has mysql

    
answered by 09.07.2017 / 19:17
source