mysql授權問題:1004 Access denied for user '使用者名稱'@'%' to database

來源:互聯網
上載者:User

標籤:

情境:平時直接用root登入到mysql伺服器上進行SQL語句查詢,當想用python串連mysql時,提示1045, "Access denied for user ‘root‘@‘IP地址‘ (using password: YES)",然後用create user 使用者名稱 identified by ‘密碼‘建立了使用者名稱為自己名字的使用者,再去執行python,提示1004 Access denied for user ‘使用者名稱‘@‘%‘ to database,這時候就要進入mysql用select * from mysql.user \G查看當前所有使用者的情況,會發現別人的許可權裡很多都是Y,而自己的都是N,所以意識到是許可權問題。

解決:給自己的使用者名稱添加許可權  grant all privileges on *.* to 使用者名稱@IP地址,然後再select * from mysql.user \G會發現自己的許可權也變成了Y,這時候python就能串連資料庫了。

 

#!/usr/bin/env python
#-*- coding: utf-8 -*-
import MySQLdb

conn = MySQLdb.connect(host = "IP地址", user = "使用者名稱", passwd = "密碼",
db = "資料庫名", port = 3306, charset="utf8")
cur = conn.cursor()
cur.execute("set NAMES UTF8")

if __name__ == ‘__main__‘:

conn.commit()
cur.close()
conn.close()

mysql授權問題:1004 Access denied for user '使用者名稱'@'%' to database

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.