mysql

MySQL on duplicate key… get existing ID?

筅森魡賤 提交于 2021-02-17 05:44:07
问题 I'm using ON DUPLICATE KEY UPDATE to handle duplicate inserts on a table, in order that they are discarded. In my case it's a simple table storing tags: id (int, PK, AI, unsigned, not null) tag (varchar 25, not null, unique) This is working fine, but I need to retrieve the ID - either the insert ID, on successful insert, or the existing ID, if it's a duplicate. I'm getting insert ID = 0 where ON DUPLICATE KEY UPDATE fires, which I guess is expected behaviour since no insert took place. Is

mysql how to compare date in the format dd-mon-yy

我是研究僧i 提交于 2021-02-17 05:43:08
问题 How do I compare date in the format dd-mon-yy ? For example: 10-NOV-14 > 07-OCT-13. select expiration_date from grocery where expiration_date < 14-oct-13 回答1: Use STR_TO_DATE: select expiration_date from grocery where expiration_date < STR_TO_DATE('14-oct-13', '%d-%b-%y') expiration_date will also need to be wrapped in STR_TO_DATE if it is not already a DATE format. 来源: https://stackoverflow.com/questions/19366376/mysql-how-to-compare-date-in-the-format-dd-mon-yy

MySQL container crash after /etc/mysql/my.cnf change, how to edit back?

旧城冷巷雨未停 提交于 2021-02-17 05:27:29
问题 I changed some mysql config settings and set something wrong, now Docker container keeps restarting and I cannot find the my.cnf file to edit in host filesystem. I have tried aufs/diff folders but so far unable to find it. Also tried: find / -name my.cnf -exec nano {} \; But it does not bring up the file I changed. And I tried to change config.v2.json to start /bin/bash instead of mysqld and restarted docker, but yet it started mysqld (due supervisor or something?) using official mysql

Subtract months from current date sql

北城以北 提交于 2021-02-17 05:22:05
问题 I am trying to substract dates from today (Get a 1 month ago till forever report). So far I've tried DATE_SUB(NOW(), INTERVAL 1 MONTH) Here is the context: SELECT contracts.currency , ROUND(SUM( CASE WHEN contracts.currency = 'USD' THEN contracts.value*550 WHEN contracts.currency = 'UF' THEN contracts.value*22000 ELSE contracts.value END),2) AS real_value FROM contracts WHERE currency IN ('USD','UF','CLP') AND date >=DATE_SUB(NOW(), INTERVAL 1 MONTH) GROUP BY currency ORDER BY currency ASC

Subtract months from current date sql

浪子不回头ぞ 提交于 2021-02-17 05:21:12
问题 I am trying to substract dates from today (Get a 1 month ago till forever report). So far I've tried DATE_SUB(NOW(), INTERVAL 1 MONTH) Here is the context: SELECT contracts.currency , ROUND(SUM( CASE WHEN contracts.currency = 'USD' THEN contracts.value*550 WHEN contracts.currency = 'UF' THEN contracts.value*22000 ELSE contracts.value END),2) AS real_value FROM contracts WHERE currency IN ('USD','UF','CLP') AND date >=DATE_SUB(NOW(), INTERVAL 1 MONTH) GROUP BY currency ORDER BY currency ASC

Unable to reset Root Password: windows, MySQL8.0

眉间皱痕 提交于 2021-02-17 05:13:29
问题 I have forgotten my root password and I am following the official page to reset my password.I have followed the exact steps. When I run the sql-init.txt file my bash gets stuck and the installation never completes. C:\Windows\system32>cd "C:\Program Files\MySQL\MySQL Server 8.0\bin" C:\Program Files\MySQL\MySQL Server 8.0\bin>mysqld --defaults-file="C:\\ProgramData\\MySQL\\MySQL Server 8.0\\my.ini" --init-file=C:\\mysql-init.txt --console 2019-03-04T12:06:43.930229Z 0 [Warning] [MY-010915]

Unable to reset Root Password: windows, MySQL8.0

自古美人都是妖i 提交于 2021-02-17 05:13:15
问题 I have forgotten my root password and I am following the official page to reset my password.I have followed the exact steps. When I run the sql-init.txt file my bash gets stuck and the installation never completes. C:\Windows\system32>cd "C:\Program Files\MySQL\MySQL Server 8.0\bin" C:\Program Files\MySQL\MySQL Server 8.0\bin>mysqld --defaults-file="C:\\ProgramData\\MySQL\\MySQL Server 8.0\\my.ini" --init-file=C:\\mysql-init.txt --console 2019-03-04T12:06:43.930229Z 0 [Warning] [MY-010915]

Field 'x' doesn't have a default value

。_饼干妹妹 提交于 2021-02-17 04:43:44
问题 I got an error CDbCommand failed to execute the SQL statement: SQLSTATE[HY000]: General error: 1364 Field 'editedbyid' doesn't have a default value. The SQL statement executed was: INSERT INTO `pos` (`serialnumber`, `posmodelid`, `active`, `created`, `updated`, `forapproval`, `approvedbyid`) VALUES (:yp0, :yp1, 1, NOW(), :yp2, :yp3, :yp4)" I'm using MySQL, PHP and uii framework. How can i resolve this? 回答1: The field editedbyid in your database table doesn't have a default value configured.

总结:被MySQL UTF8编码坑的惨痛教训...

旧城冷巷雨未停 提交于 2021-02-17 04:30:30
最近遇到几个项目被MySQL的utf8编码坑,想起之前编码问题被坑的惨痛教训,记录一下,警示自己。 曾几何时,每次建库都选utf8,觉得自己比那些用乱七八糟编码的人不知道酷到哪里去了。直到好多年前的某次课程设计做项目的时候,愉快的建了个用户表: CREATE TABLE `test_user` ( `id` int ( 11 ) unsigned NOT NULL AUTO_INCREMENT, `name` varchar ( 32 ) DEFAULT NULL , PRIMARY KEY ( `id` ) ) ENGINE = InnoDB DEFAULT CHARSET =utf8; 然后愉快的新增用户:INSERT INTO test_user(name) VALUES("我是😁"),接着愉快的反思人生: Incorrect string value : '\xF0\x9F\x98\x81' for column 'name' at row 1 我是谁?我来自哪里?我在干嘛?难道是我代码里面的字符集用错了?不对啊我所有地方都用的utf8啊…… # MySQL 的UTF8编码是什么? 首先来看官方文档: The character set named utf8 uses a maximum of three bytes per character and contains

VB.net to MySql Stored Procedure Error

☆樱花仙子☆ 提交于 2021-02-17 04:28:32
问题 I'm a total newb to stored procedures, so I may be missing something easy, but I researched the basics and I'm stuck trying to integrate it from vb.net code. I created a simple stored procedure (I think) that just runs a query of data for today's results: -- Routine DDL -- Note: comments before and after the routine body will not be stored by the server DELIMITER $$ CREATE DEFINER=`root`@`%` PROCEDURE `GetRuntestToday`() BEGIN Select * From runtest.runtest_records where Test_Date=CURDATE()