Python learning notes-database usage (1), python learning notes
1. Install MySQL on CentOS7
# Wget http://dev.mysql.com/get/mysql-community-release-el7-5.noarch.rpm
# Rpm-ivh mysql-community-release-el7-5.noarch.rpm
# Yum install mysql-community-server
Restart MySQL Service
# Service mysqld restart
The first time mysql is installed, the root account does not have a password.
# Mysql-u root
Set Password // none
Mysql> set password for 'root' @ 'localhost' = password ('Password ');
The mysql configuration file is/etc/my. cnf.
Add the encoding Configuration
[Mysql]
Default-character-set = utf8
Remote connection settings
Mysql> grant all privileges on *. * to root @ '%' identified by 'Password ';
2. Install the MySQL-python Module
1.1 Role
Python requires the MySQL-python module driver to operate MySQL.
1.2 install MySQL-python
1): https://pypi.python.org/pypi/MySQL-python/
2) decompress:
# Unzip MySQL-python-1.2.5.zip
3) enter the file:
# Cd MySQL-python-1.2.5
4) # yum-y install mysql-devel
5) # yum install gcc python-devel
6) # python setup. py install
7) the installation is successful. test:
# Python
>>> Import MySQLdb