Skip to content

Instantly share code, notes, and snippets.

@iBet7o
Last active November 9, 2017 04:36
Show Gist options
  • Save iBet7o/ab010d0ee7abbef6e6f4 to your computer and use it in GitHub Desktop.
Save iBet7o/ab010d0ee7abbef6e6f4 to your computer and use it in GitHub Desktop.
CheatSheet MySQL

Contenido

Gestion de DB

Respaldo de una base de datos completa.

mysqldump --user=root {nombre_db} > {nombre_db}.$(date +%d%m%Y).backup

Crear una base de datos.

CREATE DATABASE {nombre_db} CHARACTER SET utf8 COLLATE utf8_unicode_ci;

Muestra las tablas y el total de registros de la base actual.

SELECT TABLE_NAME, TABLE_ROWS
FROM information_schema.tables
WHERE TABLE_SCHEMA = DATABASE();

Gestión de usuarios

Muestra los usuarios en el servidor

SELECT User, Host, Password
FROM mysql.user
ORDER BY 1;

Crear un usuario

CREATE USER '{username}'@'{host}'
IDENTIFIED BY '{password}';

Eliminar un usuario

DROP USER '{username}'@'{host}';

Cambiar contraseña

SET PASSWORD FOR '{username}'@'{host}' = PASSWORD('{password}');

Añadir permisos

GRANT ALL PRIVILEGES ON *.* TO '{username}'@'{host}'
IDENTIFIED BY '{password}';

Mostrar los permisos

SHOW GRANTS FOR '{username}'@'{host}';

Eliminar los permisos

REVOKE ALL PRIVILEGES, GRANT OPTION FROM '{username}'@'{host}';

Recargar los privilegios

FLUSH PRIVILEGES;

Otros

Limpiar consola

system clear;

Debug

SHOW VARIABLES LIKE "general_log%";

/* ON DEBUG */
SET GLOBAL general_log = 'ON';
$ tail -f /var/lib/mysql/test.log
/* OFF DEBUG */
SET GLOBAL general_log = 'OFF';

SHOW VARIABLES LIKE "general_log%";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment