Skip to content

Instantly share code, notes, and snippets.

@theo-bittencourt
Last active May 12, 2017 18:34
Show Gist options
  • Save theo-bittencourt/e01d528547d0a132d57c8829b96d4409 to your computer and use it in GitHub Desktop.
Save theo-bittencourt/e01d528547d0a132d57c8829b96d4409 to your computer and use it in GitHub Desktop.
MySQL Snippets

MySQL Snippets

Initial setup

$ mysql_secure_installation

O prompt do mysql deve ser iniciado com -u root para alguns comandos

$ mysql -u root

Create Database

$ CREATE DATABASE database_name;

Create User

$ CREATE USER 'newuser'@'localhost' IDENTIFIED BY 'password';

Delete User

$ DROP USER 'user'@'localhost';

Access control

$ GRANT ALL PRIVILEGES ON database_name . table_name TO 'newuser'@'localhost';

# or

$ GRANT ALL PRIVILEGES ON * . * TO 'newuser'@'localhost';

$ FLUSH PRIVILEGES;  

Dump

$ mysqldump -h HOST -u USER -pPASS DATABASE > sql_dump.sql

Restore

$ mysql -h HOST -u USER -pPASS DATABASE < sql_dump.sql

List all users

$ select User from mysql.user;

List databases

$ show databases;

List tables

$ show tables;

List table columns

$ show columns from 'the_table';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment