[Labs-l] new database server on bots

Petr Bena benapetr at gmail.com
Wed Mar 6 15:18:07 UTC 2013


Hi,

we created a new database server bots-bsql01

every user of bots project has account there and you can login there
just by doing

mysql -h bots-bsql01 from any bots server

in case you need to create a database there, execute:

call system.create_db("database_name");

with any db name which doesn't exist yet. This procedure create a new
database and grant you privileges for it. The source code of this
procedure, in case anyone wanted to use it in another project (I spent
half of a day making it) is



BEGIN
  DECLARE temp TEXT;
  DECLARE user TEXT;
  SELECT SCHEMA_NAME FROM INFORMATION_SCHEMA.SCHEMATA WHERE
SCHEMA_NAME = name INTO temp;
  if temp = name then
  SIGNAL SQLSTATE '45002' SET MESSAGE_TEXT = 'This database already exist';
    else
    SELECT SUBSTRING_INDEX(USER(),'@',1) INTO user;

    SET @s = CONCAT('CREATE DATABASE ', name);
    PREPARE stmt_create FROM @s;
    EXECUTE stmt_create;
    DEALLOCATE PREPARE stmt_create;

    SET @s = CONCAT('GRANT ALL PRIVILEGES ON ', name, '.* TO \'',
user, '\'@\'%\'  WITH GRANT OPTION');
    PREPARE stmt_grant FROM @s;
    EXECUTE stmt_grant;
    DEALLOCATE PREPARE stmt_grant;

  END IF;
END



More information about the Labs-l mailing list