Python学习笔记-数据库的使用(一),python学习笔

作者:编程技术

1.     CentOS7安装MySQL

# wget

# 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模块    

安装MYSQL-python

先是安装 setuptools,下载源代码包:

wget http://pypi.python.org/packages/source/s/setuptools/setuptools-0.6c11.tar.gz
tar -xzvf setuptools-0.6c11.tar.gz
python setup.py build
python setup.py install

接下来安装一些扩大库

yum -y install rpm-build gcc-c mysql-devel python-devel

末尾安装MySQL-python 下载源代码包:

wget http://download.sourceforge.net/sourceforge/mysql-python/MySQL-python-1.2.3.tar.gz
tar -zxvf MySQL-python-1.2.3.tar.gz

编辑 site.cfg
把 mysql_config 那生龙活虎行撤销注释,并改为:

mysql_config = /usr/lib64/mysql/mysql_config (依据自身mysql安装位置定义卡塔 尔(阿拉伯语:قطر‎
python setup.py build
python setup.py install

Nginx配置难点

1.2    安装MySQL-python

1)         下载地址:

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

1.1    作用

Python操作MySQL供给MySQL-python模块驱动。

安装PIP

To install pip, securely download

wget https://bootstrap.pypa.io/get-pip.py
Then run the following (which may require administrator access):
python get-pip.py

1.1    作用

Python操作MySQL需求MySQL-python模块驱动。

1.     CentOS7安装MySQL

# wget

# 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 [email protected]'%'identified by 'password';

安装Mysql

1.使用yum命令安装mysql

yum -y install mysql-server

2.装置开机运行

chkconfig mysqld on

3.启动MySQL服务

service mysqld start

4.安装MySQL的root顾客安装密码

mysql -u root
mysql> select user,host,password from mysql.user;
------ ----------- ----------
| user | host | password |
------ ----------- ----------
| root | localhost | |
| root | bogon | |
| root | 127.0.0.1 | |
| | localhost | |
| | bogon | |
------ ----------- ----------
5 rows in set (0.01 sec)

询问客商的密码,都为空,用上面包车型客车吩咐设置root的密码为root

mysql> set password for root@localhost=password('root');
mysql> exit

5.用新密码登录

mysql -u root -p
Enter password:

6.创建mysql新用户test_user

mysql> create user 'test_user'@'%' identified by 'test_user';
Query OK, 0 rows affected (0.00 sec)

7.给新客户test_user授权,让他能够从表面登录和本土登入注意:@左侧是客户名,右侧是域名、IP和%,表示能够访谈mysql的域名和IP,%表示外界任何地方都能访谈。

mysql> grant all privileges on . to 'test_user'@'localhost' identified by 'test_user';
Query OK, 0 rows affected (0.00 sec)
mysql> grant all privileges on . to 'test_user'@'%' identified by 'test_user';
Query OK, 0 rows affected (0.00 sec)
mysql> select user,host,password from mysql.user;
---------- ----------- -------------------------------------------
| user | host | password |
---------- ----------- -------------------------------------------

| root | localhost | *81F5E21E35407D884A6CD4A731AEBFB6AF209E1B |
| root | bogon | |
| root | 127.0.0.1 | |
| | localhost | |
| | bogon | |
| test_user | % | *3046CF87132BBD4FDDF06F321C6859074843B7D3 |
| test_user | localhost | *3046CF87132BBD4FDDF06F321C6859074843B7D3 |
---------- ----------- -------------------------------------------
7 rows in set (0.00 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.01 sec)

8.查看mysql5.1的暗中认可存款和储蓄引擎从上面的执行结果能够观察,mysql的私下认可引擎是MyISAM,这么些引擎是不扶持职业的。

mysql> show engines;
------------ --------- ------------------------------------------------------------ -------------- ------ ------------
| Engine | Support | Comment | Transactions | XA | Savepoints |
------------ --------- ------------------------------------------------------------ -------------- ------ ------------
| MRG_MYISAM | YES | Collection of identical MyISAM tables | NO | NO | NO |
| CSV | YES | CSV storage engine | NO | NO | NO |
| MyISAM | DEFAULT | Default engine as of MySQL 3.23 with great performance | NO | NO | NO |
| InnoDB | YES | Supports transactions, row-level locking, and foreign keys | YES | YES | YES |
| MEMORY | YES | Hash based, stored in memory, useful for temporary tables | NO | NO | NO |
------------ --------- ------------------------------------------------------------ -------------- ------ ------------
5 rows in set (0.00 sec)

也能够以上面包车型地铁艺术查看

mysql> show variables like 'storage_engine';
---------------- --------
| Variable_name | Value |
---------------- --------
| storage_engine | MyISAM |
---------------- --------
1 row in set (0.00 sec)

9.退换mysql的暗中同意引擎为InnoDB
9.1 停止mysql

mysql> exit;
service mysqld stop

9.2 修改/etc/my.cnf
[mysqld] 后加入

default-storage-engine=InnoDB

投入后my.cnf的开始和结果为:

more my.cnf
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
user=mysql
default-storage-engine=InnoDB
[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid

9.3 启动mysql

service mysqld start
Starting mysqld: [ OK ]

9.4 查看mysql默许存款和储蓄引擎

mysql> show variables like 'storage_engine';

10.CentOS6.5盛放mysql端口3306CentOS6.5默许是不开放端口的,若是要让外界的系统访问CentOS6.5上的mysql,必须开放mysql的端口330610.1 改善/etc/sysconfig/iptables加多下目生机勃勃行

-A INPUT -m state --state NEW -m tcp -p tcp --dport 3306 -j ACCEPT

改进后iptables中的内容是

more /etc/sysconfig/iptables

11.重启防火墙

service iptables restart

如此那般就足以从外表访谈mysql了。
到现在,mysql在CentOS6.5上的装置进度、顾客创设、外界访问的步子全部完了。

2.   安装MySQL-python模块    

Python学习笔记-数据库的运用(生龙活虎卡塔 尔(阿拉伯语:قطر‎,python学习笔记

操作系统是CENTOS 6.5

yum中流行的也是Python 2.6.6,只好下载Python 2.7.9的源代码自身编写翻译安装。

操作步骤如下:

1)安装devtoolset

yum groupinstall "Development tools"

2卡塔尔国安装编译Python供给的手提袋

yum install zlib-devel
yum install bzip2-devel
yum install openssl-devel
yum install ncurses-devel
yum install sqlite-devel

1.2    安装MySQL-python

1)         下载地址:

2)         解压:

#unzip MySQL-python-1.2.5.zip

3)         步向文件:

#Python学习笔记-数据库的使用(一),python学习笔记分分快三计划。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学习笔记-数据库的使用(一),python学习笔记分分快三计划。python

>>>import MySQLdb

  1. CentOS7安装MySQL # wget # rpm -ivh mysql-...

安装Python2.7

用root登录之后采纳命令

wget https://www.python.org/ftp/python/2.7.10/Python-2.7.10.tgz

接纳解压命令tar解压刚刚下载的公文

tar xf Python-2.7.10.tgz

跻身解压之后的文书

cd Python-2.7.10.tgz

运转物检疫查目录结构

./configure --prefix=/usr/local
编译
make && make install
安装成功以往,你能够在 /usr/local/bin/python2.7
找到 Python 2.7

将python命令指向Python 2.7.9

ln -s /usr/local/bin/python2.7 /usr/local/bin/python

检查Python版本

sh
sh-4.1# python -V
Python 2.7.9

使用VIM编辑

vim领头接收
:wq保存退出

yum命令不宽容python2.7,需改进/usr/bin/yum文件,将第黄金时代行由“#!/usr/bin/python”改为“#!/usr/bin/python2.6"

安装nginx

1、安装prce(重定向补助)和openssl(https帮衬,假若没有必要https能够不设置。)

yum -y install pcre*
yum -y install openssl*

CentOS 6.5 作者设置的时候是选取的“基本服务器”,暗中认可那四个包都没设置全,所以那五个都运作安装就可以。

2、下载nginx 1.8.0

wget http://nginx.org/download/nginx-1.8.0.tar.gz

3、解压缩编制写翻译安装

tar -zxvf nginx-1.8.0.tar.gz

下一场进入目录编写翻译安装

cd nginx-1.8.0
./configure --prefix=/usr/local/nginx-1.8.0 --with-http_ssl_module --with-http_spdy_module --with-http_stub_status_module --with-pcre

就算未有error音讯,就足以实施上边的装置了:

make
make install

4、开启nginx进程

/usr/local/nginx-1.8.0/sbin/nginx

重启或关闭进程:

/usr/local/nginx-1.8.0/sbin/nginx -s reload
/usr/local/nginx-1.8.0/sbin/nginx -s stop

5、关闭防火墙,或然增添防火墙法规就足以测量试验了。

Python学习笔记-数据库的使用(一),python学习笔记分分快三计划。service iptables stop

大概编辑配置文件:

vi /etc/sysconfig/iptables

丰裕那样一条开放80端口的准则后保存:

-A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT

重启服务就能够:

service iptables restart

ok,,可以浏览器访问了。Welcome to nginx!

6、配置nginx.conf
vim /usr/local/nginx-1.8.0/conf/nginx.conf
运维客户去掉注释
user www-data;

本文由分分快三计划发布,转载请注明来源

关键词: 分分快三计划 李文昊老师