NI-Lab.

nilog:

← 前の日 2022-02-14 次の日 →
← 一年前 一年後 →
Twitter (2022-02-14)
いままで使っていたのが mariadb パッケージ。

mariadb · PyPI https://pypi.org/project/mariadb/
[t] 2022-02-14 18:00:33
関連するかも情報
MariaDB から MySQL に変えたから、Python で使うライブラリもちゃんと MySQL 用のに変えよう・・・
[t] 2022-02-14 17:58:16
いままで使っていたのが mariadb パッケージ。

mariadb · PyPI https://pypi.org/project/mariadb/
[t] 2022-02-14 18:00:33
使ってるメソッドはこれぐらいかな。

Cursor.execute(statement: str, data: Sequence = (), buffered=False)

Cursor.fetchall()

The cursor class — MariaDB Connector/Python 1.1.0b3-beta documentation https://mariadb-corporation.github.io/mariadb-connector-python/cursor.html
[t] 2022-02-14 18:11:24
"using an API which is compliant with the Python DB API 2.0 (PEP-249). It is written in C and uses MariaDB Connector/C client library for client server communication."

GitHub - mariadb-corporation/mariadb-connector-python: MariaDB Connector/Python https://github.com/mariadb-corporation/mariadb-connector-python
[t] 2022-02-14 18:18:22
mysqlclient パッケージが mariadb とインターフェース似てるっぽいからこれでいいかな。

mysqlclient Python3でMySQLに接続する | Python学習講座 https://www.python.ambitious-engineer.com/archives/818
[t] 2022-02-14 18:18:49
Ubuntu で先に default-libmysqlclient-dev をインストールしていないとエラーになってしまう。

$ sudo apt install default-libmysqlclient-dev
$ pip3 install mysqlclient
[t] 2022-02-14 18:23:04
このへんのパッケージが必要。

「$ sudo apt-get install python3-dev default-libmysqlclient-dev build-essential # Debian / Ubuntu」

mysqlclient · PyPI https://pypi.org/project/mysqlclient/
[t] 2022-02-14 18:24:54
mysqlclient は import MySQLdb で使える。
[t] 2022-02-14 18:26:43
あ、インターフェースがちがうっぽいな・・・

TypeError: cursor() got an unexpected keyword argument 'named_tuple'
[t] 2022-02-14 18:31:14
mariadb パッケージと互換性があるのは mysql-connector-python パッケージかな。

「cursor = cnx.cursor(named_tuple=True)」

MySQL :: MySQL Connector/Python Developer Guide :: 10.5 cursor.MySQLCursor Class https://dev.mysql.com/doc/connector-python/en/connector-python-api-mysqlcursor.html
[t] 2022-02-14 18:35:38
"MySQL driver written in Python which does not depend on MySQL C client libraries and implements the DB API v2.0 specification (PEP-249)."

mysql-connector-python · PyPI https://pypi.org/project/mysql-connector-python/
[t] 2022-02-14 18:36:03
pip でインストールできるかな。

"pip install mysql-connector-python"

MySQL :: MySQL Connector/Python Developer Guide :: 4.2 Installing Connector/Python from a Binary Distribution https://dev.mysql.com/doc/connector-python/en/connector-python-installation-binary.html
[t] 2022-02-14 18:37:13
Ubuntu で MySQL Connector/Python をインストール。

$ pip3 install mysql-connector-python

インストールできた。

Successfully installed mysql-connector-python-8.0.28 protobuf-3.19.4
[t] 2022-02-14 18:38:39
mysql-connector-python は import mysql.connector で使える。

MySQL :: MySQL Connector/Python Developer Guide :: 5.1 Connecting to MySQL Using Connector/Python https://dev.mysql.com/doc/connector-python/en/connector-python-example-connecting.html
[t] 2022-02-14 18:39:52
mariadb パッケージと mysql-connector-python パッケージは同じインターフェースっぽい。

「使用方法は既存の MySQL Connector と同様です」

MariaDB Connector/Python 0.9.52 Alpha リリース https://mariadb.com/ja/resources/blog/mariadb-connector-python/
[t] 2022-02-14 18:41:55
処理がやけに重いのとエラー(;´Д`)

mysql.connector.errors.ProgrammingError: Not all parameters were used in the SQL statement
[t] 2022-02-14 18:51:41
MariaDB のときはクエリに「?」を入れていたけど MySQL の場合は「%s」っぽい。

"Specify variables using %s or %(name)s parameter style"

MySQL :: MySQL Connector/Python Developer Guide :: 10.5.4 MySQLCursor.execute() Method https://dev.mysql.com/doc/connector-python/en/connector-python-api-mysqlcursor-execute.html
[t] 2022-02-14 19:00:16
やっと動いたけど、処理がすごく遅い・・・
[t] 2022-02-14 19:08:57
ちょっと計測してみた感じだとクエリが重いっぽい。
[t] 2022-02-14 19:40:24
「美唄焼鳥の店ではシメにもつそばと言ってかけそばの上に美唄焼鳥をほぐして乗せて食べます」

美唄焼鳥のシメのそばの作り方 レシピ・作り方 by ゆみたろう~目指せ細マッチョ❣️|楽天レシピ https://recipe.rakuten.co.jp/recipe/1110022421/
[t] 2022-02-14 19:41:56
2022年02年14日のnilogをすべて表示する

- NI-Lab.
- Mastodon (@nilab@mastodon-japan.net)
- Twitter (@nilab)
- Timelog (@nilab)
- はてなブックマーク (id:nilab)

Web Services by Yahoo! JAPAN