---
title: "MariaDB Connector/Python 0.9.52 Alpha リリース"
publish_date: 2020-01-14
updated_date: 2023-10-12
author: "MariaDB"
tags:
  - name: "Connector"
    url: "/ja/resources/blog/tag/connector-ja.md"
  - name: "Python"
    url: "/ja/resources/blog/tag/python-ja.md"
---

# MariaDB Connector/Python 0.9.52 Alpha リリース

2019-12-18 に Python 用の MariaDB ドライバがリリースされました。

[MariaDB Connector/Python 0.9.52 Alpha リリースノート](https://staging-mdb.com/kb/en/mariadb-connector-python-0952-release-notes/)

これまでは MySQL Connector が流用されていましたが，[他のプログラミング言語](https://staging-mdb.com/docs/features/mariadb-connectors/#mariadb-connectors)と同様に MariaDB Corporation から正式に Connector が提供されることになります。

MariaDB Connector / Python は <https://staging-mdb.com/downloads/#connectors> からダウンロードできます。  
また，他 Python パッケージと同様に，pip を用いてインストールすることも可能です。

### GitHub レポジトリ

MariaDB Connector/Python の GitHub レポジトリはこちらになります。

<https://github.com/mariadb-corporation/mariadb-connector-python/>

#### ドキュメント

ドキュメントは以下の Wiki で参照可能となっています。

<https://github.com/mariadb-corporation/mariadb-connector-python/wiki>

#### ベンチマークテスト結果

以下に既存の MySQL Connector との速度比較テスト結果例が記載されています。かなり高速化されているようです。

<https://github.com/mariadb-corporation/mariadb-connector-python/tree/master/benchmarks>

### Python 3.7 でテスト実施

Windows 10 から リモートの MaraDB Community Server 10.4 に MariaDB Connector/Python を用いて接続し，データ取得を行ってみました。

#### サンプルデータのインポート

MaraDB Community Server 10.4 上で以下のコマンドを実行し，テストデータをインポートします。

```
git clone https://github.com/datacharmer/test_db.git
cd test_db
mariadb < employees.sql

```

(10.3以前のバージョンでは `mysql < employees.sql` でインポートできます)

#### MariaDB Connector/Python のインストール

今回は Windows 10 上の Python 3.7 実行環境に pip で MariaDB Connector/Python をインストールしました。

```
(base) C:\Users\maria>pip install --pre mariadb
Collecting mariadb
  Using cached https://files.pythonhosted.org/packages/cf/d7/bd6560cf0353ab40cb5bd9e0ddc6c8e2ab6627aa6d75066718853901aaaf/mariadb-0.9.52-cp37-cp37m-win_amd64.whl
Installing collected packages: mariadb
Successfully installed mariadb-0.9.52

```

#### サンプルコード

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

```
# test_connector.py
import mariadb

connection = mariadb.connect(
  user = 'mariadb_user',
  password = 'password',
  database = 'employees',
  host = '192.168.xxx.xxx'
)

cursor = connection.cursor()
query = '''SELECT hire_date, first_name, last_name 
           FROM employees 
           WHERE hire_date > '2000-01-01' 
           ORDER BY hire_date'''
cursor.execute(query)
for hire_date, first_name, last_name in cursor:
  print(hire_date, first_name, last_name)

```

実行結果は以下のとおりでした。

```
> python test_connector.py
2000-01-02 Seshu Rathonyi
2000-01-02 Randi Luit
2000-01-03 Jeong Boreale
2000-01-04 Xuejun Benzmuller
2000-01-06 Ennio Alblas
2000-01-08 Shahab Demeyer
2000-01-11 Jaana Verspoor
2000-01-12 Ulf Flexer
2000-01-13 Volkmar Perko
2000-01-22 Hideyuki Delgrande
2000-01-23 Yucai Gerlach
2000-01-28 Bikash Covnot

```

### まとめ

Connector/Python は現時点では Alpha 版ですので，production 環境では利用しないよう留意願います。またライセンスは他言語用の Connector と同様に [LGPL 2.1](https://github.com/mariadb-corporation/mariadb-connector-python/blob/master/LICENSE)でライセンスされています。