Skip to content

Instantly share code, notes, and snippets.

@mguentner
Created April 15, 2016 16:34
Show Gist options
  • Save mguentner/1a0ec2ecf251e80f5f5887e7cebf5ade to your computer and use it in GitHub Desktop.
Save mguentner/1a0ec2ecf251e80f5f5887e7cebf5ade to your computer and use it in GitHub Desktop.
config / test environment for mysql nix issue / long_init_db.sql stolen from http://stackoverflow.com/questions/5125096/for-loop-example-in-mysql#5126655
# Edit this configuration file to define what should be installed on
# your system. Help is available in the configuration.nix(5) man page
# and in the NixOS manual (accessible by running ‘nixos-help’).
{ config, pkgs, ... }:
{
imports =
[ # Include the results of the hardware scan.
./hardware-configuration.nix
];
# Use the GRUB 2 boot loader.
boot.loader.grub.enable = true;
boot.loader.grub.version = 2;
# Define on which hard drive you want to install Grub.
boot.loader.grub.device = "/dev/sda";
networking.hostName = "testbed1"; # Define your hostname.
networking.wireless.enable = false; # Enables wireless support via wpa_supplicant.
networking.interfaces.enp0s3.ip4 = [ { address = "10.0.23.2"; prefixLength = 24; }];
networking.defaultGateway = "10.0.23.1";
networking.enableIPv6 = false;
networking.nameservers = ["8.8.8.8"];
networking.firewall.enable = false;
# Select internationalisation properties.
i18n = {
consoleFont = "Lat2-Terminus16";
consoleKeyMap = "us";
defaultLocale = "en_US.UTF-8";
};
users.extraUsers.admin = {
isNormalUser = true;
home = "/home/admin";
description = "Non-root admin";
extraGroups = [ "wheel" ];
};
# Set your time zone.
time.timeZone = "Europe/Berlin";
# List packages installed in system profile. To search by name, run:
# $ nix-env -qaP | grep wget
environment.systemPackages = with pkgs; [
wget
vim
];
# List services that you want to enable:
services.mysql = {
enable = true;
package = pkgs.mysql;
initialDatabases = [{name="testdb"; schema = "./schema.sql";}];
initialScript = "/etc/nixos/long_init_db.sql";
};
# Enable the OpenSSH daemon.
services.openssh.enable = true;
# The NixOS release to be compatible with for stateful data such as databases.
system.stateVersion = "16.03";
}
use testdb;
drop table if exists foo;
create table foo
(
id int unsigned not null auto_increment primary key,
val smallint unsigned not null default 0
)
engine=innodb;
drop procedure if exists load_foo_test_data;
delimiter #
create procedure load_foo_test_data()
begin
declare v_max int unsigned default 10000000000;
declare v_counter int unsigned default 0;
truncate table foo;
start transaction;
while v_counter < v_max do
insert into foo (val) values ( floor(0 + (rand() * 65535)) );
set v_counter=v_counter+1;
end while;
commit;
end #
delimiter ;
call load_foo_test_data();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment