Tag Archives: mysql

Frequently used MySQL commands (UTF-8 safe)

MySQL dump

mysqldump -u user -p database -r file.sql
to dump just the structure
mysqldump -u user -p --no-data database -r

MySQL import

mysql -u user -p --default-character-set=utf8 database

mysql> SOURCE file.sql

alternatively
mysql -u user -p --default-character-set=utf8 database < file.sql

MySQL string function

CONCAT

CONCAT('hi',' ','there','!')
UPDATE `table` SET `field`=CONCAT(`field`,'\r\nend')

REPLACE

REPLACE(field,'find','replace')
UPDATE `table` SET `field`=REPLACE(`field`,'hi','hello')