Posts Tagged ‘mysql’

install mysql server on CentOS

April 7th, 2010

yum install mysql-server mysql php-mysql

chkconfig –levels 235 mysqld on

/usr/bin/mysql_secure_installation

/usr/bin/mysqladmin -u root password ‘new-password’
/usr/bin/mysqladmin -u root -h localhost password ‘new-password’

php 5.3:connection failed:SQLSTATE[HY000] [2000] mysqlnd cannot connect to MySQL 4.1+ using old authentication

March 30th, 2010

when i using php 5.3.2 to connect to a remote msyql server, I got this error

connection failed:SQLSTATE[HY000] [2000] mysqlnd cannot connect to MySQL 4.1+ using old authentication

this’s because in php5.3, the php_mysql; php_pdo_mysql use an enhanced security password, but in my remote server, still using old password format for compatibility with mysql 3.x

the solution is to disable the old_passords in my.cnf

[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
# Default to using old password format for compatibility with mysql 3.x
# clients (those using the mysqlclient10 compatibility package).
# coment out this line or set old_passwords = 0
old_passwords=1

then update all the user password you need.

update user set password=PASSWORD('new password') where user='this user';
flush privileges;

last step, remember to restart mysql.:-)

how to change MySQL database data to utf-8

February 23rd, 2010

1.) Dump the DB:
mysqldump –user=username –password=password –default-character-set=latin1 –skip-set-charset dbname > dump.sql

2.) Replace all latin1 instances with utf8:
sed -r ’s/latin1/utf8/g’ dump.sql > dump_utf.sql

3.) Delete the old DB, create a new one in UTF8:
mysql –user=username –password=password –execute=”DROP DATABASE dbname; CREATE DATABASE dbname CHARACTER SET utf8 COLLATE utf8_general_ci;”

4.) Load the dump into the new DB:
mysql –user=username –password=password –default-character-set=utf8 dbname < dump_utf.sql