python summary

1. The difference between mysql and MongoDB:

Both MySQL and MongoDB are common open source databases , but MySQL is a traditional relational database , and MongoDB is a non- relational database , also called a document database, which is a NoSQL (not only sql non-relational database) database. They each have their own advantages, the key is to see where they are used. Therefore, those SQL (full name Structured Query Language) statements that we are familiar with are not applicable to MongoDB, because SQL statements are the standard language of relational databases.

 

    Take our company's project as an example. In the early projects, we were all using relational databases, including SQLServer, Oracle, and DB2. Later, we all switched to Mysql. The reason is very simple: Mysql has the advantage of open source under the condition of good performance. Mysql's transactionality and high performance are our main considerations. Later, because the project will use the user system, there will be a large amount of user data for interaction - mass storage, Mysql's read and write speed will be a little bit bottleneck, so we think of Nosql, which has developed very strongly recently. With the development of Nosql's early memcache, many non-relational databases appeared, such as redis and mongodb. After a period of testing, the read and write speeds of redis and mongodb do have obvious advantages over Mysql. The write speed of mongodb is about 2.5W/time per second.
 
    mongodb is stored in BSON structure (binary), which has obvious advantages for mass data storage. The following is a comparison of the operation commands of Mongodb and Mysql.

effect

MySQL

MongoDB

server daemon

mysqld

mongod

Client Tools

mysql

mongo

Logical Backup Tool

mysqldump

mongodump

Logical restore tool

mysql

mongorestore

Data export tool

mysqldump

mongoexport

Data import tool

source

mongoimport

Create a new user and authorize

grant all on *.*
to username@'localhost'
 
identified by 'passwd';

db.addUser("user","psw")
db.auth("user","psw")

show library list

show databases;

show dbs

go into the library

use dbname;

use dbname

Show table list

show tables;

show collections

Query master-slave status

show slave status;

rs.status

Create library

create database name;

No need to create it separately, just use it directly

create table

create table tname(id int);

No need to create separately, insert data directly

delete table

drop table tname;

db.tname.drop()

delete library

drop database dbname;

First go into the library, db.dropDatabase()

insert record

insert into tname(id) value(2);

db.tname.insert({id:2})

Delete Record

delete from tname where id=2;

db.tname.remove({id:2})

Modify/ update records

update tname set id=3
where id=2;

db.tname.update({id:2},
{$set:{id:3}},false,true)

query all records

select * from tname;

db.tname.find()

query all columns

select id from tname;

db.tname.find({},{id:1})

Conditional query

select * from tname where id=2;

db.tname.find({id:2})

Conditional query

select * from tname where id < 2;

db.tname.find({id:{$lt:2}})

Conditional query

select * from tname where id >=2;

db.tname.find({id:{$gte:2}})

Conditional query

select * from tname where id=2
and name='steve';

db.tname.find({id:2,
name:'steve'})

Conditional query

select * from tname where id=2
or name='steve';

db.tname.find($or:[{id:2},
{name:'steve'}])

Conditional query

select * from tname limit 1;

db.tname.findOne()

fuzzy query

select * from tname where name
like "%ste%";

db.tname.find({name:/ste/})

fuzzy query

select * from tname where name
like "ste%";

db.tname.find({name:/^ste/})

Get the number of table records

select count(id) from tname;

db.tname.count()

Get conditional
record count

select count(id) from tname
where id=2;

db.tname.find({id:2}).count()

Remove
duplicate values ​​when querying

select distinct(last_name)
from tname;

db.tname.distinct('last_name')

Positive sort query

select *from tname order by id;

db.tname.find().sort({id:1})

reverse sort query

select *from tname
order by id desc;

db.tname.find().sort({id:-1})

take storage path

explain select * from tname
where id=3;

db.tname.find({id=3}).explain()

Special note: mongodb insert multiple fields syntax
> db.user.insert({id:1,name:'steve',sex:'male'})  正确
> db.user.insert({id:2},{name:'bear'},{sex:'female'})  错误

 2. The respective advantages of Django, Tornado, and Flask Framework

Django: Django has no sockets. The purpose of Django is to be easy and fast to develop, and follow the MVC design. Multiple components can easily serve the entire framework in the form of "plug-ins". Django has many powerful third-party plug-ins. Django is very extensible.

Tornado: It is a non-blocking server, and the speed is quite fast, thanks to its non-blocking method and the use of epoll, Future object, disadvantages: no session, needs to be customized

 Flask:是一个微型的web框架,配合SQLALchemy来使用,jinja2模板, werkzeug接口       



3、单例:

class SingleSimple():
    instance=None#类属性
    def __new__(cls, *args, **kwargs):#限制生成对象,c创建对象
        if cls.instance==None:
            cls.instance=object.__new__(cls)#生成新对象
        return cls.instance
    def __init__(self,name):#必须调用,必须加参;
        print('正在初始化方法...')
        self.name=name
s=SingleSimple('abc')
ss=SingleSimple('dfjf')
print(s.name)
print(ss.name)
 
 
 
 
 
 
二、电脑配置
1、操作系统
Windows操作系统:win7、win8、XP
Unix操作系统:FreeBSD、Sun Solaris   一般用于银行、电信、移动、核心业务等高端领域,是收费的,闭源的,很贵
Linux:Ret Hat(红帽)、Ubuntu(游戏3D)、Fedora(社区版)  服务器基本都是Linux系统,维护。
Linux构成:Linux内核和外围程序(shell、gnome。。)
 
 
三、


Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325522137&siteId=291194637