MySQL

Dynamic SQL , conditional where

   1 SELECT first_name, last_name, subsidiary_id, employee_id
   2   FROM employees
   3  WHERE ( subsidiary_id    = :sub_id OR :sub_id IS NULL )
   4    AND ( employee_id      = :emp_id OR :emp_id IS NULL )
   5    AND ( UPPER(last_name) = :name   OR :name   IS NULL )
   6 
   7 
   8 select * from mysql.user
   9 where (user=NULL or NULL is null) 
  10 and (host=NULL or NULL is null)
  11 
  12 select * from mysql.user
  13 where (user='root' or 'root' is null) 
  14 and (host=NULL or NULL is null)
  15 
  16 select * from mysql.user
  17 where (user='root' or 'root' is null) 
  18 and (host='127.0.0.1' or '127.0.0.1' is null)

MySql workbench Slackware64 14.1

mysqldump

Error MariaDB 5.5 mysqldump

Use /tmp/msd -h hostx -u userx -ppassx dbname > /tmp/dump.sql

Show users

   1 select host,user,password from mysql.user;

Create function

   1 DELIMITER $$
   2 DROP FUNCTION IF EXISTS hello;
   3 CREATE FUNCTION hello() RETURNS TEXT LANGUAGE SQL
   4 BEGIN
   5   RETURN 'Hello';
   6 END;
   7 $$
   8 DELIMITER ;
   9 -- test function
  10 select hello();

User creation and grants to select and execute function

   1 create user 'userx'@'%' identified by 'passwordx';
   2 grant select on dbx.tablex to 'userx'@'%';
   3 grant execute on function dbx.hello to 'userx'@'%';

Most used commands

   1 show databases;
   2 use mysql; -- select database
   3 show tables;
   4 desc user; -- describe table user
   5 set sql_mode=ansi; -- set sql mode to ansi
   6 show create table user; -- show DDL to create table user
   7 show grants; -- show grants for current user
   8 

MySQL (last edited 2014-10-22 21:19:19 by 73)