Skip to content

Instantly share code, notes, and snippets.

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@weizh888
weizh888 / mysql_db_migration.md
Last active September 24, 2019 04:03
copy tables or databases from one MySQL server to another MySQL server

Do in ONE Step

mysqldump -u root -p database_name | mysql -h other-host.com database_name

Do in TWO Steps

Step 1: dump from old DB

mysqldump -u root -p database_name table_name > dump.txt

1. Clone your fork:

git clone [email protected]:YOUR-USERNAME/YOUR-FORKED-REPO.git

2. Add remote from original repository in your forked repository:

cd into/cloned/fork-repo
git remote add upstream git://github.com/ORIGINAL-DEV-USERNAME/REPO-YOU-FORKED-FROM.git
git fetch upstream
  • .gitignore

  • git config core.fileMode false

  • git config core.autocrlf or git config --global core.autocrlf or git config --local core.autocrlf

  • Specify the python version
virtualenv --python=<local_python_path> <venv_name>

Forward jupyter notebook from remote host

Host abc
  HostName xx.xx.xxx.xx
  User username
  • In .bash_profile:
function jptabc(){
git clone xxx
git remote add <another-fork-alias> <another-fork-URL>
git checkout <local_branch>
  • MYSQL

    • date --> unix timestamp

    UNIX_TIMESTAMP('2018-09-25', 'yyyy-MM-dd')

    • unix timestamp --> date

FROM_UNIXTIME(1255033470, 'yyyy-MM-dd')

  • Method 1
import os

file_path = 'path/to/file/example.csv'
filename_w_ext = os.path.basename(file_path)
filename, file_ext = os.path.splitext(filename_w_ext)

Output:

import pandas as pd
import zipfile

zip_file_path = 'file_path'
zf = zipfile.ZipFile(zip_file_path)

csv_file_name = 'csv_file_name'
df = pd.read_csv(zf.open(csv_file_name))