-
Notifications
You must be signed in to change notification settings - Fork 0
MySQL
E. Lynette Rayle edited this page May 14, 2022
·
8 revisions
See SQL Queries for query examples
enter without user specified
mysql
enter for specific user and prompt for password
mysql -u _USERNAME_ -p
show databases;
use _DATABASE_NAME_;
SELECT User FROM mysql.user;
show tables from _DATABASE_NAME_;
OR
use _DATABASE_NAME_;
show tables;
select TABLE_NAME AS `Table`, ROUND((DATA_LENGTH + INDEX_LENGTH) / 1024 / 1024) AS `Size (MB)` from information_schema.TABLES where TABLE_SCHEMA = "_DATABASE_NAME_" order by (DATA_LENGTH + INDEX_LENGTH) desc;
select table_name, table_rows from information_schema.tables where table_schema='_DATABASE_NAME_';
select distinct table_name from information_schema.columns where column_name in ('_COLUMN_NAME_') and table_schema='_DATABASE_NAME_';
select distinct table_name from information_schema.columns where column_name LIKE ('%_id') and table_schema='exhibits_staging';
select max(updated_at) from _TABLE_NAME_;
select id, updated_at from _TABLE_NAME_ where updated_at between '2021-12-16 00:00:00' and '2021-12-16 23:59:59'; # substituting the date returned by the first query for 2021-12-16
for all tables
SELECT table_name, column_name, character_set_name, collation_name, column_type FROM information_schema.`COLUMNS` WHERE table_schema = '_DATABASE_NAME_';
for specific table
SELECT table_name, column_name, character_set_name, collation_name, column_type FROM information_schema.`COLUMNS` WHERE table_schema = '_DATABASE_NAME_' and table_name='_TABLE_NAME_';
show columns from _TABLE_NAME_ in _DATABASE_NAME_;
OR
use _DATABASE_NAME_;
show columns from _TABLE_NAME_;
CREATE DATABASE _DATABASE_NAME_ DEFAULT CHARACTER SET utf8 DEFAULT COLLATE utf8_general_ci;
DROP DATABASE _DATABASE_NAME_;
CREATE USER '_USERNAME_'@'localhost' IDENTIFIED BY '_USERPASSWORD_';
use _DATABASE_NAME_;
GRANT ALL ON _DATABASE_NAME_.* TO _USERNAME_@localhost IDENTIFIED BY '_USERPASSWORD_';
List values for a specific column
select _COLUMN_NAME_ from _DATABASE_NAME_._TABLE_NAME_;
OR
use _DATABASE_NAME_;
select _COLUMN_NAME_ from _TABLE_NAME_;
show status where variable_name = 'threads_connected';
show processlist;