資料庫設計分類、目錄等等的結構,要去考量有幾個階層,當階層不明確,或者階層很多,通常會用下述設計方式(想要幾個階層都可以):
- cate_id / cate_name / cate_parent_id (預設 cate_parent_id = 0)
依照這種設計法,每次查詢就一直找到自己的父節點id,當找到 cate_parent_id = 0 就找到最上層了
這種作法就會需要寫個 while 一直往上查詢上去,有沒有辦法一行 SQL 語法直接達成呢?
個人筆記, 記錄關於 系統、程式、新聞 與 日常生活 等資訊
資料庫設計分類、目錄等等的結構,要去考量有幾個階層,當階層不明確,或者階層很多,通常會用下述設計方式(想要幾個階層都可以):
依照這種設計法,每次查詢就一直找到自己的父節點id,當找到 cate_parent_id = 0 就找到最上層了
這種作法就會需要寫個 while 一直往上查詢上去,有沒有辦法一行 SQL 語法直接達成呢?
Apache2 設定檔設好後,重新啟動前,都會做語法檢查:apache2ctl configtest,若有錯誤可以重新啟動前即時修正。
但是 MySQL 要怎麼做語法檢查呢?
MySQL 遇到下述錯誤訊息:
要如何解決呢?
MySQL 使用 Innobackupex 來做備份,詳見此篇:使用 Percona innobackupex 備份 與 還原 MySQL
執行下述命令:
出現下述錯誤訊息:
InnoDB: Error: log file ./ib_logfile0 is of different size 5242880 bytes
註:原始 DB 是 Debian 預設的 MySQL
修復方式如下步驟:
MySQL 的 InnoDB 只能用 mysqldump,而沒辦法使用 cp 來備份,這點可以使用 Percona 出的 innobackupex 來解決~
Percona 出很多 MySQL 的工具,可以做同步、快速備份 等等 ..
MySQL 要從備份還原啟動,但是發生啟動失敗,在 mysql 的 error log 裡面看到下述訊息。
Unable to start MySQL service: Plugin 'InnoDB' registration as a STORAGE ENGINE failed.
InnoDB: Using Linux native AIO
InnoDB: Initializing buffer pool, size = 128.0M
InnoDB: Completed initialization of buffer pool
InnoDB: Error: log file ./ib_logfile0 is of different size 0 50331648 bytes
InnoDB: than specified in the .cnf file 0 5242880 bytes!
[ERROR] Plugin 'InnoDB' init function returned error.
[ERROR] Plugin 'InnoDB' registration as a STORAGE ENGINE failed.
[ERROR] Unknown/unsupported storage engine: InnoDB
170122 12:01:00 InnoDB: Warning: table 'mysql/innodb_index_stats' InnoDB: in InnoDB data dictionary has unknown flags 50.
170122 12:01:00 InnoDB: Warning: table 'test/collect' InnoDB: in InnoDB data dictionary has unknown flags 50.
170122 12:01:00 [ERROR] /usr/sbin/mysqld: Table './mysql/user' is marked as crashed and should be repaired
170122 12:01:00 [Warning] Checking table: './mysql/user'
170122 12:01:00 [ERROR] 1 client is using or hasn't closed the table properly
170122 12:01:00 InnoDB: Warning: table 'test/users'
InnoDB: in InnoDB data dictionary has unknown flags 50.
要怎麼修復呢?
MySQL 使用 ALTER Table 的語法蠻直覺的,如下:
在 Primay Key 的沒有「修改」的語法,想要修改得用刪除再新增的方法來達成,如下範例:
Debian Linux 升級 Percona DB 5.7 (MySQL),遇到下述的警告訊息:
解法:
阿里巴巴(淘寶) Open Source 出他們改的 MySQL 版本,名叫 AliSQL。
MySQL Percona 相信大家已經不陌生,安裝步驟於 2012、2013年也寫過下述幾篇:
不過現在有更簡單的安裝方式了,所以來更新更簡單的安裝方式