반응형

unique id 발급을 위행 만든 테이블 및 펑션

성능은 검증되지 않았습니다....ㅠ

필요하신 분들은 사용하세요~

 

- sequence table

CREATE TABLE `TB_IS_GEN_SEQ_ID` (
 `site_id` VARCHAR(20) NOT NULL DEFAULT '' COMMENT '사이트아이디',
 `gen_type` VARCHAR(8) NOT NULL COMMENT '증가유형',
 `gen_length` INT(11) NOT NULL COMMENT '자릿수',
 `prefix` VARCHAR(4) NOT NULL COMMENT '접두사',
 `increment` BIGINT(20) NULL DEFAULT NULL COMMENT '증가값',
 PRIMARY KEY (`site_id`, `gen_type`)
)
COMMENT='시퀀스 아이디 발급 테이블'
COLLATE='utf8_general_ci'
ENGINE=InnoDB

 

- function

CREATE DEFINER=`iotsid`@`%` FUNCTION `FN_GEN_SEQ_ID`(`p_site_id` varchar(20), `p_gen_type` varchar(8)
)
 RETURNS varchar(20) CHARSET utf8
 LANGUAGE SQL
 DETERMINISTIC
 MODIFIES SQL DATA
 SQL SECURITY INVOKER
 COMMENT ''
BEGIN
  DECLARE len INT;
  DECLARE pre VARCHAR(10);
  DECLARE inc BIGINT;
  
  UPDATE TB_IS_GEN_SEQ_ID
     SET increment = increment + 1
   WHERE site_id = p_site_id
     AND gen_type = p_gen_type;
    
  SELECT gen_length, prefix, increment
    INTO len, pre, inc
    FROM TB_IS_GEN_SEQ_ID
   WHERE site_id = p_site_id
     AND gen_type = p_gen_type;
  RETURN CONCAT(pre, LPAD(inc, len-CHAR_LENGTH(pre), 0));
 END

 

 

--  수정 --

DELIMITER $$
DROP FUNCTION IF EXISTS FN_GEN_SEQ_ID$$
CREATE FUNCTION `FN_GEN_SEQ_ID`(`p_site_id` varchar(20), `p_gen_type` varchar(8))
 RETURNS varchar(20) CHARSET utf8
 LANGUAGE SQL
 DETERMINISTIC
 MODIFIES SQL DATA
 SQL SECURITY INVOKER
 COMMENT ''
BEGIN
 DECLARE len INT;
 DECLARE pre VARCHAR(10);
 DECLARE inc BIGINT;
 
 IF EXISTS( SELECT 1 FROM TB_IS_GEN_SEQ_ID WHERE site_id = p_site_id AND gen_type = p_gen_type )
  UPDATE TB_IS_GEN_SEQ_ID
     SET increment = increment + 1
   WHERE site_id = p_site_id
     AND gen_type = p_gen_type;
 ELSE
  INSERT INTO TB_IS_GEN_SEQ_ID (gen_type, site_id, gen_length, prefix, increment)
  VALUES (p_gen_type, p_site_id, 10, LEFT(UPPER(p_gen_type), 4), 1);
 END IF;
    
 SELECT gen_length, prefix, increment
   INTO len, pre, inc
   FROM TB_IS_GEN_SEQ_ID
  WHERE site_id = p_site_id
    AND gen_type = p_gen_type;
   
 RETURN CONCAT(pre, LPAD(inc, len-CHAR_LENGTH(pre)-CHAR_LENGTH(inc), 0));
END$$
DELIMITER;

 

반응형
LIST
반응형

MySQL Connector/J MySQL 데이터 타입과 자바 데이터 타입 간의 변환을 유연하게 처리한다.

일반적으로, 모든 MySQL 데이터 타입은 java.lang.String으로 변환할 있고, 모든 수식 타입도 자바 수식 타입으로 변환할 있다.

다음과 같은 타입 변환은 항상 보장된다:

 

Connection Properties - Miscellaneous. 

These MySQL Data Types

Can always be converted to these Java types

CHAR, VARCHAR, BLOB, TEXT, ENUM, and SET

java.lang.String, java.io.InputStream, java.io.Reader, java.sql.Blob, java.sql.Clob

FLOAT, REAL, DOUBLE PRECISION, NUMERIC, DECIMAL, TINYINT, SMALLINT, MEDIUMINT, INTEGER, BIGINT

java.lang.String, java.lang.Short, java.lang.Integer, java.lang.Long, java.lang.Double, java.math.BigDecimal

DATE, TIME, DATETIME, TIMESTAMP

java.lang.String, java.sql.Date, java.sql.Timestamp

 

 

