Column catalog

  • MySQL
    • MySQL is introduced
    • MySQL link
    • MySQL query
    • MySQL update
    • MySQL new
    • MySQL to delete
  • Mongo
    • Mongo introduction
    • Mongo query
    • Mongo delete
    • Mongo update
    • Mongo new
    • Mongo comparison operators
    • Relationship between Mongo operator
    • Mongo polymerization
    • Mongo returns the raw data after aggregation
  • Redis
    • Redis is introduced
    • Redis storage mode
    • Storage type of Redis

Column details

MySQL

MySQL is introduced

A DataBase is an electronic storage system. It is equivalent to a box of electronic files. A lot of information or files are stored in this cabinetCopy the code
MySQL is a typical relational database, mapping data format is very similar to table data and MySQL reflects excellent performance, low cost, good reliability characteristics applied to the majority of projects relational database is more based on the relational model, with the help of set algebra and other mathematical methods to deal with the databaseCopy the code

MySQL connection

# IP: indicates the value of the -h(host) option. # -p: indicates the value of the -h(host) option. Mysql -u USER -h IP -p # mysql -u USER -h IP -p When you connect to MySQL, you will enter the MySQL interfaceCopy the code

MySQL query

Show databases use DatabasesName show tables SELECT * FROM TableName TableName; SELECT field1, field2 FROM TableName; SELECT field1, field2 FROM TableName; SELECT * FROM TableName WHERE field1=1 SELECT * FROM TableName WHERE field1=1; SELECT * FROM TableName WHERE field1=1 AND field2=2; SELECT * FROM TableName WHERE field1=1 AND field2=2; SELECT * FROM TableName WHERE field1=1 OR field2=2 SELECT * FROM TableName WHERE field1=1 OR field2=2;Copy the code

MySQL update

Update tablName SET NAME ="Medusa"; Update tablName SET NAME ="Medusa" WHERE ID =1;Copy the code

MySQL new

Insert INFO tablName(ID,name) VALUES (6,' medUSA ');Copy the code

MySQL to delete

Delete from tablName WHERE ID =1; # delete all data from the tablName;Copy the code

Mongo

Mongo introduction

{{"_id": "", 'data': {{"_id": "", 'data': {{"_id": "", 'data': {{"_id": "", 'data': {{"_id": "", 'data': { 'key': 'value' } }, { "_id": '', 'info': 1 } }Copy the code

Mongo query

Find (query, * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * Find (). Pretty () # query the specified data document db.collection.find({'_id': XXX}).Copy the code

Mongo delete

Query :(Optional) Conditions for the document to be deleted: (Optional) If set to true or 1, only the first matching document is deleted, otherwise false is used, Db.collection. remove(<query>, {justOne: < Boolean >, writeConcern: <document>}) # delete db.collection.remove({})Copy the code

Mongo update

# update: update objects and some update operators (such as $,$inc...) If no update record exists, true is used to insert new data. Default is false. (Optional), the default is false to update only the first document retrieved, otherwise true to update multiple records retrieved # writeConcern: Db.collection. update(<query>, <update>, {upsert: < Boolean >, multi: < Boolean >, writeConcern: <document> } )Copy the code

Mongo new

Db.collection. insert({name: 'Medusa', description: 'new MongoDB data'})Copy the code

Mongo comparison operators

Is equal to {key:value} less than {key: {$lt :value}} more than {key: {$gt :value}} less than or equal to {key: {$lte :value}} more than or equal to {key: {$lte :value}} {$gte :value}} {key: {$ne :value}}Copy the code

Relationship between Mongo operator

AND	         {key1:value1, key2:value2}
OR	         {$or: [{key1: value1}, {key2:value2}]}
Copy the code

Mongo polymerization

To be updatedCopy the code

Mongo returns the raw data after aggregation

db.getCollection("DBName").aggregate( [ {$sort : {time : -1}}, { $group: { _id: { "a": "$A", "b": $B: {$first: "?ROOT"}}}]) $B: {$first: "?ROOT"}}}]Copy the code

Redis

Redis is introduced

Website: https://redis.io/ Redis is a lightweight storage database in general will use Redis as a cache DB data store # Advantages * support persistent in disk * support five data types * support data backup * high read and write efficiency (about 110000 reads /s, Write about 81000 times /s) * atomicity, either success or failure * transaction * storage validityCopy the code

Redis storage mode

Redis is a key-value way of storing data, just like Python dictionaries use keys to get the values of keysCopy the code

Storage type of Redis

describe instructions introduce
String string The most basic data type in Redis is binary safe, which also indicates that strings can accept any format of data, such as characters, Json data, image files, numbers, etc. It is the standard k-v mode, generally used to store characters and data, etc. The maximum length of Value is 512MB
Hash Hash value In Redis, a name can be used to store multiple K-Vs, and a name can store a maximum of 4294967295 K-Vs
List The list of Lists allow data elements to be added or removed from both ends of a sequence. Lists are ordered, repeatable sequences of strings, similar to Python lists, which contain a maximum number of elements of 4294967295
Set A collection of Collections are unordered, and like lists, it is efficient to perform inserts and deletions and determine whether or not an element is present. The biggest advantage of the set is that it can carry out the operation of intersection union and difference set. The maximum number of elements in the set is 4294967295
Sorted Set An ordered set The ordered set is based on the set with the weight parameter score, which can sort the set