Post

common commands for MySQL

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
-- Show databases
SHOW DATABASES;

-- Connect to one database
USE database;

-- List tables
SHOW TABLES;

-- Describe table
DESCRIBE users;
-- List user
SELECT * FROM mysql.user;

-- Create user in MySQL/MariaDB.
CREATE USER 'user'@'host' IDENTIFIED BY 'mypassword';
-- Create user access from localhost
CREATE USER 'user'@'localhost' IDENTIFIED BY 'mypassword';
-- user from any host
CREATE USER 'user'@'%' IDENTIFIED BY 'mypassword';

-- Drop user
CREATE USER 'user'@'host';

-- Create a database
CREATE DATABASE IF NOT EXISTS mydb;

-- Grant permissions
GRANT ALL ON database.table TO 'user'@'host';
GRANT ALL ON database.* TO 'user'@'host';

-- Grant permission global
GRANT ALL ON *.* TO 'user'@'host';

-- Show current user permissions
SHOW GRANTS FOR 'user'@'host'
This post is licensed under CC BY 4.0 by the author.