【MySQL】【故障】平常小問題記錄

刪除記錄時提示須要SELECT 權限

(1143, "SELECT command denied to user 'test_delete'@'localhost' for column 'id' in table 'agent_info'")

參考

https://stackoverflow.com/questions/22580529/mysql-duplicate-entry-error-when-trying-to-add-new-columnphp

修改表增長行時提示主鍵有重複記錄

其實沒有,是由於5.6開始支持在線修改表結構。向新表追加dml log時會出現空洞重複java

參考

https://bugs.mysql.com/bug.php?id=76895mysql

WHERE columnX=NULL是否規範?

不規範
應使用 WHERE columnX IS NULLsql

MySQL中WHERE columnX=NULL等效WHERE columnX IS NULLbash

SQL92規範中中WHERE columnX=NULL永遠不成立ide

參考

https://stackoverflow.com/questions/2747279/something-about-ansi-nullscode

You can't specify target table for update in FROM clause

參考

https://stackoverflow.com/questions/4429319/you-cant-specify-target-table-for-update-in-from-clauseci

獲取準確的頁面記錄數量總計

SELECT s.*,t.count 
FROM 
    instance_summary AS s
JOIN
    (SELECT COUNT(*) AS `count` FROM instance_summary) AS t

INSERT ON DUPLICATE KEY UPDATE 死鎖

在5.7版本上比較常見
解決辦法: 先更新,後插入get

int affectRows = update(sql)
if (affectRows ==0 )
{ 
 // 某些狀況下可能要先檢查行記錄是否存在,而後insert。經過主動採樣的方式減少異常發生
    insert(sql) 
}

參考

The following notes will be helpful for you,

mysql_affected_rows() returns

+0: a row wasn't updated or inserted (likely because the row already existed, but no field values were actually changed during the UPDATE).

+1: a row was inserted

+2: a row was updated

-1: in case of error.

https://stackoverflow.com/questions/9397291/mysql-affected-rows-returns-0-for-update-statement-even-when-an-update-actuallit

相關文章
相關標籤/搜索