You are on page 1of 7

Quick help

last modified by Manuel Antonio Lazo Reyes

on 2023/08/15 16:12
Quick help

Table of Contents
Maria DB quick reference guida ........................................................................................................................................... 3
Functions and operators ..................................................................................................................................................... 3
Maria DB commands ............................................................................................................................................................. 4
Show session and global variables ................................................................................................................................... 4
Show tables and views ....................................................................................................................................................... 4
Show tables and columns ................................................................................................................................................... 5
Show tables and records .................................................................................................................................................... 5
Show store procedures and functions ............................................................................................................................... 5
Strict mode ............................................................................................................................................................................ 5
Foreign key check ................................................................................................................................................................ 5
SQL Server commands ......................................................................................................................................................... 6
List functions and store procedures .................................................................................................................................. 6
List tables, views and rows ................................................................................................................................................ 6
Linux commands ..................................................................................................................................................................... 7
Update Ubuntu Server ........................................................................................................................................................ 7
Create user name ................................................................................................................................................................ 7
Add user to sudo group ...................................................................................................................................................... 7
Switch to user ....................................................................................................................................................................... 7
Change password ................................................................................................................................................................ 7

Page 2 / 7 - last modified by Manuel Antonio Lazo Reyes on 2023/08/15 16:12


Quick help

• Maria DB quick reference guida


• Functions and operators
• Maria DB commands
• Show session and global variables
• Show tables and views
• Show tables and columns
• Show tables and records
• Show store procedures and functions
• Strict mode
• Foreign key check
• SQL Server commands
• List functions and store procedures
• List tables, views and rows
• Linux commands
• Update Ubuntu Server
• Create user name
• Add user to sudo group
• Switch to user
• Change password

Maria DB quick reference guida


Functions and operators
Summary:

Name Description
 
+ Addition operator
/ Division operator
* Multiplication operator
% Modulo operator. Returns the remainder of N divided by M
- Subtraction operator
= Not equals
< Less than
<= Less than or equal
<=> NULL-safe equal
= Equal
> Greater than
>= Greater than or equal
 Logical NOT
&& Logical AND
XOR Logical XOR
|| Logical OR
BETWEEN AND True if expression between two values.
CASE Returns the result where value=compare_value or for the first
condition that is true
CAST Casts a value of one type to another type
CONCAT Returns concatenated string
CONCAT_WS Concatenate with separator
CONVERT Convert a value from one type to another type

Page 3 / 7 - last modified by Manuel Antonio Lazo Reyes on 2023/08/15 16:12


Quick help

CURDATE Returns the current date


CURRENT_USER Username/host that authenicated the current client
CURTIME Returns the current time
DATEDIFF Difference in days between two date/time values
DATE_ADD Date arithmetic - addition
DATE_FORMAT Formats the date value according to the format string
DATE_SUB Date arithmetic - subtraction
DAY Synonym for DAYOFMONTH()
DAYNAME Return the name of the weekday
DAYOFMONTH Returns the day of the month
DAYOFWEEK Returns the day of the week index
DAYOFYEAR Returns the day of the year
FORMAT Formats a number
IF If expr1 is TRUE, returns expr2; otherwise returns expr3
IFNULL Check whether an expression is NULL
IS NOT Tests whether a boolean value is not TRUE, FALSE, or
UNKNOWN
IS NOT NULL Tests whether a value is not NULL
IS NULL Tests whether a value is NULL
ISNULL Checks if an expression is NULL
LIKE Whether expression matches a pattern
LOCALTIME Synonym for NOW()
LOCALTIMESTAMP Synonym for NOW()
LOCATE Returns the position of a substring in a string
LTRIM Returns the string with leading space characters removed
MOD Modulo operation. Remainder of N divided by M
NOW Returns the current date and time
POSITION Returns the position of a substring in a string
ROUND Rounds a number
TRIM Returns a string with all given prefixes or suffixes removed
UTC_DATE Returns the current UTC date
UTC_TIME Returns the current UTC time
UTC_TIMESTAMP Returns the current UTC date and time
   
   

Maria DB commands
Show session and global variables
show global variables;
show session variables;

Show tables and views


-- Show tables and views
show full tables;
-- Show views
SHOW FULL TABLES
WHERE Table_Type LIKE 'VIEW';

Page 4 / 7 - last modified by Manuel Antonio Lazo Reyes on 2023/08/15 16:12


Quick help

-- Show tables
SHOW FULL TABLES
WHERE Table_Type LIKE 'TABLE';

Show tables and columns


select ordinal_position as column_id,
TABLE_NAME ,
   column_name as column_name,
    data_type as data_type,
   case when numeric_precision is not null
             then numeric_precision
       else character_maximum_length end as max_length,
   case when datetime_precision is not null
             then datetime_precision
       when numeric_scale is not null
            then numeric_scale
       else 0 end as data_precision,
    is_nullable,
    column_default,
   COLLATION_NAME
