mysqldump on slave
mysql replication backup on slave
mysqldump for additional slave


Master에 영향을 주지 않고 특정 슬레이브에서 덤프를 하고 싶을때
mysqldump option --dump-slave 옵션 사용 가능


예시)
mysqldump --all-databases --dump-slave=2 --single-transaction --order-by-primary -u 계정 -p > /덤프/파일명.sql

--dump-slave=2 : dump를 실행하는 슬레이브에 설정된 Master 서버 정보를 dump 파일에 CHANGE MASTER TO 로 기록

1: 실제 statement로 기록 / 2: CHANGE MASTER TO를 주석 처리


--------------

관련 옵션)
--master-data=2 : dump를 실행하는 서버의 정보를 CHANGE MASTER TO 정보로 기록

마스터에서 직접 dump를 실행할 경우나, 슬레이브에서 슬레이브 체인을 구성할때{M -> S(M) -> S} 활용 가능



참고:
https://dev.mysql.com/doc/refman/5.6/en/mysqldump.html#option_mysqldump_dump-slave

'개발' 카테고리의 다른 글

PHP Session handler Redis 설정  (0) 2017.12.22
Let’s Encrypt SSL 인증서 설치 경로 변경  (0) 2017.12.22
uCloud NAS 연결  (0) 2017.12.22
Hshare Demon Install (CentOS 6.9)  (0) 2017.12.22
[CodeIgniter] URL에서 index.php 제거  (0) 2017.03.20

1. STS로 Spring MVC Project 생성 후 접속 확인

- 한글이 깨져서 나오니 home.jsp 파일에
<%@ page language="java" contentType="text/html; charset=UTF-8"  %> 추가


2. pom.xml에 dependency 추가

