-
RowsThe number of rows. Some storage engines, such as
MyISAM, store the exact count. For other storage engines, such asInnoDB, this value is an approximation, and may vary from the actual value by as much as 40 to 50%. In such cases, useSELECT COUNT(*)to obtain an accurate count.The
Rowsvalue isNULLfor tables in theINFORMATION_SCHEMAdatabase.
MySql tips
Wednesday, March 3, 2010
Get total rows in table --mysql
Transfer mysql DB from 10.1.1.100 to 10.1.1.111
Login 10.1.1.100 (user:root, passwd:xxx)
mysqldump -u root --password=xxxxxx -B Ror232_PROD_HR Ror232_PROD_SYS | mysql --host=10.1.1.111 -u subird --password=xxxxxx
Sunday, November 22, 2009
backup mysql data using mysqldump
此法必需輸入root passwd後方能執行
mysqldump (-h hostname) -u root --password=xxxx Ror232_PROD_HR
此法不需手動輸入root passwd
以上會Create Tables 但不會Create Databases
mysqldump (-h hostname) -u root --password=xxxx -B Ror232_PROD_HR Ror232_PROD_SYS |more
以上會Create Tables & Create Databases
Monday, December 15, 2008
Sample MySql statement
- SELECT mid(SerialNo,4,2) AS yr,TRUNCATE((mid(SerialNo,6,2)+2)/3,0) AS season, SUM(beforeTax) FROM DCT.DCT_SOMAIN WHERE mid(SerialNo,4,2) in ( '93','94','95','96','97' ) AND SUBSTRING_INDEX(Dept,'.',1) regexp 'FSS*' GROUP BY yr,season
各部門最近5年各年的業績比較
- SELECT SUBSTRING_INDEX(Dept,'.',1) AS dep,mid(SerialNo,4,2) AS yr, SUM(beforeTax) FROM DCT.DCT_SOMAIN WHERE mid(SerialNo,4,2) in ( '93','94','95','96','97' ) AND SUBSTRING_INDEX(Dept,'.',1) regexp '[HIPCF]SS+' GROUP BY dep, yr
Monday, December 8, 2008
如何Check Mysql Update是否有成功?
- 應可Check update的rows數量便可,若是0,就表示沒有資料被updated
UPDATE returns the number of rows that were actually changed. The mysql_info() C API function returns the number of rows that were matched and updated and the number of warnings that occurred during the UPDATE.
You can use LIMIT to restrict the scope of the row_countUPDATE. A LIMIT clause is a rows-matched restriction. The statement stops as soon as it has found row_count rows that satisfy the WHERE clause, whether or not they actually were changed.
- 另可使用mysql_affected_rows (PHP 4, PHP 5, PECL mysql:1.0)
mysql_affected_rows — Get number of affected rows in previous MySQL operation
Description
Get the number of affected rows by the last INSERT, UPDATE, REPLACE or DELETE query associated with link_identifier .
Parameters
- link_identifier
-
The MySQL connection. If the link identifier is not specified, the last link opened by mysql_connect() is assumed. If no such link is found, it will try to create one as if mysql_connect() was called with no arguments. If by chance no connection is found or established, an E_WARNING level error is generated.
Return Values
Returns the number of affected rows on success, and -1 if the last query failed.
If the last query was a DELETE query with no WHERE clause, all of the records will have been deleted from the table but this function will return zero with MySQL versions prior to 4.1.2.
When using UPDATE, MySQL will not update columns where the new value is the same as the old value. This creates the possibility that mysql_affected_rows() may not actually equal the number of rows matched, only the number of rows that were literally affected by the query.
The REPLACE statement first deletes the record with the same primary key and then inserts the new record. This function returns the number of deleted records plus the number of inserted records.
Examples
Example #1 mysql_affected_rows() example
= mysql_connect('localhost', 'mysql_user', 'mysql_password');
if (!$link) {
die('Could not connect: ' . mysql_error());
}
mysql_select_db('mydb');
/* this should return the correct numbers of deleted records */
mysql_query('DELETE FROM mytable WHERE id < 10');
printf("Records deleted: %d\n", mysql_affected_rows());
/* with a where clause that is never true, it should return 0 */
mysql_query('DELETE FROM mytable WHERE 0');
printf("Records deleted: %d\n", mysql_affected_rows());
?> The above example will output something similar to:
Records deleted: 10 Records deleted: 0
