Turn
Moreover you also need to change column character set:
Be careful that now you have to do more things like set character set after connection initiation in Python:
Now before executing your query you also need to set character set on cursor:
#database #mysql #character_set #utf8mb4 #cursor #emoji
MySQL
table into utf8mb4
to store emojis:ALTER TABLE YOUR_TABLE convert to character set utf8mb4 collate utf8mb4_general_ci;
Moreover you also need to change column character set:
ALTER TABLE YOUR_TABLE CHANGE YOUR_COLUMN_NAME YOUR_COLUMN_NAME VARCHAR(250) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;
Be careful that now you have to do more things like set character set after connection initiation in Python:
your_mysql_client = MySQLdb.connect(...)
your_mysql_client.set_character_set('utf8mb4')
Now before executing your query you also need to set character set on cursor:
my_cursor.execute("SET NAMES utf8mb4;")
my_cursor.execute(YOUR_QUERY)
#database #mysql #character_set #utf8mb4 #cursor #emoji
With
So be careful with it!
#mysql #mysqldump #port #port_ignorance #3306 #backup #database_backup #sockets #ip_address #localhost
mysqldump
you can export databases. with --port
parameter you can specify which port it should connects. If you provide localhost
for --host
parameter, mySQL will use sockets and port will be ignored.So be careful with it!
#mysql #mysqldump #port #port_ignorance #3306 #backup #database_backup #sockets #ip_address #localhost
Table compression in
https://dev.mysql.com/doc/refman/5.5/en/innodb-compression-usage.html
#database #mysql #compression #innodb
MySQL
:https://dev.mysql.com/doc/refman/5.5/en/innodb-compression-usage.html
#database #mysql #compression #innodb
https://www.jetbrains.com/research/devecosystem-2018/databases/
It seems
#database #survey
It seems
MongoDB
is trying to be the first in the next decade.#database #survey
JetBrains
Databases in 2018 - The State of Developer Ecosystem by JetBrains
Over 6,000+ developers share their insights on modern database programming. Keep up with the most relevant technologies and databases in this infographic!
What does
In the above code 2 queries are issued in DB side. First it gets Entry record and then blog is fetched from DB when
You can follow foreign keys in a similar way to querying them. If you have the following models:
Then a call to
#python #django #select_related #join #database #models
select_related
do in Django
?select_related
does a join in case needed on the DB side and reduce query counts. Let's look at an example:# Hits the database.
e = Entry.objects.get(id=5)
# Hits the database again to get the related Blog object.
b = e.blog
In the above code 2 queries are issued in DB side. First it gets Entry record and then blog is fetched from DB when
e.blog
is called. And here’s select_related lookup:# Hits the database.
e = Entry.objects.select_related('blog').get(id=5)
# Doesn't hit the database, because e.blog has been prepopulated
# in the previous query.
b = e.blog
You can follow foreign keys in a similar way to querying them. If you have the following models:
from django.db import models
class City(models.Model):
# ...
pass
class Person(models.Model):
# ...
hometown = models.ForeignKey(
City,
on_delete=models.SET_NULL,
blank=True,
null=True,
)
class Book(models.Model):
# ...
author = models.ForeignKey(Person, on_delete=models.CASCADE)
Then a call to
Book.objects.select_related('author__hometown').get(id=4)
will cache the related Person and the related City:# Hits the database with joins to the author and hometown tables.
b = Book.objects.select_related('author__hometown').get(id=4)
p = b.author # Doesn't hit the database.
c = p.hometown # Doesn't hit the database.
# Without select_related()...
b = Book.objects.get(id=4) # Hits the database.
p = b.author # Hits the database.
c = p.hometown # Hits the database.
#python #django #select_related #join #database #models
Did you know you can use jsonSchema in MongoDB to search for documents?
Let's say you have
Now let's say you want to find all documents that has a customer_id of type
In Mongo shell:
This schema says look for documents that have
Interesting, right? :)
#database #mongodb #jsonSchema #json_schema
Let's say you have
users
collection with data below:{ "_id" : ObjectId("5f64bd1eca8806f2c04fcbe3"), "customer_id" : 100, "username" : "john" }
{ "_id" : ObjectId("5f64bd1eca8806f2c04fcbe5"), "customer_id" : 206, "username" : "new_customer" }
{ "_id" : ObjectId("60420df441558d6671cf54f2"), "customer_id" : "123", "username" : "Ali" }
Now let's say you want to find all documents that has a customer_id of type
string
instead of int
.In Mongo shell:
let ms = {required: ["customer_id"], properties: {customer_id: {bsonType: "string"}}}
This schema says look for documents that have
customer_id
field with string
type. To search:> db.customers.find({$jsonSchema: ms})
{ "_id" : ObjectId("60420df441558d6671cf54f2"), "customer_id" : "123", "username" : "Ali" }
Interesting, right? :)
#database #mongodb #jsonSchema #json_schema