LAMP How To – Open Source At Work

Only Passion Matters

Entries for the ‘Think SQL’ Category

Quick Mysql Tips

Logging slow queries
To enable the slow query log, start mysqld with the –log-slow-queries[=file_name] option. Use the mysqldumpslow command to summarize the queries that appear in the log. For example:
mysqldumpslow /path/to/your/mysql-slow-queries.log -t 10

shows you top 10 performance killers.
Lost Password

shutdown mysql, then

mysqld –skip-grant-tables –u root
mysql -u root
mysql> use mysql;
mysql> UPDATE [...]

submitting a form using hyperlinks

If using hyperlink to submit form, remember to return false in “onclick” so that it is backward compatible with IE6, ie
<a class=”button_next” href=”javascript:;” onclick=”$(‘#form_wizard’).submit();return false;”>
<span>Update</span>
</a>

bash: passing output from one program to another

sometimes you want to be able to pass output from one program to another, say from bash to php. There is a neat trick to do it. In php, we execute the bash script restartapache.
<?php
$command=”/usr/local/bin/restartapache {$_GET['server']}”;
exec($command, $output); foreach ($output as $v)
{ echo “$v <br/>”; }
?>
then in the bash, we write the output to a [...]

Removing Foreign Key Constraints In MYSQL

Some Mysql db is using innoDB which implements foreign key contraints. If you can’t drop or alter a table, check that it doesnt have foreign key contraints. Well, innoDB can be an angel or devil…
In mysql command line, check existence of foreign keys

show create table demographic_type
CREATE TABLE `demographic_type` (
`id` int(10) unsigned NOT NULL auto_increment,
`user_group_id` varchar(255) [...]

Retrieve Lost Password in MYSQL

Sometime, we forget the root password for mysql. It happened to me once in my company. The previous developer left and didn’t document where to look for passwords. Well, it is possible for the root user of the system to reset it anyway…
First shutdown mysql,
/etc/init.d/mysql stop
then
mysqld –skip-grant-tables –u root
mysql -u root
mysql> use mysql;
mysql> UPDATE [...]