To enable Python to operate MySQL databases, you must first install the MySQL-python package. On CentOS, run the following command to install
To enable Python to operate MySQL databases, you must first install the MySQL-python package. On CentOS, run the following command to install
1. To enable Python to operate the MySQL database, first install the MySQL-python package. You can run the following command on CentOS to install the package:
[Python]
$ Sudo yum install MySQL-python
2. Leave nothing to say. Take two steps. The following program creates a connection to the mysql database, executes a simple query, and prints the query result.
[Python]
3. The following is a database table creation and insertion Operation.
[Python]
4. next let's look at the query. there are usually two ways to query: one is to use cursor. fetchall () is used to obtain all query results and then iterate over one row. fetchone () gets a record until the obtained result is null. Let's take a look at the following example:
[Python]