I've done this via some php:
<?php
// load in mysql server configuration
include 'mysqlConfig.php';
// connect to the database
$pdo = new PDO($dsn, $username, $password);
// make an empty array in which to put the data
$rows = array();
// prepare a query for the year passed in via POST
$stmt = $pdo->prepare('SELECT * FROM table WHERE year='.$_GET['year'].';');
// query the database
$stmt->execute(array('year'));
// return the results in json format
echo json_encode($rows);
Then I just use d3.json() to retrieve it, e.g.:
data = {};
d3.json('data_by_year?year=' + year, function(json) {
data[year] = json;
update_visualization();
});
It works great when you have hundreds of millions of datapoints and only need to display a few thousand at any given time.