Pages - Menu

標籤

AWS (1) bash (1) Boost (2) C (2) CMake (2) Concurrency_Programming (3) CPP (37) Database (2) DNS (1) Docker (4) Docker-Compose (1) ELK (1) emacs (4) gcp (1) gdrive (1) git (1) gitbash (2) gitlab (1) kvm (4) Linux (5) MT4 (4) MT5 (4) Multicast (2) MySQL (2) Nijatrader8 (1) OpenCV (1) Python (4) QT5 (1) R (1) rdp (3) screenshot (1) ssh (3) Tabnine (1) TCP (1) TensorFlow (1) Tools (12) Ubuntu_1904 (11) Ubuntu_20_04 (5) UDP (1) VS2010 (1) VS2015 (1) VS2019 (1) WebServer (1) Win10 (1) winmerge (1) WSL (1) xrdp (1)

搜尋此網誌

2019年8月9日星期五

MySQL cheat sheet

Cheat Sheet


# Create a new user and let remote access possible
mysql> CREATE USER 'username'@'localhost' IDENTIFIED BY 'password';
mysql> GRANT ALL PRIVILEGES ON *.* TO 'username'@'localhost' WITH GRANT OPTION;
mysql> CREATE USER 'username'@'%' IDENTIFIED BY 'password';
mysql> GRANT ALL PRIVILEGES ON *.* TO 'username'@'%' WITH GRANT OPTION;
mysql> FLUSH PRIVILEGES;
#
# Show user in sql
# Show all MySQL users:
mysql> SELECT user FROM mysql.user;
# List only unique user names:
mysql> SELECT DISTINCT user FROM mysql.user;
# Show MySQL users and hosts they are allowed to connect from:
mysql> SELECT user,host FROM mysql.user;
# Show MySQL users, their passwords and hosts:
mysql> SELECT user,host,password FROM mysql.user;
# in MySQL 5.7 and higher:
mysql> SELECT host,user,authentication_string FROM mysql.user;
#
# Remove user
## Revoke all grants for a mysql user
mysql> REVOKE ALL PRIVILEGES, GRANT OPTION FROM 'username'@'localhost';
mysql> DROP USER 'username'@'localhost';
mysql> FLUSH PRIVILEGES;
# Clean a table, delete all records
mysql> DELETE FROM tableName;
# select / use a database
mysql> USE databaseName;
# remove a table
mysql> DROP TABLE tablename;
# remove a database
mysql> DROP DATABASE dbname;
# login with other user name
mysql> mysql -h localhost -P 3306 --protocol=tcp -u userName -p
mysql> mysql -h 127.0.0.1 -P 3306 --protocol=tcp -u userName -p

沒有留言:

發佈留言