MySQL 筆記

因為做項目需要,就學了一些MySQL.也不想把太多的東西記在腦子里,所以就在這裡做一些學習小筆記

Basic Info

System: Ubuntu 19.10

Installation

例行升級

sudo apt update && sudo apt upgrade -y

安裝mysql server

sudo apt install mysql-server

這一步很重要,之前老是忘掉 安全安裝

sudo mysql_secure_installation

然後輸入你的登入密碼,接下來那四個基本上都是y

然後查看mysql的運行狀況

sudo systemctl status mysql
#系統開機啟動
sudo systemctl enable mysql

連結到MySQL server

sudo mysql -u root -p
#如果看到mysql>的話就成功了
mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sys                |
+--------------------+
4 rows in set (0.05 sec)

Cheat Sheet

What to achieve Command Reference
創建新用戶 CREATE USER ‘user’@‘localhost’;
給用戶分配權限 GRANT [ALL PRIVILEGES]/[SELECT, INSERT, DELETE] ON data_basename.* TO ‘username’@‘localhost’;
撤銷用戶權限 REVOKE [ALL PRIVILEGES(僅一項權限)]/[GRANT OPTION(所有權限)] ON data_basename.* FROM ‘username’@‘localhost’;
刷新privileges緩衝區 FLUSH PRIVILEGES;
創建table CREATE TABLE events( id int auto_increment primary key, event_name varchat(255), visitor varchar(255), properties json )
插入數據 INSERT INTO events(properties) VALUE (’{“type”:{‘THIS IS TEST JSON’}}’)
删除表 DROP TABLE events