Monday, April 11, 2005

Adding a user to mySQL

$ cd /usr/local/mysql/bin

$ ./mysql -uroot -p

> use mysql;

> grant all on teamwork.* to hax0r@'localhost' identified by 'passwordhere';
> flush privileges;

If you get a client authentication error telling you to upgrade:
mysql> UPDATE user SET Password = OLD_PASSWORD('mypass')
-> WHERE Host = 'some_host' AND User = 'some_user';
mysql> FLUSH PRIVILEGES;

Even then I've had it not work because of multiple entries for the same user in other tables such as 'db' so if you're still having problems go through those.

Here's a php script to login:

echo('Starting\n');
// Set the database access information as constants.
DEFINE ('DB_USER', 'hax0r');
DEFINE ('DB_PASSWORD', 'passw0rd');
DEFINE ('DB_HOST', 'localhost');
DEFINE ('DB_NAME', 'j00rdb');
// Make the connnection and then select the database.
$dbc = mysql_connect (DB_HOST, DB_USER, DB_PASSWORD);
//$dbc = mysql_connect ('localhost','hax0r','passw0rd');

mysql_select_db (DB_NAME);

if (!$dbc) {
die('Could not connect: ' . mysql_error());
}
echo('\nDone, success!\n');
?>

No comments:

Labels

Blog Archive

Contributors