Forum Moderators: coopster
$conex = mysql_connect($hostname, $username, $password);
if (!$conex) {
die('Can not connect to MySQL: '. mysql_error());
}
echo 'Connection ok';
$query = 'CREATE DATABASE dbname';
if (mysql_query($query, $conex)) {
echo 'Database created;
} else {
echo 'Error: ' . mysql_error();
}
mysql_close($conex);
?>
But with this script the database is not created. Instead of it, it appears:
Connection okError: Access denied for user 'a_username'@'localhost' to database 'dbname'
**So I do this:
STEP 1: I write in MySQL environment:
mysql>Grant all on dbname.* to a_username@localhost
->identified by 'a_password';
but unfortunately this message appears:
Warning: mysql_connect(): Client does not support authentication protocol requested by server; consider upgrading MySQL client in C:\Archivos de programa\Apache Group\Apache2\htdocs\xx1.php on line 7
Cannot connect to MySQL: Client does not support authentication protocol requested by server; consider upgrading MySQL client
STEP 2: So I write this also in MySQL environment:
mysql> UPDATE mysql.user SET Password = OLD_PASSWORD('a_password')
-> WHERE Host = 'localhost' AND User = 'a_username';
mysql> FLUSH PRIVILEGES;
**And then finally the database is created!
But here begins the rare thing: If I want to create a second database in PHP, I cannot: I must do again all the above MySQL commands, that is Step 1 and 2 together. If I want to create a third database, I must do ALL Step 1 and 2 again, and so no...
Dear folks: Why does it happen and, the most important, how can I solve it? I remember that some time ago I had a similar problem: I could connect to MySQL via command line but could not connect in PHP, and in this Forum you recommend to use STEP 2 (Update mysql.user and so on...) and it worked well, although i have never known why and for what I had to do it, if my PHP and MySQL versions were apparently ok. But now I can only connect but not create databases...
Finally I must say that I connect to MySQL in DOS in this way:
Shell>mysqld.exe
shell>mysql -u=a_username -p=a_password
I have read that the normal is connecting with mysql.exe (without D, daemon), but when I did do I could not connect well, and I have never understood why...
Is this type of connection affecting in a some way? I have read a lot in manuals but I do not find the way to solve it. Must I Upgrade to MySql 4.4.0 or 5.0.4? What do you think? - Thank you very much