import os import subprocess cmdline = ['mysql -u"username" -p"password" < query.sql'] p = subprocess.Popen(cmdline,stdout=subprocess.PIPE) stdout,stderr = p.communicate() retcode = p.wait()
So that my code connects to mysql and runs query.sql. It looks good, but it does not work, and the bad thing is that I do not receive an error at all. retcode is 1 and from stdout, stderr I get only the standard mysql text "Using mysql [OPTIONS] [Database] ...", so I thought my syntax was wrong. But this is not so. I tested a line of code in a terminal and it works.
Does python have a problem to execute this through a subprocess? I just want an easy way to execute this little mysql code. Thank.
cmdline = ['mysql -u"username" -p"password" < query.sql']
Popen. , , , . cmdline = ["mysql", "-u", username, "-p", password]. , , "< query.sql". stdin = PIPE, SQL, p.communicate(sqlQuery).
Popen
cmdline = ["mysql", "-u", username, "-p", password]
stdin = PIPE
p.communicate(sqlQuery)
retcode = p.wait()
.communicate(), p.returncode.
.communicate()
p.returncode
, MySQL python, DBAPI . python wiki , ORM, SQLAlchemy
mySQL
Source: https://habr.com/ru/post/1791660/More articles:Get Unicode character by glyph index in CTFontRef or CGFontRef - objective-cUsing PHP as a template engine - phpProcess.Start vs Process `p = new Process ()` in C #? - c #Is there a Google Closure compiler plugin for Notepad ++ - javascriptMimic batch file with C # - c #Static asset caching on Heroku with Jammit by modifying ActionController :: Base # page_cache_directory - ruby-on-railshttps://translate.googleusercontent.com/translate_c?depth=1&pto=aue&rurl=translate.google.com&sl=ru&sp=nmt4&tl=en&u=https://fooobar.com/questions/1791662/how-to-convert-silverlight-projects-or-controls-to-wpf&usg=ALkJrhgEB2dlGlCIkrHVhJcCYGo7rAVjeASharing your homepage and content on an asp.net page - asp.netregular expression to extract data from html page - linuxUsing the IF construct in Hibernate - javaAll Articles