Skip to content

Instantly share code, notes, and snippets.

@RomanTuras
Last active April 26, 2023 14:41
Show Gist options
  • Select an option

  • Save RomanTuras/d7ac45860bdfabb118adef9c38ae9c97 to your computer and use it in GitHub Desktop.

Select an option

Save RomanTuras/d7ac45860bdfabb118adef9c38ae9c97 to your computer and use it in GitHub Desktop.
SQL cli helper
-- Create mysql database and user, basic tips:
-- sudo mysql -u root -p
-- Show MySQL Users
SELECT user FROM mysql.user;
CREATE DATABASE [IF NOT EXISTS] database_name;
SHOW DATABASES;
CREATE USER 'newuser'@'localhost' IDENTIFIED BY 'password';
GRANT ALL PRIVILEGES ON * . * TO 'newuser'@'localhost';
FLUSH PRIVILEGES;
-- Show databases with SIZE:
SELECT table_schema AS "Database Name",
ROUND(SUM(data_length + index_length) / 1024 / 1024, 2) AS "Size in (MB)"
FROM information_schema.TABLES
GROUP BY table_schema;
USE database_name;
SHOW DATABASES;
SHOW TABLES;
-- Import DB from file, to local using comand line:
-- create a database with same name (as showing above)
-- create a user with imported DB credentials
-- mysql -u username -p database_name < file.sql
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment