發表文章

目前顯示的是 1月, 2015的文章

Insert data to a mysql server from python ON PC with windows

圖片
after installing mysql server and client(python connector) on my beaglebone, I learn to insert data from python in to mysql server. All these are done on windows PC. most data are found in  http://www.mysqltutorial.org/python-mysql/ Here is a example on how to connect to a data base from python: import mysql.connector from mysql.connector import Error def connect():     """ Connect to MySQL database """     try:         conn = mysql.connector.connect(host='localhost',                                        database='iot',                                        user='root',                                        password='')         if conn.is_connected():             print('Connected to MySQL database')                       except Error as e:         print(e)     finally:         conn.close()         print('Disconnected from MySQL database') connect() To insert or query from

Installation of Python MySQL client on beaglebone angustrom

Referring to http://www.hkcode.com/programming/417 http://sourceforge.net/projects/mysql-python/ http://dev.mysql.com/doc/connector-python/en/connector-python-installation.html There are several connectors for different platform, win32, win64, debian, ubuntu...etc, each has file in 2 compression formats.ZIP or tar. My beaglebone is on angustrom, no worry, there is a platform independent option down load the tar file, and transfer to beaglebone with SCP, then un tar it, using python setup.py install to install it. shell> tar xzf mysql-connector-python- VER .tar.gz shell> cd mysql-connector-python- VER shell> sudo python setup.py install  installation complete with out error, but  in python: import mysql   no error import mysql.connector failed with lot of error Traceback (most recent call last):   File "dates.py", line 38, in <module>     import mysql.connector   File "/usr/lib/python2.7/site-packages/mysql/connector/__init__.py&qu

Few basic operation mysql after installation...

圖片
After installing mysql server and python client connector, I need to know how to set up a data base and read write it, I don't need something super fancy, just simply usable for adding rolls and readable for others. http://www.mysqltutorial.org/   is a site seems nice to me to read...there is a basic tutorial Manage Database in MySQL Under windows mysql server, the is a MySQL command line client, open it, it would ask for the password, which is what we have entered during installation. Once entered, try SHOW DATABASES ; it would list out what are the databases available. capital or not is not an issue, but always end with ; we can use 1 CREATE DATABASE [ IF NOT EXISTS ] database_name ; to create data base,and use show to see it. as linux system, we can use up arrow to find previous used commands. No matter you use capital letter for database name or not, it will always in 小寫 Tell mysql which database to be used: 1 U