import MySQLdb # MySQLの接続情報 db_config = { 'host': 'localhost', 'db': 'test', # Database Name 'user': 'root', 'passwd': '', 'charset': 'utf8', } try: # 接続 conn = MySQLdb.connect(host=db_config['host'], db=db_config['db'], user=db_config['user'], passwd=db_config['passwd'], charset=db_config['charset']) except MySQLdb.Error as ex: print('MySQL Error: ', ex) # デフォルトの結果セットはタプル cursor.execute('SELECT * FROM youtubers ') # fetchone() メソッド実行のたびにカーソル位置が移動します print(cursor.fetchone()) print(cursor.fetchone()) list = [] # 結果セットを辞書型で取得 dict_cursor = conn.cursor(MySQLdb.cursors.DictCursor) dict_cursor.execute('SELECT * FROM youtubers') for row in dict_cursor: list.append(row); print(row['id'], row['name']) print(list)