mysql+mysqlconnector

MySQL

[7] MySQL は、データベースです。

MySQL over TLS

[2] TLS が有効かどうかは SHOW STATUS LIKE "Ssl_cipher" で確認できます。 適当な cipher が返ってきたら、 TLS が有効です。

[3] mysql コマンドほかいくつかのクライアントライブラリーTLS が指定されていてもそれが適用されなかった場合にも、これをエラーとしないので、 注意が必要です。

[33] mysql クライアントから ClearDB サーバーに接続するには

$ mysql --user=XXX --password=XXX --host=XXX XXX --ssl-ca=cleardb-ca.pem --ssl-cert=XXX-cert.pem --ssl-key=XXX-key.pem

最初の4つのXXXは Heroku の設定変数として設定されている CLEARDB_DATABASE_URL の値から採る。最後の3つのファイルは Heroku の設定ページから ClearDB のページに行き、ダウンロードする (ログイン必要なのでブラウザで保存する)。

秘密鍵のエラーが出る時は (OpenSSL のバージョンの問題らしい)、

$ openssl rsa -in XXX-key.pem -out XXX-key-pkcs1.pem
... として作られたファイルを指定すれば良い。

本当に SSL で接続できたかは

SHOW STATUS LIKE 'Ssl_cipher';
... で値が空文字列になっていないかどうかで確認できる。

[34] Perl の DBI で接続する時は

DBI:mysql:database=%s;host=%s;user=%s;password=%s;mysql_ssl=1;mysql_ssl_ca_file=%s;mysql_ssl_client_cert=%s;mysql_ssl_client_key=%s
... のような dsn で同じ要領で接続できる。ただし DBD::mysql は標準では SSL 無効でコンパイルされる。その場合 mysql_ssl* は無視されるので注意しないといけない。無視されるがエラーにならずに平文で接続できてしまう。

DBD::mysql インストール時の Makefile.PL でオプション --ssl をつけると SSL 付きでコンパイルされる。 cpanm でインストールするなら --configure-args=--ssl をつければ良い。 pmbp.pl を使うなら今日の版以降は標準で --ssl 付きでコンパイルされる。

SSL なしで接続できてしまうのは怖いが、 MySQL で SSL 固定にするには GRANT ほにゃららを実行するらしい。 ClearDB では GRANT を実行する権限がなさそう (未確認)。

接続時に SHOW STATUS LIKE 'Ssl_cipher' して確認する実装にしておかないと怖い。

[35] AnyEvent::MySQL は SSL に対応していない。

Docker 版

[30] mysql/mysql-server - Docker Hub ( 版) https://hub.docker.com/r/mysql/mysql-server/

[4] Dockerの公式MySQLイメージの使い方を徹底的に解説するよ · DQNEO起業日記 ( ()) http://dqn.sakusakutto.jp/2015/10/docker_mysqld_tutorial.html

[6] () https://hub.docker.com/_/mysql/

[31] なぜかサーバーが起動せず、 docker logs を見ても特にエラーも無いときは、 docker-d を付けずに実行すると、エラーが出ていることがあります。

[32] 環境変数の組み合わせが間違っているとかで、わりと簡単に >>31 のような状況になるようです。

[36] CircleCI で実行すると mbind: Invalid argument というエラーが出まくるようですが、これ自体は無視して構わず、そのまま起動するなら問題ないようです。

mysql: URL scheme

[8] Extended indexing features http://www.dataparksearch.org/dpsearch-extended-indexing.en.html#htdb ()

[9] >>8
mysql://foo:bar@localhost/search/?dbmode=single

[10] Engine Configuration — SQLAlchemy 0.7 Documentation ( ( 版)) http://docs.sqlalchemy.org/en/rel_0_7/core/engines.html#database-urls

[11] felixge/node-mysql · GitHub ( 版) https://github.com/felixge/node-mysql

[12] mysqld の既定のポート番号3306

[13] Mojo::MySQL5::URL - search.cpan.org ( 版) http://search.cpan.org/dist/Mojo-MySQL5/lib/Mojo/MySQL5/URL.pm
  my $url = Mojo::MySQL5::URL->new('mysql://sri:foo@server:3306/test?foo=bar');

[5] 他にも色々バリエーションがあるようです。

MySQL プロトコル

caching_sha2_password

[45] MySQL :: MySQL 8.0.4 : New Default Authentication Plugin : caching_sha2_password, https://dev.mysql.com/blog-archive/mysql-8-0-4-new-default-authentication-plugin-caching_sha2_password/

[50] MySQL :: Preparing your Community Connector for MySQL 8 – part 2 – SHA256, https://dev.mysql.com/blog-archive/preparing-your-community-connector-for-mysql-8-part-2-sha256/

[46] MySQL: Caching_sha2_password information, https://dev.mysql.com/doc/dev/mysql-server/latest/page_caching_sha2_authentication_exchanges.html

[47] caching_sha2_passwordの仕様の話 - amamanamam, https://amamanamam.hatenablog.com/entry/2023/11/20/215121

[48] MySQL: Protocol::HandshakeResponse:, https://dev.mysql.com/doc/dev/mysql-server/latest/page_protocol_connection_phase_packets_protocol_handshake_response.html

[49] ひたすら面倒になっただけに見えるんだが... これ意味あるのかなあ?

SQL

[41] GIS 系の SQL 関数の古いもの (非推奨になっていたもの) は MySQL 8 で廃止されて削除されて使えなくなってしまったようです。

[42] だいたいは先頭に ST_ をつければいいのですが、 GLengthST_Length になるなど注意が必要なものもあります。

[43] こういう非互換変更、やめてほしいですね。

メモ

[14] MySQL :: MySQL Connector/J 5.1 Developer Guide :: 5.1 Driver/Datasource Class Names, URL Syntax and Configuration Properties for Connector/J () https://dev.mysql.com/doc/connector-j/5.1/en/connector-j-reference-configuration-properties.html

The general format for a JDBC URL for connecting to a MySQL server is as follows, with items in square brackets ([ ]) being optional:

jdbc:mysql://[host1][:port1][,[host2][:port2]]...[/[database]] »

[?propertyName1=propertyValue1[&propertyName2=propertyValue2]...]

Here is a simple example for a connection URL:

jdbc:mysql://localhost:3306/sakila?profileSQL=true

[15] MySQL :: MySQL Connector/J 5.1 Developer Guide :: 5.1 Driver/Datasource Class Names, URL Syntax and Configuration Properties for Connector/J () https://dev.mysql.com/doc/connector-j/5.1/en/connector-j-reference-configuration-properties.html

The following is an alternate format for JDBC URLs connecting to a MySQL server, which is mandatory for IPv6 connections, but can also be used with IPv4 (items in square brackets ([ ]) are optional):

jdbc:mysql://address=(key1=value)[(key2=value)]...[,address=(key3=value)[(key4=value)]...]...[/[database]]»

[?propertyName1=propertyValue1[&propertyName2=propertyValue2]...]

Supported key-value pairs include:

(protocol=tcp), or (protocol=pipe) for named pipes on Windows.

(path=path_to_pipe) for path of named pipes. Default value for the path is \\.\pipe\MySQL. Use the key-value pair to specify a custom named pipe.

(host=hostname) for TCP connections.

(port=port_number) for TCP connections.

For example:

jdbc:mysql://address=(protocol=tcp)(host=localhost)(port=3306)/db

[16] mysqljs/mysql: A pure node.js JavaScript Client implementing the MySql protocol. () https://github.com/mysqljs/mysql

In addition to passing these options as an object, you can also use a url string. For example:

var connection = mysql.createConnection('mysql://user:pass@host/db?debug=true&charset=BIG5_CHINESE_CI&timezone=-0700');

Note: The query values are first attempted to be parsed as JSON, and if that fails assumed to be plaintext strings.

[17] mysql/ConnectionConfig.js at master · mysqljs/mysql () https://github.com/mysqljs/mysql/blob/master/lib/ConnectionConfig.js

if (url.query) {

for (var key in url.query) {

var value = url.query[key];

try {

// Try to parse this as a JSON expression first

options[key] = JSON.parse(value);

} catch (err) {

// Otherwise assume it is a plain string

options[key] = value;

}

}

}

[18] Engine Configuration — SQLAlchemy 0.9 Documentation () http://docs.sqlalchemy.org/en/rel_0_9/core/engines.html#database-urls

# default

engine = create_engine('mysql://scott:tiger@localhost/foo')

# mysql-python

engine = create_engine('mysql+mysqldb://scott:tiger@localhost/foo')

# MySQL-connector-python

engine = create_engine('mysql+mysqlconnector://scott:tiger@localhost/foo')

# OurSQL

engine = create_engine('mysql+oursql://scott:tiger@localhost/foo')

[19] MySQL — SQLAlchemy 0.9 Documentation () http://docs.sqlalchemy.org/en/rel_0_9/dialects/mysql.html

mysql+mysqldb://<user>:<password>@<host>[:<port>]/<dbname>

mysql+mysqldb://root@/<dbname>?unix_socket=/cloudsql/<projectid>:<instancename>

mysql+pymysql://<username>:<password>@<host>/<dbname>[?<options>]

mysql+mysqlconnector://<user>:<password>@<host>[:<port>]/<dbname>

mysql+cymysql://<username>:<password>@<host>/<dbname>[?<options>]

mysql+oursql://<user>:<password>@<host>[:<port>]/<dbname>

mysql+mysqldb://root@/<dbname>?unix_socket=/cloudsql/<projectid>:<instancename>

mysql+gaerdbms:///<dbname>?instance=<instancename>

