====== mysql-shell ====== * [[https://dev.mysql.com/doc/mysql-shell/8.0/en/|mysql-shell]] * [[database:mysql|MySQL]] DB 에 접속해서 [[:javascript|Javascript]], [[:python|Python]] 혹은 SQL 명령으로 조작 ===== install ===== * https://dev.mysql.com/downloads/shell/ * [[https://dev.mysql.com/doc/mysql-shell/8.0/en/mysql-shell-install-linux-quick.html|MySQL :: MySQL Shell 8.0 :: 2.2 Installing MySQL Shell on Linux]] ==== snapcraft ==== # snap 설치시에 파일 백업 경로등이 올바로 잡히지 않음. # 경로를 /tmp 로 지정하면 /tmp/snap-private-tmp 로 잡히는 문제가 있음. sudo snap install mysql-shell ==== apt repo ==== * https://dev.mysql.com/downloads/repo/apt/ 에서 mysql-apt-config 패키지 다운로드 * 정작 제대로 작동안했음. sudo dpkg -i mysql-apt-config__all.deb sudo apt-get update # update repository configuration 필요할 경우에만 sudo apt-get install mysql-apt-config sudo apt-get install mysql-shell ===== 실행 ===== * ''mysqlsh'' 명령으로 실행 ===== 기본 명령 ===== * 기본 명령들이 ''\'' (역슬래시)로 시작한다는 점 주의 * [[https://dev.mysql.com/doc/mysql-shell/8.0/en/mysql-shell-commands.html|mysql-shell 명령어들]] * 접속 \connect : ==== 언어 모드 변경 ==== * ''javascript'' 버전과 ''python'', ''sql'' 버전이 존재한다. * ''py'' 버전은 snake_case 에 python dictionary 방식으로 옵션을 지정해야한다. \js # to javascript \py # to python \sql # to sql ===== dump & load (backup / restore) ===== * [[https://dev.mysql.com/doc/mysql-shell/8.0/en/mysql-shell-utilities-dump-instance-schema.html|MySQL :: MySQL Shell 8.0 :: 11.5 Instance Dump Utility, Schema Dump Utility, and Table Dump Utility]] * [[https://hoing.io/archives/17918|MySQL Shell - Dump Utility - mysqlsh | Hoing]] * [[database:mysql:dump|MySQL Database Dump & Copy]] 보다 더 빠르고 강력하다고 한다. * ''util.dump_tables()'', ''util.dump_instance()'', ''util.dump_schemas()'' ==== Table 단위 dump / load ==== util.dump_tables('', ['table1', 'table2'], '/저장/경로/dir'); * 이는 python 코드를 호출하는 것이기 때문에 각 파라미터를 변수에 넣어두고 변수로 지정해줘도 된다. ===== 참조 ===== * [[https://www.percona.com/blog/mysql-shell-for-vs-code-your-new-gui/|MySQL Shell For VS Code - Your New GUI? - Percona Database Performance Blog]]