Let's use MemSQL Vol.14: Practice 7

Perform additional verification for Windows environment.

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. image.png

This time I will introduce Jupyter Notebook as an Anaconda environment ...

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.

a1.jpg Go to the download page a2.jpg 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.

Then! Install! !!

Launch the downloaded installer. a3.jpg Select ** Next> **. a4.jpg This time, I chose the form only for personal use. a5.jpg Is there any problem with the default installation directory? (This will be related to later pass-through) a6.jpg 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 ... ?!) a14.jpg Basically, the installation process goes on quietly, so please be patient. a15.jpg If you come here, you will have a rest. a10.jpg The installation is completed successfully. a11.jpg

Now, check the operation ...

First, let's write Python using a text editor ...

print("test")

Save it as test.py instead of test.txt. a12.jpg

It will call the installed environment. a16.jpg

Select Anaconda Prompt and try to fill it with the previous file.

> python

Enter and insert a space, then drag and drop the file. a18.jpg It started to move safely! !!

Finally encounter with Jupyter Notebook ...

As before, launch Anaconda Prompt,

> jupyter notebook

Enter. Jupyter Notebook has been successfully launched on Windows 10 environment! a20.jpg

Just in case ... Check the integration with MemSQL

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.

Introducing the promised module

First, install ** pymysql ** as before.

> pip install pymysql

I entered quickly. a21.jpg

Now, let's start the concrete cooperation work.

First read ...

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. image.png I was able to read it safely!

Next, write the database ...

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. image.png

… So, the rush verification @ Windows is over.

This summary

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.

Acknowledgments

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

Let's use MemSQL Vol.14: Practice 7
Let's use MemSQL Vol.13: Practice 6
Let's use pytube
Let's use def in python
Let's use python's wordcloud easily!
Let's use usercustomize.py instead of sitecustomize.py
Let's use tomotopy instead of gensim
[Introduction to Python] Let's use pandas
[Introduction to Python] Let's use pandas
[Introduction to Python] Let's use pandas