Last time, we verified the cooperation between Jupyter Notebook and MemSQL in Mac environment, but this time we would like to change the environment a little and carry out additional verification using Windows environment and remote MemSQL.
Last time, we took various steps to build the environment, but in this verification, we will simply use the latest version of Anaconda to prepare the related environment.
First, go to ** Anaconda Home Page ** and download the required modules.
Go to the download page At the time of writing, the version of Python 3.7 was released, so download the 64-bit version of Anaconda to match the 64-bit version of Windows 10.
Launch the downloaded installer. Select ** Next> **. This time, I chose the form only for personal use. Is there any problem with the default installation directory? (This will be related to later pass-through) The point of this time is this screen. Not recommended in red! However, if you continue without doing this, you will need to manually set the PATH environment variable, so this time with courage (bitter smile), check this item. I installed it (Hitobashira ... ?!) Basically, the installation process goes on quietly, so please be patient. If you come here, you will have a rest. The installation is completed successfully.
First, let's write Python using a text editor ...
print("test")
Save it as test.py instead of test.txt.
It will call the installed environment.
Select Anaconda Prompt and try to fill it with the previous file.
> python
Enter and insert a space, then drag and drop the file. It started to move safely! !!
As before, launch Anaconda Prompt,
> jupyter notebook
Enter. Jupyter Notebook has been successfully launched on Windows 10 environment!
At this point, it will basically be the Python world of Jupyter Notebook, so I would like to perform read / write cooperation verification to MemSQL using the same procedure as last time.
First, install ** pymysql ** as before.
> pip install pymysql
I entered quickly.
Now, let's start the concrete cooperation work.
import pymysql
db = pymysql.connect (host ='xxx.xxx.xxx.xxx', # IP address given to MemSQL on the net
user='root',
password='',
db='r_db',
charset='utf8',
cursorclass=pymysql.cursors.DictCursor)
db.commit()
with db:
cur=db.cursor()
cur.execute("SELECT * FROM r_table03")
rows=cur.fetchall()
for row in rows:
print (row)
This time, the database and table created in the previous verification are read as they are. I was able to read it safely!
import pymysql
db = pymysql.connect (host ='xxx.xxx.xxx.xxx', # IP address given to MemSQL on the net
user='root',
password='',
db='r_db',
charset='utf8',
cursorclass=pymysql.cursors.DictCursor)
db.commit()
with db:
cur=db.cursor()
cur.execute("CREATE TABLE IF NOT EXISTS pw_test(test_id INT AUTO_INCREMENT PRIMARY KEY, data VARCHAR(25))")
cur.execute("INSERT INTO pw_test(data) VALUES('aaaaaaa')")
cur.execute("INSERT INTO pw_test(data) VALUES('bbbbbbb')")
cur.execute("INSERT INTO pw_test(data) VALUES('ccccccc')")
I will check if I was able to write it safely.
with db:
cur=db.cursor()
cur.execute("SELECT * FROM pw_test")
rows=cur.fetchall()
for row in rows:
print (row)
It fits nicely in the database.
… So, the rush verification @ Windows is over.
This time, continuing from the previous time, I tried to verify the cooperation between Jupyter Notebook and MemSQL in Windows 10 + remote MemSQL environment. With this mechanism, once the required environment starts to work, you will be able to operate MySQL while pretending to be MySQL via ** pymysql **, so I hope that all Windows enthusiasts can try MemSQL. I think.
In addition, as a plan for the next time and later, using the file system pipeline of MemSQL introduced in the previous time, we will accumulate basic data on MemSQL while regularly fetching data, and R I would like to challenge the scenario of writing the result to MemSQL again while operating with Jupyter Notebook and finally visualizing it with Zoomdata.
The screenshots reprinted in this commentary use the images of the official homepage currently published by MemSQL, except for some, and are published on this content and the official homepage of MemSQL. Please understand that if the contents are different, the information of MemSQL will take precedence.
Recommended Posts