mysql

mysql中emoji表情存储

ⅰ亾dé卋堺 提交于 2021-02-16 10:53:23
mysql中emoji表情存储 背景 在mysql 5.7.19,创建的数据库默认选择的编码是 utf8 -- UTF-8 Unicode ,因此字段默认的编码为 utf-8 ,但在项目开发中存在一个需求:在某个字段中存储混有emoji表情的字符串,此时以普通编码格式如 utf8 来存储emoji表情时,会报 org.springframework.orm.jpa.JpaSystemException: could not execute statement; nested exception is org.hibernate.exception.GenericJDBCException: could not execute statement ... Caused by: org.hibernate.exception.GenericJDBCException: could not execute statement ... Caused by: java.sql.SQLException: Incorrect string value: '\xF0\x9F\x92\x95\xE2\x80...' for column 'android_id' at row 1 请求的实例 解决方案 把 android_id 这个字段的编码格式改为: utf8mb4 ,如在Navicat中修改:

Django之ORM

前提是你 提交于 2021-02-16 10:10:34
概念 对象关系映射(Object Relational Mapping,简称ORM)模式是一种为了解决面向对象与关系数据库存在的互不匹配的现象的技术。简单的说,ORM是通过使用描述对象和数据库之间映射的元数据,将程序中的对象自动持久化到关系数据库中。ORM在业务逻辑层和数据库层之间充当了桥梁的作用 优势 ORM解决的主要问题是对象和关系的映射。它通常将一个类和一张表一一对应,类的每个实例对应表中的一条记录,类的每个属性对应表中的每个字段。 ORM提供了对数据库的映射,不用直接编写SQL代码,只需操作对象就能对数据库操作数据。让软件开发人员专注于业务逻辑的处理,提高了开发效率 劣势 ORM的缺点是会在一定程度上牺牲程序的执行效率。ORM的操作是有限的,也就是ORM定义好的操作是可以完成的,一些复杂的查询操作是完成不了。ORM用多了SQL语句就不会写了,关系数据库相关技能退化... ORM与数据库的关系 Django 项目使用MySQL数据库 1.在Django项目的settings.py文件中,修改数据库配置信息 DATABASES = { ' default ' : { ' ENGINE ' : ' django.db.backends.mysql ' , #引擎 ' NAME ' : ' orm ' , #数据库名字 ' HOST ' : ' 127.0.0.1 ' , #IP

如何在腾讯云上部署项目-小白案例

▼魔方 西西 提交于 2021-02-16 09:57:07
如何把一个简单的项目部署到 腾讯云 上 那么我们马上开始吧! * 第一步 项目打包 第二步 连接云服务器 第三步 发送打包文件和sql文件 第四步 导入sql文件,启动,测试 那么我们马上开始吧! 第一步 项目打包 1.1准备一个spring boot maven 项目 项目端口号是8091 1.2 在sts 工具中点击项目右键 – Run As – 从上到下第一个 maven build 1.3 Goals 填写package(一定要填写package)点击run 1.4 完成后出现 BUILD SUCCESS代表打包成功啦! 1.5点击target 右键打开所属文件夹目录,刚刚打包的jar,就在这里,没想到吧。 1.6 准备一个文件夹,把刚刚打包的项目剪切到这里,改名yang8091.jar,也可以把sql文件也拿过来。 在该文件夹目录栏输入cmd回车后 (会有一个小黑框跳出来) 输入指令 java -jar yang8091.jar 输入后大佬们记得要回车!回车? 名字不要写错了 1.7 出现spring 说明项目运行成功 ,在浏览器访问一下作为验证,在运行界面 ctr +c 停止服务 第二步 连接云服务器 我假设你已经有了一台免费且强大的 腾讯云 服务器, 而且还有人替你1.配置好了jdk,2.打开了端口号8091防火墙和访问设置,这当然不是我,我没有这样好的邻居

How willl I set MySQL enum datatype default value as 'No'?

大城市里の小女人 提交于 2021-02-16 09:52:42
问题 I have a field in my Mysql table whose values are ('Yes','No') which is enum data type. Here I want to set its default value as 'No'. But when I am setting it as 'No', it takes no value. How will I do this? 回答1: CREATE TABLE enum_test ( enum_fld ENUM('Yes', 'No') DEFAULT 'No' ); or something like this 回答2: If an ENUM column is declared to permit NULL , the NULL value is a legal value for the column, and the default value is NULL . If an ENUM column is declared NOT NULL , its default value is

How willl I set MySQL enum datatype default value as 'No'?

眉间皱痕 提交于 2021-02-16 09:52:04
问题 I have a field in my Mysql table whose values are ('Yes','No') which is enum data type. Here I want to set its default value as 'No'. But when I am setting it as 'No', it takes no value. How will I do this? 回答1: CREATE TABLE enum_test ( enum_fld ENUM('Yes', 'No') DEFAULT 'No' ); or something like this 回答2: If an ENUM column is declared to permit NULL , the NULL value is a legal value for the column, and the default value is NULL . If an ENUM column is declared NOT NULL , its default value is

SQL: Comparing two counts from different Tables

风格不统一 提交于 2021-02-16 09:34:05
问题 I have 3 Tables one with every Country in the World and its token NAME CODE Afghanistan AFG Albania AL Algeria DZ American Samoa AMSA Andorra AND Angola ANG Anguilla AXA (...) And and a Table of all lakes and another one of all mountains in these countries. LAKE CODE Bodensee A Neusiedlersee A Lake Prespa AL Lake Ohrid AL Lake Skutari AL Lake Eyre AUS Lake Jindabyne AUS Lake Hume AUS Lake Eucumbene AUS Lake Hume AUS Lake Burley Griffin AUS (...) MOUNTAIN CODE Hochgolling A Hochgolling A

docker-compose: reinitializing MySQL db every time

牧云@^-^@ 提交于 2021-02-16 09:23:07
问题 We have a Rails app with MySQL as DB. The db part of docker-compose.yml looks like db: image: mysql env_file: - ma.env volumes: - ./dump-db:/docker-entrypoint-initdb.d - ./my.cnf:/etc/mysql/my.cnf restart: always ports: - "3306:3306" environment: - MYSQL_HOST= and under ./dump-db folder there actually is an sql-dump of our db. Problem is, we need to have that exact dump loaded each and every time docker-compose up is run. MySQL docker image works in such a way, that it stores it's data on

如何在MySQL中使用命令行导入SQL文件?

生来就可爱ヽ(ⅴ<●) 提交于 2021-02-16 08:54:44
问题: I have a .sql file with an export from phpMyAdmin . 我有一个 .sql 文件,从 phpMyAdmin 导出。 I want to import it into a different server using the command line. 我想使用命令行将其导入到其他服务器中。 I have a Windows Server 2008 R2 installation. 我有 Windows Server 2008 R2安装。 I placed the .sql file on the C drive , and I tried this command 我将 .sql 文件放在 C驱动器上 ,并尝试了此命令 database_name < file.sql It is not working. 它不起作用。 I get syntax errors. 我收到语法错误。 How can I import this file without a problem? 如何顺利导入该文件? Do I need to create a database first? 我需要先创建一个数据库吗? 解决方案: 参考一: https://stackoom.com/question/1C7nV/如何在MySQL中使用命令行导入SQL文件

mySQL Query for summing amount in columns (months)

社会主义新天地 提交于 2021-02-16 08:54:09
问题 I have data in the following format: date (mm/dd/yyyy), desc (detail desc), category (a,b,c), tran_type (debit, credit), amount spent (amounts). I would like to get the data in the following format: category || tran_type || Jan_total || feb_total || mar_total A || debit || $101 || $201 || $302 A || credit || $500 || $600 || $200 回答1: This query should give you result required. SELECT category ,tran_type ,SUM(IF(month(date) = 1,ABS(amount),0)) as jan_total ,SUM(IF(month(date) = 2,ABS(amount),0

django cannot connect mysql in docker-compose

走远了吗. 提交于 2021-02-16 08:33:57
问题 I'm very new for docker, now I am trying to run django with mariadb in docker through docker-compose, but I always get this error: I use Docker version 17.09.1-ce, build 19e2cf6 , docker-compose version 1.18.0, build 8dd22a9 django.db.utils.OperationalError: (2003, 'Can\'t connect to MySQL server on \'mariadb55\' (111 "Connection refused")') I can connect db correctly after run docker-compose up db in local or remote, and I even can run python manage.py runserver 0.0.0.0:6001 correctly in