{"id":25939544,"url":"https://github.com/kwon37xi/jdbc-mysql-test","last_synced_at":"2026-06-09T05:31:05.039Z","repository":{"id":8607719,"uuid":"10247058","full_name":"kwon37xi/jdbc-mysql-test","owner":"kwon37xi","description":"MySQL JDBC Driver test code with Spring 3.2","archived":false,"fork":false,"pushed_at":"2013-06-02T03:56:35.000Z","size":128,"stargazers_count":4,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-12-05T00:23:21.406Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/kwon37xi.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2013-05-23T15:35:59.000Z","updated_at":"2019-08-20T07:57:27.000Z","dependencies_parsed_at":"2022-09-19T00:31:39.997Z","dependency_job_id":null,"html_url":"https://github.com/kwon37xi/jdbc-mysql-test","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/kwon37xi/jdbc-mysql-test","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kwon37xi%2Fjdbc-mysql-test","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kwon37xi%2Fjdbc-mysql-test/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kwon37xi%2Fjdbc-mysql-test/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kwon37xi%2Fjdbc-mysql-test/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kwon37xi","download_url":"https://codeload.github.com/kwon37xi/jdbc-mysql-test/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kwon37xi%2Fjdbc-mysql-test/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":34093773,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-06-09T02:00:06.510Z","response_time":63,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-03-04T04:17:53.991Z","updated_at":"2026-06-09T05:31:05.011Z","avatar_url":"https://github.com/kwon37xi.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"jdbc-mysql-test\n===============\n\nTesting MySQL JDBC Replication Driver and Spring 3.2 @Transactional(readOnly=true/false)\n\nMySQL JDBC Replication Driver는 Connection.setReadOnly(true/false) 값에 따라 true이면 Slave로\nfalse이면 Master로 요청을 보낸다.\n```\n# Replication MySQL JDBC Driver URL\njdbc:mysql:replication://MasterDB:3306,SlaveDB:3306/test?useUnicode=true\u0026useServerPrepStmts=true\u0026characterEncoding=utf8\n```\n\n이 코드는 test라는 DB에 products라는 테이블이 있다고 간주하고서 setReadOnly에 따라 정말로 Master와 Slave를 나눠서\n요청을 보내는지 확인 할 수 있도록 한다.\n\n```sql\nCREATE TABLE `products` (\n  `product_id` int(11) NOT NULL AUTO_INCREMENT,\n  `name` varchar(20) NOT NULL,\n  `cnt` int(11) NOT NULL DEFAULT '0',\n  `price` int(11) NOT NULL DEFAULT '0',\n  PRIMARY KEY (`product_id`)\n);\n```\n\nmysql master/slave의 my.cnf 에 다음 설정을 두고 /var/log/mysql/mysql.log 파일을 살펴보면 쿼리가 원하는 DB로\n날라가는지 확인할 수 있다.\n\n```\ngeneral_log_file        = /var/log/mysql/mysql.log\ngeneral_log             = 1\n```\n\n### mysqlreplicationdriver.groovy\nConnection 객체에 직접 setReadOnly()를 지정하여 정말로 master/slave로 요청이 가는지 확인해본다.\n\n```sh\n# setReadOnly(true)로 요청보내기 테스트\ngroovy mysqlreplicationdriver.groovy true\n\n# setReadOnly(false)로 요청보내기 테스트\ngroovy mysqlreplicationdriver.groovy false\n```\n\n### Spring @Transactional 테스트\nSpring의 @Transactionl(readOnly=true/false)이 제대로 setReadOnly()를 지정해주는지 확인해본다.\n```\n# Transactional(readOnly=true) 테스트\ngradle readService\n\n# Transactional(readOnly=false) 테스트 -Pproduct=제품명,갯수,개당가격 insert\ngradle writeService -Pproduct=제품명,3,5000\n```\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkwon37xi%2Fjdbc-mysql-test","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkwon37xi%2Fjdbc-mysql-test","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkwon37xi%2Fjdbc-mysql-test/lists"}