Start > Linux Tips & Trics > Mysql character set

Mysql character set

26 januari 2007

Today I had this problem with a MySQL/php application:

Illegal mix of collations (latin1_bin,IMPLICIT) and (latin1_swedish_ci,IMPLICIT)

I’ve created this loop to solve the problem, because the server contains several database with lots of tables:

  1. passwd="yeah right!"
  2. mysql="mysql -u root -p"$passwd" -ss -B -e"
  3. $mysql "show databases"|while read db; do
  4. $mysql "SHOW TABLES FROM $db"|while read table; do
  5. if [ "$($mysql "show create table $db.$table"|grep -c latin1_bin)" != "0" ]; then
  6. $mysql "ALTER TABLE $db.$table CONVERT TO CHARACTER SET  latin1"
  7. fi
  8. done
  9. done
Categorieën:Linux Tips & Trics Tags:
Geen reacties mogelijk.