블로그 이미지
암초보

calendar

1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30

Notice

Tag

04-24 00:41
2018. 9. 12. 12:29 DB/MySQL

$ mysql -N -e 'show databases' | while read dbname; do mysqldump --routines --triggers --single-transaction "$dbname" > "$dbname".sql; done

posted by 암초보
2016. 10. 7. 07:58 DB/MySQL

SELECT

table_name

FROM 

information_schema.KEY_COLUMN_USAGE 

WHERE 

table_schema ='my_database' 

AND referenced_table_name = 'my_table' 

'DB > MySQL' 카테고리의 다른 글

mysqldump db별 sql 덤프  (1) 2018.09.12
selecting top N records per group  (0) 2014.08.12
INSERT IGNORE  (0) 2013.11.29
procedure function 덤프  (0) 2013.10.31
The Rows Holding the Group-wise Maximum of a Certain Column  (0) 2013.10.23
posted by 암초보
2014. 8. 12. 16:40 DB/MySQL

Group by로 묶은 것중에 n번째를 선택하는방법은...

아래 링크를 참고..

http://code.openark.org/blog/mysql/sql-selecting-top-n-records-per-group


간단한 예제. 해석은 알아서..

SELECT
    SUBSTRING_INDEX( GROUP_CONCAT(fieldA ORDER BY dateField DESC), ',', 1 ) as 'test'
FROM
    tableA
GROUP BY fieldC


그리고,,

group_concat_max_len 에 주의,,


'DB > MySQL' 카테고리의 다른 글

mysqldump db별 sql 덤프  (1) 2018.09.12
특정 테이블을 참조하고 있는 테이블 찾는 방법  (0) 2016.10.07
INSERT IGNORE  (0) 2013.11.29
procedure function 덤프  (0) 2013.10.31
The Rows Holding the Group-wise Maximum of a Certain Column  (0) 2013.10.23
posted by 암초보
2013. 11. 29. 14:42 DB/MySQL

INSERT 시 PK가 중복되면 무시하는 것.


INSERT IGNORE INTO... 이렇게 INSERT와 INTO사이에 IGNORE 만 넣어주면된다.



그 외 


INSERT문 끝에 ON DUPLICATE KEY를 사용하여

키 중복시 Update를 사용할 수도 있음..

posted by 암초보
2013. 10. 31. 17:35 DB/MySQL

mysqldump --routines --no-create-info --no-data --no-create-db --skip-opt -u계정 -p 데이터베이스이름 > 백업할 파일이름

'DB > MySQL' 카테고리의 다른 글

selecting top N records per group  (0) 2014.08.12
INSERT IGNORE  (0) 2013.11.29
The Rows Holding the Group-wise Maximum of a Certain Column  (0) 2013.10.23
datadir 변경에 대한 답변  (0) 2013.09.25
SELECT 결과 INSERT하기  (0) 2013.09.12
posted by 암초보
2013. 10. 23. 14:30 DB/MySQL

http://jan.kneschke.de/projects/mysql/groupwise-max/


아래와 같은 방법도 있다...


SELECT continent,
       SUBSTRING( MAX( CONCAT(LPAD(population,10,'0'),name) ), 10+1) AS name,
       MAX( population ) AS population
  FROM Country
 GROUP BY continent;


SELECT continent,
       SUBSTRING_INDEX(GROUP_CONCAT(name ORDER BY population, ','), ',', 1)) AS name,
       MAX( population ) AS population
  FROM Country
 GROUP BY continent;


'DB > MySQL' 카테고리의 다른 글

INSERT IGNORE  (0) 2013.11.29
procedure function 덤프  (0) 2013.10.31
datadir 변경에 대한 답변  (0) 2013.09.25
SELECT 결과 INSERT하기  (0) 2013.09.12
last_insert_id()  (0) 2013.09.11
posted by 암초보
2013. 9. 25. 19:11 DB/MySQL

If you are using ubuntu or apparmor you should permit this change in apparmor.

Edit /etc/apparmor.d/usr.sbin.mysqld and change /var/lib/mysql with the new DATADIR.

It should work.

'DB > MySQL' 카테고리의 다른 글

procedure function 덤프  (0) 2013.10.31
The Rows Holding the Group-wise Maximum of a Certain Column  (0) 2013.10.23
SELECT 결과 INSERT하기  (0) 2013.09.12
last_insert_id()  (0) 2013.09.11
INDEX  (0) 2013.08.23
posted by 암초보
2013. 9. 12. 10:43 DB/MySQL

INSERT INTO target_table SELECT * FROM ori_table

간단함.

물론  insert의 필드와 select문의 필드를 맞춰야함.

'DB > MySQL' 카테고리의 다른 글

The Rows Holding the Group-wise Maximum of a Certain Column  (0) 2013.10.23
datadir 변경에 대한 답변  (0) 2013.09.25
last_insert_id()  (0) 2013.09.11
INDEX  (0) 2013.08.23
group_concat size  (0) 2013.06.04
posted by 암초보
2013. 9. 11. 15:40 DB/MySQL

last_insert_id()

자동 증가값을 가져오는 거지....

PK를 가져오는 것이아니다...


'DB > MySQL' 카테고리의 다른 글

datadir 변경에 대한 답변  (0) 2013.09.25
SELECT 결과 INSERT하기  (0) 2013.09.12
INDEX  (0) 2013.08.23
group_concat size  (0) 2013.06.04
char와 varchar 차이점  (0) 2011.10.31
posted by 암초보
2013. 8. 23. 10:11 DB/MySQL

SHOW INDEX FROM 테이블명;

SHOW KEYS FROM 테이블명;



CREATE INDEX 인덱스명 ON 테이블명(컬럼명);


DROP INDEX 인덱스명 ON 테이블명

'DB > MySQL' 카테고리의 다른 글

SELECT 결과 INSERT하기  (0) 2013.09.12
last_insert_id()  (0) 2013.09.11
group_concat size  (0) 2013.06.04
char와 varchar 차이점  (0) 2011.10.31
MySQL function 생성 실패시  (0) 2011.10.06
posted by 암초보
prev 1 2 3 next