MongoDB, MySQL

Source: Internet
Author: User
Tags install mongodb mongoclient

Install mongodb:www.mongodb.com/download-center#community download. msi installation package → Customize the installation of the path to the first letter C to D, and other such as server\3.x and so on do not change → manually create two directories (log D : \program Files\mongodb\log\mongodb.log; Data D:\Program files\mongodb\data) →d:\program files\mongodb\server\3.4\ Under Bin Press shift+ right-click to enter the command Window →Mongod--logpath "D:\Program files\mongodb\log\mongodb.log"--dbpath "D:\Program files\mongodb\data" --install--servicename "MongoDB" (UninstallbeforeRemoval is--remove) →netStartMongoDB (Close is stop) → Browser open http://localhost:27017 (Error--install Add a--storageengine=mmapv1 at the end of the sentence) CMD directly with MONGO: Put this string into the system environment Path:d:\program Files\mongodb\server\3.4\bin; ***** ************** Split Line ************** *****Pycharm installed MONGO plugin plug-in, right side MONGO Explorer point open is blank: Settings button → +→lable random →ok; When you open the datasheet, click the View as Table button in the upper-right corner to change the tree to a table-type ***** ************** Split Line ************** *****MongoDB Usage Example: (Crawling pepper Live) Import requests,refrom BS4 import beautifulsoupfrom pymongo import mongoclient def getliveid ( urlofanchors): Liveids=set () Response=requests.get (urlofanchors). Text Soup=beautifulsoup (response, ' lxml ') #正则元 After the character ^ (), the group (n) is no longer represented, and the start is a string of content for link in soup.find_all (' A ', Href=re.compile ('^(/l/)'):         href=link[' href ']         liveid=href.split ('/') [ -1]        liveids.add (LiveId)     return liveids def getUserId (liveId):     liveurl= '/http www.huajiao.com/l/{} '. Format (liveId)     response=requests.get (liveurl) .text     soup=beautifulsoup (response, ' lxml ')     title=soup.title.get_text ()      return re.findall (' \d+ ', title) [0] def Getuserdata (userId):     print (' Getting host information for ID: {} '. Format (userId) ')     response=requests.get (' http://www.huajiao.com/user/{} ' . Format (userId)). Text    soup=beautifulsoup (response, ' lxml ')      Userinfo=soup.find (' div ', id= ' userInfo ')     data={}    data[' userId ']= userid    data[' haEdphoto ']=userinfo.find (' div ', ' Avatar '). img[' src ']    tmp=userinfo.h3.get_text (' | ', strip= True). Split (' | ')     data[' userName ']=tmp[0]    data[' area ']=tmp[2]     tmp=userinfo.find (' ul ', ' Clearfix '). Get_text (' | ', Strip=true). Split (' | ')     data[' fans ']=tmp[0]    data[' Thumbsup ']=tmp[2]     data[' gift ']=tmp[4]    data[' expense ']=tmp[6]    return data  def Saveuserdata (userData):     client=mongoclient ()     database= client[' Pepper ']    #Mongodb中若无此数据库, then automatically create     table=database[' host info ']     table.save (UserData)     print (' host {} information saved successfully '. Format (userdata[' UserName '))   if __name__ = = ' __main__ ':     urlofanchors= ' http://www.huajiao.com/category/1000 '      liveids=getliveid (UrlofAnchors)     for liveId in liveids:        userid= GetUserId (liveId)         try:     #getUserId () Some liveurl open slowly and skip them             userdata=getuserdata (userId)             saveuserdata (userData)          except:             pass  open cmd, input + ENTER: Mongo;show databases;use pepper; show tables;db. Host information. count (); DB. Host information. FindOne () ; db. Host information. FIND () **************************************** Split Line ****************************************mysql5.7.19: Turn from: www.jb51.net/article/119369.htm?utm_source=debugrun&utm_medium=referral 1, Installation & configuration: ① download package to E : \mysql-5.7.19-winx64→ environment variableSystem VariablesNEW: Variable name mysql_home, variable value e:\mysql-5.7.19-winx64→path tail add ;%mysql_home%\bin→e:\mysql-5.7.19-winx64\binBuild a My.ini file (the old version does not need; The content is at the end of the text); ② Administrator, open cmd and cut to the bin directory (the following commands are executed in this directory): Mysqld.exe-install(Hint: Service successfully installed) → mysqld--initialize-insecure--user=mysql (Initialize root to create empty password); ③ net start MySQLmysqladmin-u root-p password New passwordEnter Password:(If the old password is empty then enter directly) → net stop MySQL(Uninstalling MySQL is mysqld--remove) 2, use: ①のcmd (not recommended): net start mysql→mysql-u root-p→enter password: new password (... Operation Example:mysql> show databases;or mysql> SELECT statement ...;) →mysql> quit;→net Stop MySQL method ②のnavicat:net start MySQL→ Open the software navicat→ connection → In addition to the password optional → connection test. If the inserted data contains the QQ expression, then the new database (or right-click Target Library selected database properties), the character set selected at the end of the UTF8MB4. View database information? field: Right-click Connection name or library name Select command Column interface →①show create database name; ②show create table table name; ③desc xs; Add User: User icon → new user → host name is localhost, password can be empty → save button; rights Manager → Select the connection name on the left or the next level of a library name → add permissions → left tick new user → Right click grant Select all Grant → OK. 3. Contents of My.ini: [client]port=3306default-character-set=utf8[mysqld]port=3306character_set_server=utf8basedir=% Mysql_home%datadir=%mysql_home%\data[winmysqladmin]%mysql_home%\bin\mysqld.exe ***** ************** Split Line ************** *****MySQL Usage example: Import MYSQLDB class Xiaoshuo:def __init__ (self): #连接个事先手动建的UTF8 Library, otherwise acting onFieldCharSet is invalid, the default encoding of the library overrides the #MySQLdb与django的DATABASES的不同 as a table: port value is not str; library name is not name; add CharSet Self.conn=mysqldb.connect (host= ' localhost ', port=3306,user= ' chengy ', PASSWorD= ', db= ' my_db ',charset= ' UTF8 ') #passworD or passwd,database or db can be self.cur=self.conn.cursor () # If you create a database with code, specify the database & table separately in your code, and the encoding of the field # Self.cur . Execute (' CREATE DATABASE IF not EXISTS my_dbdefault CharSet UTF8') # Self.conn. Set_character_set (' UTF8 ')#字段的编码: MySQLdb line, pymysql no such attribute # Self.conn. select_db(' my_db ') self.cur.execute (' CREATE table if not exists XS (author varchar (ten), title text) ' Def operatebase (self        ): Self.cur.execute (' INSERT into XS (author) values ("Xiaoming") ') Self.conn.commit () #self. Conn.rollback () # SQL statements in addition to set assignment, where equivalent judgment is also used for a =, not in Python = = Self.cur.execute (' select * from XS where author="Xiaoming" ') Print (Self.cur.fetchall ()) #fetchmany (5), Fetchone () print (Self.cur.rowcount) def closebase (sel f): Self.cur.close () Self.conn.close () Xs=xiaoshuo () xs.operatebase () xs.closebase ()

MongoDB, MySQL

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.