728x90

MySQL 오늘기준으로 최근 한달 동안 데이터 가져오기

 

긴 말이 필요 없습니다. 기준이 되는 데이터 칼럼만 있다면 BETWEEN 과 DATE_ADD() 함수를 이용해서

간단하게 가져올 수가 있습니다.

 

SELECT seq, title FROM TABLE WHERE DATE_COLUMN BETWEEN DATE_ADD(NOW(),INTERVAL -1 MONTH ) AND NOW();

 

그럼 오늘 기준으로 최근 일주일 동안 데이터를 가져올려면 어떻게 해야 할까요.

아래와 같이 MONTH를 WEEK로만 바꿔 주시면 됩니다.

 

SELECT seq, title FROM TABLE WHERE DATE_COLUMN BETWEEN DATE_ADD(NOW(),INTERVAL -1 WEEK ) AND NOW();

 

 

 

From : 높이뜬새(www.webmadang.net)

 


728x90
등록되어있는 코드를 보려면 다음 명령을 실행한다.

[프로시져 목록 확인방법]
mysql> show procedure status 

[프로시져 스크림트 확인방법]
mysql> show create procedure uso_Get_Mini_Evaluation

[뷰 스크립트 확인방법]
mysql> show create view v_core_ability_examination



출처: http://sangmin.tistory.com/1553 [Pell's seer Blog]

출처: http://sangmin.tistory.com/1553 [Pell's seer Blog]

728x90


개요

MySQL 의 default character set 은 MySQL 의 설정 파일에 설정할 수 있다.

배포판
위치
RHEL/CentOS /etc/my.cnf
Ubuntu /etc/mysql/mysql.conf.d/mysqld.cnf


명시적으로 설정하지 않으면 기본 캐릭터 셋은 latin1 이 된다. 현재 characterset 확인은 다음과 같이 mysql 클라이언트로 연결한 후에 status 명령어로 알수 있다.

또는 다음과 같이 mysql 콘솔에서 show variable 을 사용해도 된다.

mysql> show variables like 'char%';


redmine, gitlab 등 거의 모든 app 들은 charset 으로 UTF-8 을 권장하고 있고 실제로도 UTF-8 을 사용하는게 정신건강에 좋다.

MySQL 5.1 과 5.5 이상은 my.cnf 에 캐릭터 셋 설정하는 방식이 약간 다르다.


설정

MySQL 5.5 이상

MySQL 5.5 부터는 default-character-set 옵션이 제거되었고 character-set-server 만 설정해 주면 된다.

skip-character-set-client-handshake 가 빠지면 client 의 시스템 encoding 을 사용하는데 윈도의 경우 euckr 로 설정 될수 있으므로 필요하다.

MySQL 5.5
[mysqld]
collation-server = utf8_unicode_ci
character-set-server = utf8
skip-character-set-client-handshake


이제 service mysqld restart 로 재구동후에 mysql client 에서 status 명령어로 보면 charset 이 utf-8 로 변경되었을 것이다.


MySQL 5.1

5.1 은 다음과 같이 설정해야 한다.

MySQL 5.1
[mysqld]
character-set-server = utf8
  
[client]
default-character-set=utf8
 
[mysql]
default-character-set=utf8

UTF8-MB 

Emoji 는 기존 utf-8 로는 표현을 못하므로 MySQL에서 이모지를 저장하려면 4바이트의 가변 길이를 갖는 utf8mb4 캐릭터 셋을 사용해야 한다. (MySQL 5.5.3 이상 필요)

[mysqld]
collation-server = utf8mb4_unicode_ci
character-set-server = utf8mb4
skip-character-set-client-handshake


이미 기존에 만들어진 database 라면 alter database 명령어로 캐릭터 셋과 collate 를 변경할 수 있다.


character set 변경
ALTER DATABASE homestead CHARACTER SET = utf8mb4 COLLATE = utf8mb4_unicode_ci;


같이 보기

Ref

utf8mb4_unicode_ci 

728x90

List stored procedures in MySQL

Posted in MySql - Last updated Oct. 05, 2011

This post shows how to get a complete list of stored procedures in a MySQL database and then to see what code is used in the stored procedure.

List MySQL stored procedures

Run the following SQL query either from the MySQL command line, or using a GUI tool like phpMyAdmin to get a complete list of stored procedures from all databases your login has access to:

SHOW PROCEDURE STATUS

To just list procedures from a particular database do this, where we want to query stored procedures from the "mydb_abc" database:

SHOW PROCEDURE STATUS WHERE Db = 'mydb'

The output from the above commands will look something like this:

+------+---------+-----------+---------+---------------------+---------------------+---------------+---------+----------------------+----------------------+--------------------+
| Db   | Name    | Type      | Definer | Modified            | Created             | Security_type | Comment | character_set_client | collation_connection | Database Collation |
+------+---------+-----------+---------+---------------------+---------------------+---------------+---------+----------------------+----------------------+--------------------+
| mydb | mysproc | PROCEDURE | root@%  | 2011-08-18 20:29:53 | 2011-08-18 20:29:53 | DEFINER       |         | utf8                 | utf8_general_ci      | latin1_swedish_ci  |
+------+---------+-----------+---------+---------------------+---------------------+---------------+---------+----------------------+----------------------+--------------------+

Show the SQL code in the stored procedure

Use the show create procedure query to get the SQL code from the query. To get it for the "mysproc" stored procedure in the example output above, do this:

SHOW CREATE PROCEDURE mysproc

This then gives you a few fields as a resultset and it's the "Create Procedure" column which has the procedure creation SQL.

+ Recent posts