ResultSet.getObject() 방식은 JDBC 지정하는 방식으로 MySQL 자바 타입 간의 타입 변환을 사용한다. ResultSetMetaData.GetColumnClassName() 리턴하는 값이 아래와 나와 있다.

MySQL Types to Java Types for ResultSet.getObject(). 

 

MySQL Type Name

Return value of GetColumnClassName

Returned as Java Class

BIT(1) (new in MySQL-5.0)

BIT

java.lang.Boolean

BIT( > 1) (new in MySQL-5.0)

BIT

byte[]

TINYINT

TINYINT

java.lang.Boolean if the configuration Property tinyInt1isBit is set to true (the default) and the storage size is 1, or java.lang.Integer if not.

BOOL, BOOLEAN

TINYINT

See TINYINT, above as these are aliases for TINYINT(1), currently.

SMALLINT[(M)] [UNSIGNED]

SMALLINT [UNSIGNED]

java.lang.Integer (regardless if UNSIGNED or not)

MEDIUMINT[(M)] [UNSIGNED]

MEDIUMINT [UNSIGNED]

java.lang.Integer, if UNSIGNED java.lang.Long

INT,INTEGER[(M)] [UNSIGNED]

INTEGER [UNSIGNED]

java.lang.Integer, if UNSIGNED java.lang.Long

BIGINT[(M)] [UNSIGNED]

BIGINT [UNSIGNED]

java.lang.Long, if UNSIGNED java.math.BigInteger

FLOAT[(M,D)]

FLOAT

java.lang.Float

DOUBLE[(M,B)]

DOUBLE

java.lang.Double

DECIMAL[(M[,D])]

DECIMAL

java.math.BigDecimal

DATE

DATE

java.sql.Date

DATETIME

DATETIME

java.sql.Timestamp

TIMESTAMP[(M)]

TIMESTAMP

java.sql.Timestamp

TIME

TIME

java.sql.Time

YEAR[(2|4)]

YEAR

If yearIsDateType configuration Property is set to false, then the returned object type is java.sql.Short. If set to true (the default) then an object of type java.sql.Date (with the date set to January 1st, at midnight).

CHAR(M)

CHAR

java.lang.String (unless the character set for the column is BINARY, then byte[] is returned.

VARCHAR(M) [BINARY]

VARCHAR

java.lang.String (unless the character set for the column is BINARY, then byte[] is returned.

BINARY(M)

BINARY

byte[]

VARBINARY(M)

VARBINARY

byte[]

TINYBLOB

TINYBLOB

byte[]

TINYTEXT

VARCHAR

java.lang.String

BLOB

BLOB

byte[]

TEXT

VARCHAR

java.lang.String

MEDIUMBLOB

MEDIUMBLOB

byte[]

MEDIUMTEXT

VARCHAR

java.lang.String

LONGBLOB

LONGBLOB

byte[]

LONGTEXT

VARCHAR

java.lang.String

ENUM('value1','value2',...)

CHAR

java.lang.String

SET('value1','value2',...)

CHAR

java.lang.String

 

 

출처 : http://www.mysqlkorea.co.kr/sub.html?mcode=manual&scode=01_1&m_no=23841&cat1=1434&cat2=1438&cat3=1458&lang=k

 

반응형
LIST
반응형

centos 7 / mysql 5 버전에서 mysql yum 설치 후 root 패스워드를 모르는 경우 확인 방법...

어렵게 찾았음.

=== 원문 ===

Centos 7 3.10.0-123.8.1.el7.x86_64

Hi i have installed MySQL 5.7.7 from MySQL Yum Repository

rpm -Uvh http://dev.mysql.com/get/mysql-community-release-el7-5.noarch.rpm

After service mysqld start i use mysql_secure_installation then i get prompted for a password i just press enter and i get this error:

Error: Access denied for user 'root'@'localhost' (using password: NO)

I think i have tried everything to find the password or to reset it - but no go

here are my steps:

  1. rpm -Uvh http://dev.mysql.com/get/mysql-community-release-el7-5.noarch.rpm
  2. nano /etc/yum.repos.d/mysql-community.repo
  3. Set MySQL 5.6 enabled=0 and set MySQL 5.7 enabled=1
  4. yum install mysql-community-server
  5. service mysqld start
  6. mysql_secure_installation

Error: Access denied for user 'root'@'localhost' (using password: NO)

any help is appreciated.


답변

MySQL v 5.7 or higher generates a temporary random password after installation and stored that in mysql error log file, located at /var/log/mysqld.log 
for an installation by the MySQL Yum repository on CentOS 7.

use below command to see the password: 
shell > sudo grep 'temporary password' /var/log/mysqld.log

반응형
LIST

+ Recent posts