从数据库查看数据时出错

时间:2014-06-03 02:33:30

标签: python mysql

我是这个python和mysql的新手。我尝试从我的数据库中查看第一行数据。这是我的代码:

import MySQLdb

db = MySQLdb.connect(host="localhost", # your host, usually localhost
                     user="root", # your username
                     passwd="", # your passwords
                     db="58c_t2d_10") # name of the database

# you must create a Cursor object. 
# It will let you execute all the queries you need
cur = db.cursor() 

# Use all the SQL you like
cur.execute("SELECT * 58c_10")

# print all the first cell of all the rows
for row in cur.fetchall() :
    print row[0]

我收到了这个错误:

OperationalError: (1044, "Access denied for user ''@'localhost' 
                          to database '58c_t2d_10'")

我试图以root用户身份登录:

ProgrammingError: (1064, "You have an error in your SQL syntax; check the manual 
                          that corresponds to your MySQL server version for the 
                          right syntax to use near '58c_10' at line 1")

1 个答案:

答案 0 :(得分:1)

cur.execute("SELECT * From 58c_10") 

u have missed from