LAMP How To – Open Source At Work

Only Passion Matters

Entries Tagged ‘MYSQL’

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 [...]

Share and Enjoy:
  • Digg
  • del.icio.us
  • Facebook
  • Google
  • StumbleUpon
  • Technorati
  • LinkedIn
  • MySpace
  • Slashdot
  • TwitThis
  • Yahoo! Buzz

Quick script to sort mysql database/tables based on table size

Mysql can show the table status with the row and size for each table but doesn’t do sorting. We can however store each row in an array and sort the array.
I am too lazy to write a script for it. 2 x for loops does the trick. This script is from adamyoung.net. Just run the [...]

Share and Enjoy:
  • Digg
  • del.icio.us
  • Facebook
  • Google
  • StumbleUpon
  • Technorati
  • LinkedIn
  • MySpace
  • Slashdot
  • TwitThis
  • Yahoo! Buzz

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) [...]

Share and Enjoy:
  • Digg
  • del.icio.us
  • Facebook
  • Google
  • StumbleUpon
  • Technorati
  • LinkedIn
  • MySpace
  • Slashdot
  • TwitThis
  • Yahoo! Buzz

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 [...]

Share and Enjoy:
  • Digg
  • del.icio.us
  • Facebook
  • Google
  • StumbleUpon
  • Technorati
  • LinkedIn
  • MySpace
  • Slashdot
  • TwitThis
  • Yahoo! Buzz