<div><h3id="mysql">MySQL</h3><p><strong>Has a very similar interface, with differences listed below.</strong></p><pre><codeclass="python language-python hljs"><spanclass="hljs-comment"># $ pip3 install mysql-connector</span>
<spanclass="hljs-keyword">from</span> mysql <spanclass="hljs-keyword">import</span> connector
<cursor> = <conn>.cursor() <spanclass="hljs-comment"># Only cursor has execute() method.</span>
<cursor>.execute(<spanclass="hljs-string">'<query>'</span>) <spanclass="hljs-comment"># Can raise a subclass of connector.Error.</span>
<cursor>.execute(<spanclass="hljs-string">'<query>'</span>, <list/tuple>) <spanclass="hljs-comment"># Replaces '%s's in query with values.</span>
<cursor>.execute(<spanclass="hljs-string">'<query>'</span>, <dict/namedtuple>) <spanclass="hljs-comment"># Replaces '%(<key>)s's with values.</span>
<div><h2id="bytes"><ahref="#bytes"name="bytes">#</a>Bytes</h2><p><strong>Bytes object is an immutable sequence of single bytes. Mutable version is called bytearray.</strong></p><pre><codeclass="python language-python hljs"><bytes> = <spanclass="hljs-string">b'<str>'</span><spanclass="hljs-comment"># Only accepts ASCII characters and \x00-\xff.</span>
<int> = <bytes>[<index>] <spanclass="hljs-comment"># Returns an int in range from 0 to 255.</span>
<bytes> = <bytes>[<slice>] <spanclass="hljs-comment"># Returns bytes even if it has only one element.</span>