顯示具有 SQL 標籤的文章。 顯示所有文章
顯示具有 SQL 標籤的文章。 顯示所有文章

2021年11月24日 星期三

Mariadb (Mysql) enable audit log

Reference:
 
#login mysql
mysql -u root -p

#確認plugin目錄 (in mysql)
SHOW GLOBAL VARIABLES LIKE 'plugin_dir';
+---------------+--------------------------+
| Variable_name | Value                    |
+---------------+--------------------------+
| plugin_dir    | /usr/lib64/mysql/plugin/ |
+---------------+--------------------------+

2020年12月18日 星期五

SQL Server Transaction Log Shrink

 Reference:

[SQL] 交易記錄檔 LDF 太大 (趴兔) - 使用 DBCC Shrinkfile

SQL Server Transaction Log Backup, Truncate and Shrink Operations

SQL DB的檔案有兩個:

*.MDF 資料檔

*.LDF 記錄檔


如果有正常備份成功,LDF內的log應該會刪除。如果有其他因素造成log持續成長,會把硬碟塞滿。這時候只能把log清除並壓縮LDF。

作法:

  • 將資料庫復原模式設成「簡單」
  • 執行 DBCC SHRINKFILE (DBname_log, 2)
  • 將資料庫復原模式設成「完整」

2020年12月3日 星期四

SQL injection 測試方法及工具

 Reference:

資安滲透攻防筆記-1

sqlmap®

Using sqlmap for testing HTTPS sites

使用工具 SQLMAP 檢測

安裝在CentOS 7,步驟:

  • yum install python
  • yum install git
  • git clone --depth 1 https://github.com/sqlmapproject/sqlmap.git sqlmap-dev
  • yum install squid
  • service squid start

執行:

  • cd sqlmap-dev/
  • ./sqlmap.py -u "https://target.com/" --batch
  • 若網頁需要輸入資料,指令 ./sqlmap.py -u "https://target.com/" --batch --forms

(2021.7.13 version update後似乎不需要 --batch --proxy "http://127.0.0.1:3128")

  • ./sqlmap.py -u "https://target.com/" --batch --proxy "http://127.0.0.1:3128"


2017年6月27日 星期二

CentOS 6.x upgrade PHP, MySQL

● Upgrade CentOS 6.x

  1. Change to root.
  2. Backup import data. Ex: /etc, /var/log, web, mysql ...
  3. yum update
  4. reboot

Reference: Upgrade to CentOS 6.7 from CentOS 6.6/6.5/6.4/6.3/6.2/6.1/6.0

2015年8月21日 星期五

SQL like query for nchar field

Reference:
SQL Server char and nchar columns search differently

狀況:
MS SQL DB Table 有一個欄位 TB007 是 nchar(10) 型態,裡面有一筆資料是 DR0019A。
用 select * from table where TB007 like '19A' 查詢回覆 0 筆資料。

原因:
nchar(10) 會把資料後面補空白變成 10 個字元,所以實際上那筆資料是 'DR0019A   '。

解法:
加上 RTRIM 去掉空白的部份。
select * from table where RTRIM(TB007) like '19A'

2014年4月23日 星期三

How to detect when an UPDATE fails when using ADODB.Command Execute

Reference:
How to detect when an UPDATE fails when using ADODB.Command Execute

Dim update_cmd As New ADODB.Command
lRecordsAffected = 0
update_cmd.ActiveConnection = CurrentProject.Connection
update_cmd.CommandType = adCmdText
update_cmd.CommandText = "your SQL Update command"
Set adoRS = update_cmd.Execute(lRecordsAffected)

If (lRecordsAffected = 0) Then
    MsgBox "update fail"
ElseIf (lRecordsAffected > 0) Then
    MsgBox "update complete"
End If

註:
Set adoRS = update_cmd.Execute(lRecordsAffected) 這一行一定要有 Set adoRS。
如果只寫 update_cmd.Execute(lRecordsAffected),不會把更新筆數記錄到 lRecordsAffected。

2014年1月3日 星期五

Microsoft SQL 2008 "Saving changes is not permitted" solution

Reference:
http://weblogs.asp.net/coltk/archive/2009/12/26/saving-changes-is-not-permitted-in-sql-2008-management-studio.aspx

I used to write ALTER statement (e.g. ALTER Table.. .ALTER Column...) so I don't really know what is the error message mean. Today, I search it during my Xmas holiday and know that there's a option in Tools | Options | Designer | Prevent saving change that require table re-creation.

2012年12月28日 星期五

How do I configure SQL Server Express to allow remote tcp/ip connections on port 1433

Reference:
http://support.webecs.com/KB/a375/how-do-i-configure-sql-server-express-to-allow-remote.aspx

1. open "SQL Server Configuration Manager"

2. Protocols for SQLEXPRESS

3. Right click TCP/IP and select Properties
  • Active: Yes
  • TCP Dynamic Ports: (blank)
  • TCP port: 1433
4. Enable "SQL Browser" in SQL Server Services