[py]py3/pip/virtualenv/mysql环境安装

centos python3安装

curl -O https://www.python.org/ftp/python/3.6.6/Python-3.6.6.tgz



tar xf Python-3.6.6.tgz
cd Python-3.6.6
./configure --prefix=/usr/local/Python-3.6.6
make
make install



echo 'alias python3="/usr/local/Python-3.6.6/bin/python3.6"' > /etc/profile.d/python.sh
/usr/local/Python-3.6.6/bin/
chmod 755 /etc/profile.d/python.sh
source /etc/profile.d/python.sh
python3 -V


$ vim /etc/profile
#golang env config
#export GO111MODULE=on
export GOROOT=/usr/local/go
export GOPATH=/data/gopath

#python env config
export PYTHON3ROOT=/usr/local/Python-3.6.6

export PATH=$PATH:$GOROOT/bin:$GOPATH/bin:$PYTHON3ROOT/bin

cd
pip3 install virtualenv
virtualenv --python=/usr/local/Python-3.6.6/bin/python3 py36env

Traceback (most recent call last):是什么意思?

追踪(最后调用)

pip.ini添加
https://www.cnblogs.com/lsdb/p/9188204.html

创建 %APPDATA%\pip\目录

mkdir %APPDATA%\pip\
cd %APPDATA%\pip\
cat > pip.ini
[global]
trusted-host = pypi.tuna.tsinghua.edu.cn
index-url = https://pypi.tuna.tsinghua.edu.cn/simple

win下正确姿势安装py3

  • 选择64bit的python3
  • 选择自定义安装

  • 选择安装位置

pycharm安装激活

  • 安装pip
yum install install python-pip -y
cd
mkdir ~/.pip
cat > .pip/pip.conf<<EOF
[global]
index-url = http://mirrors.aliyun.com/pypi/simple/
 
[install]
trusted-host=mirrors.aliyun.com
EOF
  • 安装虚拟环境
- for windows
pip install virtualenv
pip install virtualenvwrapper
pip install virtualenvwrapper-win
mkvirtualenv --python=C:\Python27\python.exe py27env
exit
mkvirtualenv --python=C:\Python36\python.exe py36env
workon  #查看刚刚创建的环境,mkvirtualenv  -h查看帮助


pip3 install -i https://pypi.douban.com/simple/ virtualenv
pip3 install -i https://pypi.douban.com/simple/ virtualenvwrapper
virtualenv --python=/usr/bin/python3 py3env
source py3env/bin/activate
pip install django


for linux:
yum install mysql-devel
pip install MySQL-python
  • py3/py2安装mysql-devel驱动程序

这个对windows很友好, 我在入库日志时候用到这个

pip install pymysql

https://blog.csdn.net/hldh214/article/details/50650357

import pymysql
pymysql.install_as_MySQLdb() 

django settings.py连接mysql的配置

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.mysql',
        'NAME': 'devops',
        'USER': 'root',
        'PASSWORD': '123456',
        'HOST': '127.0.0.1',
        'PORT': 3306,
        'OPTIONS':{
            'init_command': 'SET default_storage_engine=INNODB;',
        },
    }
}

pycharm设置

  • 导入配置
wget https://github.com/lannyMa/scripts/blob/master/pycharm/settings.jar
file -> import settings就ok了



黄色不伤害眼睛的rgb
255 251 232
FFFBE8

  • 设置terminal
File -> Settings -> Tools -> Terminal

for 64bit:
"C:\Program Files\Git\bin\sh.exe" -login -i

for 32bit:
"C:\Program Files (x86)\Git\bin\sh.exe" -login -i
"C:\Windows\System32\cmd.exe" /C "bash"

mysql for win

下载安装

MySQL Community Server 5.7.16
http://dev.mysql.com/downloads/mysql/

cd D:\Program Files\mysql-5.7.19-winx64\bin
mysqld --initialize-insecure

添加path

D:\Program Files\mysql-5.7.19-winx64\bin

启动MySQL服务

"D:\Program Files\mysql-5.7.19-winx64\bin\mysqld" --install

- 初始化: http://www.cnblogs.com/yyhh/p/5062153.html
D:\Service\mysql57\bin>mysqld --initialize --user=root --console

- 修改密码
mysqladmin -uroot -p123456 password 123

- 启动
net start mysql




mysql -u root -p


"D:\Program Files\mysql-5.7.19-winx64\bin\mysqld" --remove
net stop mysql


create database bbs;
grant all on bbs.* to dev@localhost identified by '123456';
grant all on bbs.* to dev@'%' identified by '123456';

字符集

SET NAMES 'utf8'; 
SET character_set_client = utf8;
SET character_set_connection = utf8;
SET character_set_database = utf8;
SET character_set_results = utf8;
SET character_set_server = utf8;

SET collation_connection = utf8_general_ci;
SET collation_database = utf8_general_ci;
SET collation_server = utf8_general_ci;

缺陷是: 登出后设置的就失效了.
show variables like '%storage_engine%';

show VARIABLES like '%max_allowed_packet%';
show variables like '%storage_engine%';
show variables like 'collation_%';
show variables like 'character_set_%';

mysql另一种配置文件持久化:

D:\Program Files\mysql-5.7.19-winx64\my.ini
[mysqld]
default-storage-engine = innodb
innodb_file_per_table = 1
character-set-server = utf8
collation-server = utf8_general_ci
init-connect = 'SET NAMES utf8'

[mysql]
default-character-set = utf8

[mysql.server]
default-character-set = utf8


[mysqld_safe]
default-character-set = utf8


[client]
default-character-set = utf8


参考: http://blog.csdn.net/u013474104/article/details/52486880

mysql配置及命令参考

- mysql生产配置参考
https://www.teakki.com/p/57e227aea16367940da625f8


- 配置文件查找先后顺序
C:\ProgramData\MySQL\MySQL Server 5.7\my.ini
C:\windows\my.ini
C:\my.ini
E:\dev\mysql57\my.ini

- 通过配置文件设置字符集
default-storage-engine = innodb
innodb_file_per_table = 1
character-set-server = utf8
collation-server = utf8_general_ci
init-connect = 'SET NAMES utf8'


- 查看建表语句
show create database test;


- 查看权限
show grants

mysql crud语句

mysql安装完后接单优化

- 建表
create table log(ip varchar(40), status int, count int);

- 插入记录
insert into log values ('192.168.1.1',404,10)

- 删除某条记录
delete from mysql.user where user='';


mysql指引
1,mysql基本安装
2,mysql多实例安装与维护
3,备份恢复

备份数据库
分备数据库
分备表
恢复数据库

解决pycharm问题:module 'pip' has no attribute 'main'

posted @ 2018-01-05 17:38  mmaotai  阅读(423)  评论(0编辑  收藏  举报