Transfer from sqlite to MySQL/ sqlite에서 mysql로 변환

 

 

This article is about moving data from sqlite to MySQL. For information on moving the other direction, see its companion article, Transfer from MySQL to sqlite.

There are two general approaches to this problem:

  1. Use the command line utility sqlite3 to dump the contents of the sqlite database to a file, then massage the file, then upload its contents to MySQL using the utility mysql; or
  • Use the wee_database utility to transfer the sqlite archive to a MySQL database.

The first is more general and can be done independently of weeWX. The second is simpler, but requires access to a weeWX installation.

Please note that the python-mysqldb module is required to use weeWX with a MySQL database.

Using sqlite3 and mysql commands

For approach #1, first dump the sqlite database using the utility sqlite3. Adjust the path to the sqlite3 database, weewx.sdb, as necessary. Note: you may have to install sqlite3 first.

$ echo ".dump archive" | sqlite3 weewx.sdb > weewx.sql

Now recreate in MySQL. Start by creating the database:

$ echo "CREATE DATABASE weewx" | mysql -u root -p

Now restore using the contents of the file weewx.sql, massaged a bit:

$ sed -e '/PRAGMA/d' -e's/BEGIN/START/' -e 's/"archive"/archive/' < weewx.sql | mysql -u root -p --database=weewx

This will result in a database weewx in MySQL, with a single table, archive, holding the contents of your sqlite archive file.

If the new database is to be used as the weewx archive, weewx will need to be configured to use MySQL as per the Configuring MySQL section of the User's Guide.

There is one more step before the new database can be used with weewx: creating the daily summaries inside the new database. If weewx is configured to use the new database the daily summaries will be built automatically by weewx at the next startup. Alternatively, the daily summaries can be built manually using the wee_database utility and the --backfill-daily option:

$ wee_database --backfill-daily

Using wee_database

To transfer a database using wee_database, data bindings for both the source and destination databases must exist in weewx.conf. As the source database will most likely be the archive database currently used by weeWX, it is likely that only the destination database will require the addition of a data binding to weewx.conf. To add a data binding; edit weewx.conf, locate the [DataBinding] section and add a binding similar to the following:

경축! 아무것도 안하여 에스천사게임즈가 새로운 모습으로 재오픈 하였습니다.
어린이용이며, 설치가 필요없는 브라우저 게임입니다.
https://s1004games.com

    [[dest_binding]]
        database = archive_mysql
        table_name = archive
        manager = weewx.wxmanager.WXDaySummaryManager
        schema = schemas.wview.schema

The above settings assume an archive_sqlite entry in the weewx.conf [Databases] section and use the default wview database schema. If this is not the case (e.g., you use a modified schema) you will need to alter one of more of the above settings accordingly.

Before doing the transfer, it may worthwhile to run wee_database with the --help option:

$ wee_database --help

Note the --dry-run option. When used with the --transfer option, wee_database prints out what would happen but does not actually do the transfer.

To use the --dry-run option with --transfer:

$ wee_database --transfer --dest-binding=dest_binding --dry-run

This will result in output something like this:

Using configuration file /home/weewx/weewx.conf
Using database binding 'wx_binding', which is bound to database 'archive_sqlite'
Transfer 7814 records from source database 'weewx.sdb' to destination database 'weewx'.
Dry run, nothing done.

If the dry run was successful the transfer can be completed using the following command:

$ wee_database --transfer --dest-binding=dest_binding

This will result in output something like this:

Using configuration file /home/weewx/weewx.conf
Using database binding 'wx_binding', which is bound to database 'archive_sqlite'
Transfer 7814 records from source database 'weewx.sdb' to destination database 'weewx' (y/n)? y
transferring, this may take a while.... complete
7814 records transferred from source database 'weewx.sdb' to destination database 'weewx'.

Once the transfer is complete and before the new database can be used with weeWX the daily summaries need to be created inside the new database. If weeWX is configured to use the new database, the daily summaries will be built automatically by weeWX at the next startup. Alternatively, the daily summaries can be built manually using the wee_database utility and the --backfill-daily option:

$ wee_database --backfill-daily --binding=dest_binding

If the new database is to be used as the weeWX archive then weeWX needs to be configured to use MySQL as per the Configuring MySQL section of the User's Guide