(버전 확인 - http://mvnrepository.com/)
<dependency>
    <groupId>org.mybatis</groupId>
    <artifactId>mybatis</artifactId>
    <version>3.2.7</version>
</dependency>

<dependency>
    <groupId>org.mybatis</groupId>
    <artifactId>mybatis-spring</artifactId>
    <version>1.2.2</version>
</dependency>

<dependency>
    <groupId>mysql</groupId>
    <artifactId>mysql-connector-java</artifactId>
    <version>5.1.31</version>
</dependency>

<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-jdbc</artifactId>
    <version>3.2.3.RELEASE</version>
</dependency>



3. root-context.xml에 bean 추가

<bean id="dataSource" class="org.apache.ibatis.datasource.pooled.PooledDataSource">
    <property name="driver" value="com.mysql.jdbc.Driver"/>
    <property name="url" value="jdbc:mysql://localhost:3306/스키마이름"/>
    <property name="username" value="계정"/>
    <property name="password" value="암호"/>
</bean>

<bean id ="sqlSessionFactory" class= "org.mybatis.spring.SqlSessionFactoryBean" >
    <property name ="dataSource" ref= "dataSource"></property >
    <property name ="configLocation"
        value= "classpath:/mybatis/mybatis-config.xml" >
    </property >
</bean >

<bean id ="transactionManager"
    class= "org.springframework.jdbc.datasource.DataSourceTransactionManager" >
    <property name ="dataSource" ref= "dataSource"></property >
</bean >

<bean id ="sqlSession"
    class= "org.mybatis.spring.SqlSessionTemplate" >
    <constructor-arg ref= "sqlSessionFactory"></constructor-arg >

</bean >



4. mybatis-config.xml 생성

(src/main/resources/mybatis/mybatis-config.xml)

<?xml version="1.0" encoding= "UTF-8" ?>
<!DOCTYPE configuration
PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-config.dtd" >

<configuration>
    <mappers >
        <mapper resource ="/mybatis/mapper-sample.xml"/>
    </mappers >
</configuration>



5. mapper-sample.xml 생성

(src/main/resources/mybatis/mapper-sample.xml)
<?xml version="1.0" encoding= "UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd" >

<mapper namespace= "userControlMapper" >
    <select id ="selectSample" parameterType="java.util.HashMap" resultType= "java.util.HashMap">
        SELECT *
        FROM TEST_USERS
        WHERE NAME = #{name}
    </select>

    <insert id ="insertTable01" parameterType="java.util.HashMap" >
        INSERT INTO TEST_USERS
        (NAME, EMAIL)
        VALUES
        ( #{name}, #{email} )
    </insert>

</mapper>



6. MySQL에 테스트 table과 data 준비

CREATE TABLE `스키마이름`.`TEST_USERS` (
    `NO` INT NOT NULL AUTO_INCREMENT,
    `NAME` VARCHAR(100) NULL,
    `EMAIL` VARCHAR(100) NULL,
    PRIMARY KEY (`NO`),
    UNIQUE INDEX `NO_UNIQUE` (`NO` ASC));

INSERT INTO TEST_USERS (NAME, EMAIL) VALUES ("han", "han@test.com");



7. HomeController.java 수정

@Controller
public class HomeController {

@Controller
public class HomeController {
    
    // <--- 추가 
    @Autowired
    private SqlSession sqlSession;
    // 추가 --->
    
    private static final Logger logger = LoggerFactory.getLogger(HomeController.class);
    
    /**
    * Simply selects the home view to render by returning its name.
    */
    @RequestMapping(value = "/", method = RequestMethod.GET)
    public String home(Locale locale, Model model) {
        logger.info("Welcome home! The client locale is {}.", locale);
        
        Date date = new Date();
        DateFormat dateFormat = DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.LONG, locale);
        
        String formattedDate = dateFormat.format(date);
        
        model.addAttribute("serverTime", formattedDate );
        
        // <--- 추가 
        HashMap<String, String> input = new HashMap<String, String>();
        input.put("name", "han");
        List<HashMap<String, String>> outputs = sqlSession.selectList("userControlMapper.selectSample", input);
        System.out.println(outputs.toString());
        // 추가 --->
        
        return "home";
}
    
}



8. 브라우저로 server 접속 후 Console 출력 확인

- [{NO=1, EMAIL=han@test.com, NAME=han}]


참고 :
http://blog.naver.com/refreshin/150170189512








http://hangaebal.blogspot.kr/2014/08/spring-spring-tool-suitests-mysql.html



DELIMITER $$

CREATE PROCEDURE myFunction()
BEGIN

    DECLARE i INT DEFAULT 1;

    WHILE (i < 500000) DO
        INSERT INTO `test table` (num, name, email)
        VALUE (i, CONCAT(‘test’, i), HEX(AES_ENCRYPT(CONCAT(‘test’, i, ‘@test.com’), ‘key’)));
        SET i = i + 1;
    END WHILE;
END$$

DELIMITER ;
CALL myFunction();




http://hangaebal.blogspot.kr/2014/07/mysql-procedure-loop-insert.html

 Node.js - Error connection lost the server closed the connection
Error: Connection lost: The server closed the connection.


var db_config = {
  host: 'localhost',
    user: 'root',
    password: '',
    database: 'example'
};

var connection;

function handleDisconnect() {
  connection = mysql.createConnection(db_config); // Recreate the connection, since
                                                  // the old one cannot be reused.

  connection.connect(function(err) {              // The server is either down
    if(err) {                                     // or restarting (takes a while sometimes).
      console.log('error when connecting to db:', err);
      setTimeout(handleDisconnect, 2000); // We introduce a delay before attempting to reconnect,
    }                                     // to avoid a hot loop, and to allow our node script to
  });                                     // process asynchronous requests in the meantime.
                                          // If you're also serving http, display a 503 error.
  connection.on('error', function(err) {
    console.log('db error', err);
    if(err.code === 'PROTOCOL_CONNECTION_LOST') { // Connection to the MySQL server is usually
      handleDisconnect();                         // lost due to either server restart, or a
    } else {                                      // connnection idle timeout (the wait_timeout
      throw err;                                  // server variable configures this)
    }
  });
}

handleDisconnect();



출처 :
http://stackoverflow.com/questions/20210522/nodejs-mysql-error-connection-lost-the-server-closed-the-connection

http://hangaebal.blogspot.kr/2014/06/nodejs-error-connection-lost-server.html

+ Recent posts