lagrange's blog

what's dead may never die

0%

python与mysql

  1. mysql命令行的使用 注意以管理员身份运行 net start mysql80命令 安装时注意windows service name 是 mysql80不能写mysql 进入C:\Program Files\MySQL\MySQL Server 8.0\bin该路径操作cd “C:\Program Files\MySQL\MySQL Server 8.0\bin”不要一步一步来 .\mysql -u root -p –i-am-a-dummy 不怕手作删库跑路可以不写–i-am-a-dummy 操作完成 net stop mysql80

  2. 遇到的Unread result found异常 All that was required was for buffered to be set to true! cursor = cnx.cursor(buffered=True) The reason is that without a buffered cursor, the results are “lazily” loaded, meaning that “fetchone” actually only fetches one row from the full result set of the query. When you will use the same cursor again, it will complain that you still have n-1 results (where n is the result set amount) waiting to be fetched. However when you use a buffered cursor the connector fetches ALL rows behind the scenes and you just take one from the connector so the mysql db won’t complain. Hope it helps. 来自 https://stackoverflow.com/questions/29772337/python-mysql-connector-unread-result-found-when-using-fetchone

    1
    2
    3
    4
    my = mysql.connector.connect(user="username",
    password="123456",
    charset="utf8",
    buffered=True)

    记得buffered=True要不然从数据中读取太多数据,又不全用会导致这个异常,但不用异常捕获是看不到的,只会直接退出不报错。