It covers the basics of MySQL programming with Python. The examples were created and tested on Ubuntu Linux. MySQLdb is a Python 2 legacy database module lion binary option MySQL.
It is a multi user, multithreaded database management system. MySQL is especially popular on the web. It is one part of the very popular LAMP platform which consists of Linux, Apache, MySQL, and PHP. Currently MySQL is owned by Oracle. MySQL database is available on most important OS platforms. It runs on BSD Unix, Linux, Windows, or Mac OS. These sites manage millions of queries each day.
We use the apt-cache command to figure it out. While installing the package, we are prompted to enter a password for the MySQL root account. Next, we are going to create a new database user and a new database. We connect to the database using the root account. We show all available databases with the SHOW DATABASES statement. We create a new testdb database. We will use this database throughout the tutorial.
We grant all privileges to this user for all tables of the testdb database. The _mysql module implements the MySQL C API directly. It is not compatible with the Python DB API interface. Generally, the programmers prefer the object oriented MySQLdb module. We will concern ourself with the latter module.
Here we present only one small example with the _mysql module. The example will get and print the version of the MySQL database. It is compatible with the Python DB API, which makes the code more portable. Using this model is the preferred way of working with the MySQL. We pass four parameters: the hostname, the database user name, the password, and the database name. From the connection, we get the cursor object.
The cursor is used to traverse the records from the result set. We print the data that we have retrieved to the console. In the final step, we release the resources. With the with keyword, the Python interpreter automatically releases the resources. This SQL statement creates a new database table called Writers.