Blog Cover Image

Inspire you to have New thinking, Walk out your unique Road.

有的時候,你無意間遇到的一些故事,會激發你的靈感,改變你的想法,接下來你會用與之前全然不同的觀念去創造屬於你獨特的故事。

Sign @MinaYu.

後端小菜鳥學習記錄(1)

Posted on

紀錄後端學習

9/10-9/15 第一週學習筆記

9/10

Begin(1.5h)

開始學習(3h)

Anaconda

Create python2.7 environment by using anaconda

conda create <span class="pun">-</span><span class="pln">n python2 python</span><span class="pun">=</span><span class="lit">2.7</span><span class="pln"> anaconda</span>
source activate python2

https://stackoverflow.com/questions/24405561/how-to-install-2-anacondas-python-2-and-3-on-mac-os

conda create --name pyjsviz anaconda

source activate pyjsviz

source deactivate

https://conda.io/docs/user-guide/tasks/manage-environments.html


mongoDB

https://docs.mongodb.com/v3.0/tutorial/install-mongodb-on-os-x/#install-mongodb

$ python -V
Python 3.6.5 :: Anaconda, Inc.
$ python -m http.server
Serving HTTP on 0.0.0.0 port 8000 (http://0.0.0.0:8000/) ...

<strong>flask</strong>
http://flask.pocoo.org/docs/1.0/

利用SQLAlchemy/Pymysql 兩種方法扔資料上資料庫/ 10秒內完成4000筆資料傳輸

架設MySQL/打通任督二脈(3h)

mysql+SQLAlchemy

https://www.cnblogs.com/pangguoping/p/5720322.html

https://www.pythoncentral.io/introductory-tutorial-python-sqlalchemy/

https://www.cnblogs.com/pangguoping/p/5720322.html

https://pymysql.readthedocs.io/en/latest/user/examples.html

https://blog.techbridge.cc/2017/08/12/python-web-flask101-tutorial-sqlalchemy-orm-database-models/ http://docs.sqlalchemy.org/en/latest/core/engines.html


MySQL

https://dev.mysql.com/doc/mysql-getting-started/en/#mysql-getting-started-installing

<span class="s1">-bash: mysql: command not found</span>

https://stackoverflow.com/questions/22391778/mysql-command-line-bash-command-not-found

Change Bash File

<span class="s1">vi ~/.bash_profile</span>
<span class="s1"># set mysql</span>
<span class="s1">export PATH="/usr/local/mysql/bin:$PATH"</span>

成就達成 Connect MySQL


9/11

搞懂任務內容/搞懂Mysql指令/搞懂Pymysql/SQLAlchemy(早上2.5h)

Connect to Mysql and Some Operation

https://dev.mysql.com/doc/mysql-getting-started/en/#mysql-getting-started-connecting

https://www.cyberciti.biz/faq/how-to-connect-to-my-mysql-database-server-using-command-line-and-php/

<span class="s1">Welcome to the MySQL monitor.<span class="Apple-converted-space">  </span>Commands end with ; or \g.</span>
<span class="s1">Your MySQL connection id is </span>
<span class="s1">Server version: 5.7.23 MySQL Community Server (GPL)</span>
<span class="s1">Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.</span>
<span class="s1">Oracle is a registered trademark of Oracle Corporation and/or its</span>
<span class="s1">affiliates. Other names may be trademarks of their respective </span><span class="s1">owners.</span>

<span class="s1">Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.</span>

<span class="s1">mysql></span>

資料庫階層

DataBase > Table > Column

<em>CRUD</em> (create, read, update and delete)

任務:利用SQLAlchemy/Pymysql 兩種方法扔資料上資料庫/ 10秒內完成4000筆資料傳輸

STUDY: 任何丟資料方法

https://www.cnblogs.com/pangguoping/p/5720322.html

http://docs.sqlalchemy.org/en/latest/dialects/mysql.html#module-sqlalchemy.dialects.mysql.mysqlconnector

SQLAlchemy

https://www.pythoncentral.io/introductory-tutorial-python-sqlalchemy/

http://docs.sqlalchemy.org/en/latest/core/engines.html

Flask+SQLAlchemy

https://blog.techbridge.cc/2017/08/12/python-web-flask101-tutorial-sqlalchemy-orm-database-models/

pymysql

https://pymysql.readthedocs.io/en/latest/user/examples.html

https://www.cnblogs.com/pangguoping/p/5720322.html


確認連結資料庫 (Complete)

#!/usr/bin/env python

# -*- coding: utf-8 -*-

import pymysql

# 创建连接

conn = pymysql.connect(host='hostip', port=xxxx, user='user', passwd='pw', db='db')

# 开启自动提交SQL,如果这里不设置,以后的命令需要执行conn.commit()来提交执行,否则都在内存中

conn.autocommit(True)

# 创建游标

cur = conn.cursor()

# 执行普通SQL,并返回受影响行数

effect_row = cur.execute("show tables")

print(effect_row) 

# 提交

conn.commit()

# 关闭游标

cur.close()

# 关闭连接

conn.close()

新建測試資料/扔資料上去MySQL(1.5h)

https://openhome.cc/Gossip/Python/StringFormat.html

**新建測試資料/**嘗試扔東西到MySQL(Complete)

for python 3

https://www.w3schools.com/python/python_mysql_insert.asp

sqltest = cur.execute("INSERT INTO Info(ID,Name,Mobile) VALUES (123345436, 'A','CA001')")








卡住問題: 資料欄位中文編碼
解決方法:資料庫欄位改編碼

https://dev.mysql.com/doc/refman/5.7/en/charset-conversion.html

https://dev.mysql.com/doc/refman/5.7/en/charset-applications.html

MySQL version 5.7

<span class="s1">ALTER TABLE tablename MODIFY column VARCHAR(64) CHARACTER SET utf8;</span>
<span class="s1">mysql> SET NAMES 'utf8';</span>

 


用兩種方法上傳(寫到7點)

https://www.pythonsheets.com/notes/python-sqlalchemy.html

http://flask-sqlalchemy.pocoo.org/2.3/models/

https://blog.techbridge.cc/2017/08/12/python-web-flask101-tutorial-sqlalchemy-orm-database-models/

http://docs.sqlalchemy.org/en/latest/orm/extensions/declarative/table_config.html

http://flask.pocoo.org/

http://www.itfanr.cc/2017/01/06/use-sqlalchemy-by-python/

回家作業:

  1. Review兩個上傳資料庫的方法

  2. 研究Flask

  3. 熟能生巧

  4. 懂得原理

成就達成: Flask+Pymysql / Flask + SQLAlchemy

(還不熟,需重複練習)