Python MySQL-从表格中选择数据

In this tutorial, we will learn how to retrieve data from MySQL table in python, both, the complete table data, and data from some specific columns. 在本教程中,我们将学习如何从 python中的MySQL表中检索数据 ,包括完整的表数据和某些特定列...
摘要由CSDN通过智能技术生成

In this tutorial, we will learn how to retrieve data from MySQL table in python, both, the complete table data, and data from some specific columns.

在本教程中,我们将学习如何从 python中的MySQL表检索数据 ,包括完整的表数据和某些特定列中的数据。

Python MySQL-选择数据 (Python MySQL - SELECT Data)

In MySQL, to retrieve data from a table we will use the SELECT statement. The syntax for the same is given below:

在MySQL中, 要从表中检索数据,我们将使用SELECT语句。 下面给出了相同的语法:

SELECT column_names FROM table_name

从MySQL表中检索所有记录 (Retrieve All records from MySQL Table)

In order to get all the records from a table, * is used instead of column names. Let us retrieve all the data from the students table which we inserted before:

为了从表中获取所有记录,使用*代替列名。 让我们从之前插入的students表中检索所有数据:

import mysql.connector as mysql

db = mysql.connect(
    host = "localhost",
    user = "yourusername",
    passwd = "yourpassword",
    database = "studytonight"
)

cursor = db.cursor()

#
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值