Category: mysql

[mysql] 追蹤與紀錄執行過久的 SQL

Mysql 5.7 有以下兩個設定可以協助你排查 SQL 執行的狀況以及相關指標,由於這類設定可能會影響效能上的表現,預設會是關閉的,以下簡介如何開啟設定以及相關的設定檔。 General Query Log:記錄下所有執行的 SQL query 供排查,開啟後通常會伴隨大量的寫入因此不建議在生產環境開啟設定,範例輸出像是以下: 開啟 general_log 我們可以透過以下 SQL 讀取/設定目前的 gerenal_logs 設定 要注意的有以下三個值 general_log:ON / OFF 開啟 general_logs 與否 general_log_file:寫入指定目的地路徑的檔案 log_output:FILE / TABLE 寫入目的地為檔案 或資料表( mysql.general_log) 透過 SQL 更改 runtime 設定設定會立即生效不需要重啟 mysql service,但重啟 mysql 後需要重新設定 透過 my.cnf 設定重啟後 mysql 預設會依照以下路徑的先後讀取設定檔(mysql -h 可以看到此提示) /etc/my.cnf /etc/mysql/my.cnf /usr/local/etc/my.cnf ~/.my.cnf Slow Query Log:對比於 […]

[mac] mysql2 gem: Don’t know how to set rpath on your system, if MySQL libraries are not in path mysql2 may not load

這幾天在裝 mysql2 gems 時發生如下的錯誤 原因主要是 ld: library not found for -lssl 通常是 openssl 未安裝或路徑設定有誤 可以先試著重裝 openssl ,必且重新設定對應的環境變數 重新安裝 mysql2 gem 應該就正常囉! 參考資料: https://stackoverflow.com/questions/30834421/error-when-trying-to-install-app-with-mysql2-gem/30837897#30837897?newreg=a89c9550c93f4e7c84db03b8c15ff3d9

[mysql] InnoDB: Table `mysql`.`innodb_table_stats` not found.

前陣子裝了 mysql,但似乎沒裝完整,導致執行 mysql 機器負載總是衝很高。 看了一下 mysql error.log InnoDB: Table `mysql`.`innodb_table_stats` not found. Table ‘performance_schema.session_variables’ doesn’t exist 嗯…連 show variables; 都無法執行 查了一下相關資料,用以下步驟即可解決。 強制更新 mysql mysql_upgrade -u root -p –force 重開 mysql sudo service mysql restart   參考資料: https://stackoverflow.com/questions/31967527/table-performance-schema-session-variables-doesnt-exist    

[mysql] start: Job failed to start invoke-rc.d: initscript mysql, action “start” failed. ,完整移除並重新安裝

剛好同事遇到 mysql 無法正常開啟,但重裝(sudo apt-get install mysql-server-5.6)時卻一直顯示 start: Job failed to start invoke-rc.d: initscript mysql, action “start” failed. dpkg: error processing mysql-server-5.5 (–configure): subprocess installed post-installation script returned error exit status 1 或是 Unable to set password for the mysql “root” user….. 嘗試執行 mysql 也會寫著服務的 socket 未開啟 ERROR 2002 (HY000): Can’t connect to local MySQL server […]

[mysql] 新增使用者及權限設定

每次要設定 mysql 的資料庫給外面的廠商,都一直忘記指令…… 來記錄一下指令~ 新增使用者 INSERT INTO user(host,user,password) VALUES(‘%’,’camel’,password(‘2243’)); 授予特定資料庫全部權限(camel/2243) GRANT ALL ON dbname.* TO ‘camel’@localhost IDENTIFIED BY ‘2243’; 移除使用者(camel)特定資料庫權限 REVOKE ALL PRIVILEGES ON dbname.* FROM ‘camel’@’localhost’; 移除使用者(camel) DROP USER ‘camel’@’localhost’;   參考資料: http://blog.toright.com/posts/1214/mysql-%E6%96%B0%E5%A2%9E%E4%BD%BF%E7%94%A8%E8%80%85%E8%88%87%E6%AC%8A%E9%99%90%E8%A8%AD%E5%AE%9A-%E7%AD%86%E8%A8%98.html