mysql+pyodbc://<username>:<password>@<dsnname>

mysql+zxjdbc://<user>:<password>@<hostname>[:<port>]/<database>

[20] ClearDB MySQL | Heroku Dev Center () https://devcenter.heroku.com/articles/cleardb

You can retrieve your new ClearDB database URL by issuing the following command:

$ heroku config | grep CLEARDB_DATABASE_URL

CLEARDB_DATABASE_URL => mysql://adffdadf2341:adf4234@us-cdbr-east.cleardb.com/heroku_db?reconnect=true

To set your DATABASE_URL to the value of CLEARDB_DATABASE_URL, simply issue the following heroku command. For example:

If you’re using the mysql2 gem, you will need to change the mysql:// scheme in the CLEARDB_DATABASE_URL to mysql2://

[21] ClearDB MySQL | Heroku Dev Center () https://devcenter.heroku.com/articles/cleardb

To instantiate a JDBC connection in your code, you can use a method like this:

private static Connection getConnection() throws URISyntaxException, SQLException {

URI dbUri = new URI(System.getenv("CLEARDB_DATABASE_URL"));

String username = dbUri.getUserInfo().split(":")[0];

String password = dbUri.getUserInfo().split(":")[1];

String dbUrl = "jdbc:mysql://" + dbUri.getHost() + dbUri.getPath();

return DriverManager.getConnection(dbUrl, username, password);

}

[22] kennethreitz/dj-database-url ( 版) https://github.com/kennethreitz/dj-database-url

MySQL (GIS) django.contrib.gis.db.backends.mysql mysqlgis://USER:PASSWORD@HOST:PORT/NAME

[23] julianwachholz/dj-config-url: Use 12factor inspired URLs to configure your Django Application. () https://github.com/julianwachholz/dj-config-url

MySQL django.db.backends.mysql mysql://USER:PASSWORD@HOST:PORT/NAME

MySQL (GIS) django.contrib.gis.db.backends.mysql mysqlgis://USER:PASSWORD@HOST:PORT/NAME

[24] prometheus/promdash: Prometheus Dashboard Builder () https://github.com/prometheus/promdash

DATABASE_URL="mysql2://username:password@host/database"

[25] java - JDBC MySQL connection using Unix Socket - Stack Overflow () http://stackoverflow.com/questions/25918416/jdbc-mysql-connection-using-unix-socket

If you want to use UNIX sockets with the Mysql JDBC Connector/J you need to provide a socketFactory.

jdbc:mysql:///?user=test&password=test&socketFactory=<classname>&<socket>=/tmp/mysql.sock

So this will vary with the implementation you use. By default, Mysql does not ship with any implementation for that, just provides an example for such a factory in it's source-code.

[26] java - JDBC MySQL connection using Unix Socket - Stack Overflow () http://stackoverflow.com/questions/25918416/jdbc-mysql-connection-using-unix-socket

As another answer pointed out, it's possible (at least in Intellij IDE) to use socket connection for Mysql JDBC Connector/J (I am using version 5.1) without having to provide a socketFactory,

jdbc:mysql://localhost:3306/database_name?socket=/tmp/mysql.sock

[27] java - JDBC MySQL connection using Unix Socket - Stack Overflow () http://stackoverflow.com/questions/25918416/jdbc-mysql-connection-using-unix-socket

The JDBC Driver from the MariaDB project supports Unix domain sockets while remaining compatible with the MySQL Connector/J JDBC driver. Example jdbc url for the MariaDB driver is: jdbc:mariadb://localhost:3306/revmgt?localSocket=/var/run/mysqld/mysqld.sock

[28] Manual :: The Data Source Name () http://pear.php.net/manual/en/package.database.db.intro-dsn.php

mysql -> MySQL (for MySQL <= 4.0)

mysqli -> MySQL (for MySQL >= 4.1) (requires PHP 5) (since DB 1.6.3)

[29] The DB-URI — TurboGears 1.0 documentation () http://turbogears.org/1.0/docs/DbUri.html

To specify the socket file for MySQL, you need to use the unix_socket option:

mysql://localhost/database?unix_socket=/var/lib/mysql/socket

[37] Client/Server Protocol - MariaDB Knowledge Base () https://mariadb.com/kb/en/library/clientserver-protocol/

[38] library/mariadb - Docker Hub () https://hub.docker.com/_/mariadb/

[39] mysql - SQLSTATE[HY000]: General error: 1835 Malformed communication packet on LARAVEL - Stack Overflow () https://stackoverflow.com/questions/64677836/sqlstatehy000-general-error-1835-malformed-communication-packet-on-laravel

[40] [MDEV-24121] Recent MariaDB update appears to have introduced a DB connection issue for PHP < 7.3 (or anything using PDO) - Jira () https://jira.mariadb.org/browse/MDEV-24121

[44] MariaDB

Can't initialize timers