Caveats

WeeWX v3.0.0 or greater is required in order to use wee_database to transfer from sqlite to MySQL. When weeWX is installed using setup.py and the default location of /home/weewx, wee_database is installed to /home/weewx/bin/wee_database. When weeWX is installed using .deb or .rpm, wee_database is installed to /usr/share/weewx/wee_database with a symbolic link /usr/bin/wee_database.

The database transfer option was added in v3.3.0. For weeWX v3.2.1 and earlier, the latest version of wee_database can be downloaded from the weewx GitHub code repository:

$ wget -O wee_datbase https://raw.githubusercontent.com/weewx/weewx/master/bin/wee_database

 

[출처] https://github.com/weewx/weewx/wiki/Transfer-from-sqlite-to-MySQL

본 웹사이트는 광고를 포함하고 있습니다.
광고 클릭에서 발생하는 수익금은 모두 웹사이트 서버의 유지 및 관리, 그리고 기술 콘텐츠 향상을 위해 쓰여집니다.
번호 제목 글쓴이 날짜 조회 수
공지 오라클 기본 샘플 데이터베이스 졸리운_곰 2014.01.02 86078
공지 [SQL컨셉] 서적 "SQL컨셉"의 샘플 데이타 베이스 SAMPLE DATABASE of ORACLE 가을의 곰을... 2013.02.10 78599
공지 [G_SQL] Sample Database 가을의 곰을... 2012.05.20 95324
18 TensorFlow Lite 101 - MoblieNet 맛보기 file 졸리운_곰 2018.05.30 1089
17 Apache MXNet에서 사전 트레이닝된 모델을 사용해 보세요. 졸리운_곰 2018.05.30 988
16 MXNet을 활용한 이미지 분류 앱 개발하기 file 졸리운_곰 2018.05.30 1424
15 세상에 있는 (거의) 모든 머신러닝 문제 공략법 file 졸리운_곰 2018.05.30 1119
14 sklearn 내부의 pickle lib 를 통해 모델을 저장하고 다시 로드하여 재사용할 수 있다. 졸리운_곰 2018.05.30 1636
13 텐서플로우 기반 딥러닝 훈련 모델 파일 저장, 로딩 및 재활용 file 졸리운_곰 2018.05.30 1765
12 TensorFlow 모델을 저장하고 불러오기 (save and restore) 졸리운_곰 2018.05.30 1637
11 텐서플로우(TensorFlow)를 이용해서 글자 생성(Text Generation) 해보기 – Recurrent Neural Networks(RNNs) 예제 – Char-RNN file 졸리운_곰 2018.05.13 1121
10 외장형 그래픽카드로 우분투에서 텐서플로우 사용 How to setup an eGPU on Ubuntu for TensorFlow file 졸리운_곰 2018.05.09 1426
9 Keras and NLTK 케라스를 이용한 NLTK 자연어처리 졸리운_곰 2018.05.08 1600
8 Windows7에서 "처음 심층 학습 프로그램」을 사경 보면 (1-2) 제 1 장 후반 file 졸리운_곰 2018.05.08 1138
7 CSLAIER CSLAIER에 의한 LSTM file 졸리운_곰 2018.05.08 1661
6 Tensorboard 사용하기 1 file 졸리운_곰 2018.05.08 1410
5 텐서보드 사용법 file 졸리운_곰 2018.05.08 1407
4 Ubuntu 18.04 Settings for TensorFlow 설치 file 졸리운_곰 2018.05.08 1181
3 딥러닝용 서버 설치기 file 졸리운_곰 2018.05.07 1391
2 Installing Tensorflow GPU on Ubuntu 18.04 LTS file 졸리운_곰 2018.05.06 1215
1 TensorFlow Lite 101 - MoblieNet 맛보기 file 졸리운_곰 2018.04.07 1272
대표 김성준 주소 : 경기 용인 분당수지 U타워 등록번호 : 142-07-27414
통신판매업 신고 : 제2012-용인수지-0185호 출판업 신고 : 수지구청 제 123호 개인정보보호최고책임자 : 김성준 sjkim70@stechstar.com
대표전화 : 010-4589-2193 [fax] 02-6280-1294 COPYRIGHT(C) stechstar.com ALL RIGHTS RESERVED