Python学习笔记-数据库的使用(一)
1. CentOS7安装MySQL
# 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
重启MySQL服务
# service mysqld restart
初次安装mysql,root账户没有密码。
# mysql -u root
设置密码 //可无
mysql> set password for 'root'@'localhost' =password('password');
mysql配置文件为/etc/my.cnf
最后加上编码配置
[mysql]
default-character-set =utf8
远程连接设置
mysql> grant all privileges on *.* to root@'%'identified by 'password';
2. 安装MySQL-python模块
1.1 作用
Python操作MySQL需要MySQL-python模块驱动。
1.2 安装MySQL-python
1) 下载地址:https://pypi.python.org/pypi/MySQL-python/
2) 解压:
#unzip MySQL-python-1.2.5.zip
3) 进入文件:
#cd MySQL-python-1.2.5
4) #yum -y install mysql-devel
5) #yum install gcc python-devel
6) #python setup.py install
7) 安装成功,测试:
#python
>>>import MySQLdb
上一篇: 大和太