pymysql mysql given connection and operation of the database connection module pymysql given Solution

pymysql module database and the connection operation being given Solution

 
import pymysql
MySQL statement sql = "select host, user, password from user" # want to perform
#sql = 'create database sss character set utf8'
# Open Database Connectivity
db = pymysql.connect(host="192.168.254.40", user="root",
                     password="root", db="mysql", port=3306)
cur = db.cursor () # using the cursor () method to get the cursor operation
cur.execute (sql) # sql statement execution
results = cur.fetchall () # get all records of the query
for i in results: # traversal results
    print(i)
db.close () # close the connection
 pymysql: Mysql refuse from remote access solutions
Error content
Traceback (most recent call last):
  File "E:/untitled1/lvs_rr.py", line 15, in <module>
    password="1", db="mysql", port=3306)
  File "E:\untitled1\lib\site-packages\pymysql\__init__.py", line 94, in Connect
    return Connection(*args, **kwargs)
  File "E:\untitled1\lib\site-packages\pymysql\connections.py", line 325, in __init__
    return Connection(*args, **kwargs)
  File "E:\untitled1\lib\site-packages\pymysql\connections.py", line 325, in __init__
    self.connect()
  File "E:\untitled1\lib\site-packages\pymysql\connections.py", line 599, in connect
    self._request_authentication()
  File "E:\untitled1\lib\site-packages\pymysql\connections.py", line 861, in _request_authentication
    auth_packet = self._read_packet()
  File "E:\untitled1\lib\site-packages\pymysql\connections.py", line 684, in _read_packet
    packet.check_error()
  File "E:\untitled1\lib\site-packages\pymysql\protocol.py", line 220, in check_error
    err.raise_mysql_exception(self._data)
  File "E:\untitled1\lib\site-packages\pymysql\err.py", line 109, in raise_mysql_exception
    raise errorclass(errno, errval)
 
Solution:
Adding users to allow connections from any host server mysql 
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'password' WITH GRANT OPTION;
With immediate effect
FLUSH PRIVILEGES;
import pymysql
MySQL statement sql = "select host, user, password from user" # want to perform
#sql = 'create database sss character set utf8'
# Open Database Connectivity
db = pymysql.connect(host="192.168.254.40", user="root",
                     password="root", db="mysql", port=3306)
cur = db.cursor () # using the cursor () method to get the cursor operation
cur.execute (sql) # sql statement execution
results = cur.fetchall () # get all records of the query
for i in results: # traversal results
    print(i)
db.close () # close the connection
 pymysql: Mysql refuse from remote access solutions
Error content
Traceback (most recent call last):
  File "E:/untitled1/lvs_rr.py", line 15, in <module>
    password="1", db="mysql", port=3306)
  File "E:\untitled1\lib\site-packages\pymysql\__init__.py", line 94, in Connect
    return Connection(*args, **kwargs)
  File "E:\untitled1\lib\site-packages\pymysql\connections.py", line 325, in __init__
    return Connection(*args, **kwargs)
  File "E:\untitled1\lib\site-packages\pymysql\connections.py", line 325, in __init__
    self.connect()
  File "E:\untitled1\lib\site-packages\pymysql\connections.py", line 599, in connect
    self._request_authentication()
  File "E:\untitled1\lib\site-packages\pymysql\connections.py", line 861, in _request_authentication
    auth_packet = self._read_packet()
  File "E:\untitled1\lib\site-packages\pymysql\connections.py", line 684, in _read_packet
    packet.check_error()
  File "E:\untitled1\lib\site-packages\pymysql\protocol.py", line 220, in check_error
    err.raise_mysql_exception(self._data)
  File "E:\untitled1\lib\site-packages\pymysql\err.py", line 109, in raise_mysql_exception
    raise errorclass(errno, errval)
 
Solution:
Adding users to allow connections from any host server mysql 
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'password' WITH GRANT OPTION;
With immediate effect
FLUSH PRIVILEGES;

Guess you like

Origin www.cnblogs.com/look-789/p/11764384.html
Recommended