目錄表

Install mycli

mycli

yaourt -S mycli

Login to mysql shell

mycli -u root -p

Create database

CREATE DATABASE newdatabase;
USE newdatabase

Create user and grant the database access

CREATE USER 'newuser'@'localhost' IDENTIFIED BY 'newpassword';
GRANT ALL PRIVILEGES ON newdatabase.* TO 'newuser'@'localhost';

Change credential

mysqladmin -u root password 'new-password'
mysqladmin -u root -h localhost password 'new-password'
SET PASSWORD FOR 'user'@'localhost' = PASSWORD('password');
-- or
update mysql.user set password=PASSWORD(‘新password) where User=’root’;­
-- and then
flush privileges;­

Show users

SELECT * FROM mysql.user;

Show grants

SHOW DATABASES;
SELECT host, USER, password FROM mysql.user;
SHOW GRANTS FOR username@localhost;

Remote grants

REVOKE ALL privileges ON newdatabase.* FROM 'newuser'@'localhost';
FLUSH privileges;

List databases

SHOW DATABASES

List tables

SHOW TABLES