from information_schema.columns
where table_schema = 'mayu' and COLLATION_NAME is not null and COLLATION_NAME  <>
'utf8_general_ci'
order by table_name, COLUMN_NAME ;

Show tables and records


-- Listar tablas y registros
select table_name as 'table',
    table_rows as 'rows'
from information_schema.tables
where table_schema = 'mayu' -- put your database name here
   and table_type = 'BASE TABLE'
order by table_rows desc;

Show store procedures and functions


show procedure status;
select routine_schema as database_name,
      routine_name,
       routine_type as type,
       data_type as return_type,
       routine_definition as definition
from information_schema.routines
where routine_schema not in ('sys', 'information_schema',
                         
'mysql', 'performance_schema')
   -- and r.routine_schema = 'database_name' -- put your database name here
order by routine_schema,
        routine_name;

Strict mode
set global innodb_default_row_format='dynamic';
set session innodb_strict_mode=OFF;

Foreign key check


set foreign_key_checks = 0 | 1
set foreign_key_checks = 0
set foreign_key_checks = 1

Page 5 / 7 - last modified by Manuel Antonio Lazo Reyes on 2023/08/15 16:12


Quick help

SQL Server commands


List functions and store procedures
SELECT ROUTINE_NAME FROM information_schema.routines -- WHERE routine_type = 'function'

List tables, views and rows


--Cursor que contiene todos los objetos que ocupan espacio
DECLARE objects_cursor CURSOR LOCAL FAST_FORWARD READ_ONLY for
     SELECT s.name + '.' + o.name from sys.schemas s
     INNER JOIN sys.objects o
     ON o.schema_id = s.schema_id
     WHERE
            o.type = 'S' or --Tablas de sistema
           o.type = 'U' or --Tablas de usuario
           o.type = 'V' or --Vistas (solo las indexadas devuelven tamaño)
           o.type = 'SQ' or --Cola de servicio
           o.type = 'IT' -- Tablas internas usadas p.e. por el Service Broker o los indices XML
/*
DECLARE objects_cursor CURSOR LOCAL FAST_FORWARD READ_ONLY FOR
      SELECT name FROM
            sysobjects o
      WHERE
            o.xtype = 'S' or --Tablas de sistema
            o.xtype = 'U' or --Tablas de usuario
            o.xtype = 'V' --Vistas (solo las indexadas devuelven tamaño)
*/
--Tabla temporal para albergar los resultados
CREATE TABLE #results
      (name SYSNAME, rows CHAR(11),
      reserved VARCHAR(18), data VARCHAR(18),
      index_size VARCHAR(18),Unused VARCHAR(18))
--Recorremos el cursor obteniendo la información de espacio ocupado
DECLARE @object_name AS SYSNAME
OPEN objects_cursor
FETCH NEXT FROM objects_cursor
INTO @object_name;
WHILE @@FETCH_STATUS = 0
BEGIN
     INSERT INTO #results
           EXEC sp_spaceused @object_name     
     FETCH NEXT FROM objects_cursor
           INTO @object_name;     
END;
CLOSE objects_cursor;
DEALLOCATE objects_cursor;
-- Quitamos "KB" para poder ordenar
UPDATE
 #results
SET
  reserved = LEFT(reserved,LEN(reserved)-3),
 data = LEFT(data,LEN(data)-3),
  index_size = LEFT(index_size,LEN(index_size)-3),
  Unused = LEFT(Unused,LEN(Unused)-3)
--Ordenamos la información por el tamaño ocupado
SELECT

Page 6 / 7 - last modified by Manuel Antonio Lazo Reyes on 2023/08/15 16:12


Quick help

  Name,
  reserved AS [Tama ñ o en Disco (KB)],
 data AS [Datos (KB)],
  index_size AS [Indices (KB)],
  Unused AS [No usado (KB)],
 Rows AS Filas FROM #results
ORDER BY
 CONVERT(bigint, reserved) DESC
--Eliminar la tabla temporal
DROP TABLE #results

Linux commands
Update Ubuntu Server
-- Update Ubuntu server
sudo apt update;
sudo apt upgrade;
sudo reboot;
-- List available packages
sudo apt list --upgradable;
sudo cat /var/lib/update-notifier/updates-available;
-- List security updates
sudo unattended-upgrade --dry-run

Create user name


adduser username;

Add user to sudo group


usermod -aG sudo username;

Switch to user
su - username

Change password
passwd

Show 

Page 7 / 7 - last modified by Manuel Antonio Lazo Reyes on 2023/08/15 16:12

You might also like