mysql開啟日志功能


今天要調試個程序,需要開啟mysql日志功能搞了好一會沒成功。最后在網上找到資料搞定,這樣做個記錄。

 

首先在windows上弄,找到my.ini,按照網上的說法,在配置文件底部加入

 

[plain]  view plain copy 在CODE上查看代碼片 派生到我的代碼片
 
  1. log="C:/temp/mysql.log"  
  2. log_slow_queries="C:/temp/mysql_slow.log"  
  3. long_query_time=1  


弄完后,便打開cmd,重啟下,這時報了好幾個錯

 

 

[plain]  view plain copy 在CODE上查看代碼片 派生到我的代碼片
 
  1. C:\D\lamp\mysql\bin>mysqld.exe restart  
  2. 131218 15:09:25 [Warning] The syntax '--log' is deprecated and will be removed i  
  3. n a future release. Please use '--general-log'/'--general-log-file' instead.  
  4. 131218 15:09:25 [Warning] The syntax '--log-slow-queries' is deprecated and will  
  5.  be removed in a future release. Please use '--slow-query-log'/'--slow-query-log  
  6. -file' instead.  


在網上查了下,原來是mysql版本問題,我的版本是5.5.20,上面的是mysql5.5.8配置的方法,於是換了下寫法

 

 

[plain]  view plain copy 在CODE上查看代碼片 派生到我的代碼片
 
  1. log-error="C:/D/lamp/log/error.log"  
  2. general-log=1  
  3. general-log-file="C:/D/lamp/log/mysql.log"  
  4. long_query_time=3  
  5. slow_query_log=1  
  6. slow-query-log_file="C:/D/lamp/log/slowquery.log"  


重啟搞定。

 

在linux環境下,更好配置,打開my.cnf文件(一般位於/etc目錄下),在底部加上

 

[plain]  view plain copy 在CODE上查看代碼片 派生到我的代碼片
 
  1. log-error=/var/log/mysqld.log  
  2. log_slow_queries=/var/log/slowquery.log  
  3. long_query_time=3  


重啟mysql,service mysql restart。

 

 

這里再說說,在windows環境下,重啟mysql遇到的問題。

 

[plain]  view plain copy 在CODE上查看代碼片 派生到我的代碼片
 
  1. C:\Users\molaifeng>net start mysql  
  2. 發生系統錯誤 5。  
  3.   
  4. 拒絕訪問。  


從網上查詢得知,是權限不夠,使用管理員權限運行即可,於是去C:/Windows/System32,找到cmd.exe,以管理員的身份運行,運行后,又報了個錯誤

 

 

[plain]  view plain copy 在CODE上查看代碼片 派生到我的代碼片
 
  1. C:\windows\system32>net start mysql  
  2. MySQL 服務正在啟動 ...  
  3. MySQL 服務無法啟動。  
  4.   
  5. 系統出錯。  
  6.   
  7. 發生系統錯誤 1067。  
  8.   
  9. 進程意外終止。  


還是得依靠萬能的互聯網,得知是配置文件出錯,把配置文件中出錯的的配置去掉,就好了。

 

同時,第一次錯誤的配置時,重啟了下電腦,后來發現mysql進不去了,說是密碼錯誤,於是便把命令行上如何在忘記密碼的情況下重新設置密碼給記錄下。

首先,打開一個cmd窗口,輸入

 

[plain]  view plain copy 在CODE上查看代碼片 派生到我的代碼片
 
  1. mysqld --defaults-file="C:\Program Files\MySQL\MySQL Server 5.1\my.ini" --console --skip-grant-tables  


其次,再開一個cmd窗口,輸入

 

 

[plain]  view plain copy 在CODE上查看代碼片 派生到我的代碼片
 
  1. mysql -u root -p  


回車,緊接便是要輸入密碼,記住這次就不需要輸入密碼了,因為第一個cmd窗口里的命令便是跳過mysql的權限安全檢查,因此直接回車,再依次輸入以下命令

 

 

[plain]  view plain copy 在CODE上查看代碼片 派生到我的代碼片
 
  1. use mysql;  
  2. UPDATE user SET Password=PASSWORD('newpassword') where USER='root';#注意,那個newpassword便是新密碼,可以設置  
  3. FLUSH PRIVILEGES;  

 

退出后,再重新連入mysql就ok了。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM