How can I set a password for user in MySQL - mysql

I need a password for an user as Drupal's installation asks that. I'm totally newcomer on creating databases so I tried this:
CREATE DATABASE 'drupaltest';
CREATE USER 'jaakko'#'localhost' IDENTIFIED BY 'password';
But PHPMyAdmin says
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '`password`'
Could anyone say what queries should I put to make an user with password that Drupal's installation requires and what grants should the new user have?

What you have should work I think. The only things I can think of is maybe you have the wrong type of quotation marks or maybe it has an issue with you setting password to 'password'. Perhaps try set it to something else. If that doesn't work maybe try create the user and then in a separate statement set the password and see if / where it trips up. E.g.
CREATE USER 'jaakko'#'localhost';
SET PASSWORD FOR 'jaakko'#'localhost' = PASSWORD('newpass');
This will also store the password more securely since the hash value will be stored instead of just the plain-text.

Brent777's solution will work, but for added security I would suggest salting the hash with a salt_value.
SELECT users.id, users.name into #id, #name FROM users where users.name = 'jaakko';
CREATE USER 'jaakko'#'localhost';
SET #newpass = 'newpass';
SET PASSWORD FOR 'jaakko'#'localhost' = PASSWORD(concat(#id,#name,#newpass));
Otherwise it will be too easy to attack the password table.

Related

escape # in host name of mysql when dropping a user

I need a drop a user from my mysql server and the former admin created a very strange entry, user XXX # €€s#€%.
So, the normal syntax:
drop user 'nick'#"€€s#€%";
does not work, and it complains about:
Malformed hostname (illegal symbol: '#')
Is there a way around it without the risk of messing up with existing users? This is my work's mysql server and I don't really want to experiment/change much, if possible.
Thank you!
Added solution based on comments
UPDATE mysql.user SET host='test' WHERE user='nick'
DROP USER 'nick'#'test'

SQL Grant SELECT

I want to create a user and only allow them to use select statements on the cameracircle database. So I have the following code:
CREATE USER 'hoeym'#'localhost' IDENTIFIED BY 'password';
CREATE DATABASE cameracircle;
GRANT SELECT ON cameracircle TO 'hoeym'#'localhost';
But the phpmyadmin doesn't like that. If I run this it says there is an error cause I don't have a databases selected, and if I add in USE cameracircle; before the GRANT statement it says that there is no table inside the database with the same name as the database. What have I done wrong?
Before you issue a GRANT statement, check that the
derby.database.sqlAuthorization
property is set to true. The derby.database.sqlAuthorization property enables the SQL Authorization mode.
Solved it with
GRANT SELECT ON cameracircle.* TO 'hoeym'#'localhost';
phpMyAdmin lets you do this graphically. From the Users tab, look for Add User then don't select anything for the Global Privileges area. Go ahead and create the user, then edit the privileges. Halfway down the page there's a area for "Database-specific privileges" where you can specify the permissions on a database (or even table-) level.

How to use "RENAME USER" in MySQL 4.1.12?

MySQL 5.1 has a RENAME USER feature that would do what I want. But unfortunately I'm running MySQL 4.1.12.
What I want to do is just change the host part of the username. I want to change the User name from 'myUsername'#'localhost' to 'myUsername'#'123.45.%'.
Sorry to inform you but the host is not a part of the username but a separate field in the mysql users table . You need either to create another user with the same username (yes it is possible) or to update the host field value of the record of that user like something:
UPDATE mysql.user SET host = '123.45.%' WHERE user = 'myUsername';
Warning - this would update every record where username is equal to the given one additionally if it is needed you could specify another condition in the where clause.

Error 1449 in MySQL - Alternative Solutions?

Recently, I deleted a user account in MySQL assigned to my former boss. Then, some database functions like deleting records from tables he made weren't working, giving the following error:
#1449 - There is no '*username*'#'localhost' registered
Now, I added a new user with the same name (and diff. password) and it works fine with no errors. But, is there way to resolve this without an placeholder user account?
Try replacing the DEFINER of the function
First login to mysql as root#localhost
Then, substitute root#localhost as the DEFINER
UPDATE mysql.proc SET definer='root#localhost'
WHERE definer = '*username*#localhost';
In fact, you can look at all DEFINERs like this:
SELECT COUNT(1) DefinerCount,definer,type
FROM mysql.proc GROUP BY definer,type;
This will show you how many functions and procedures each user owns. If any other the reported DEFINERs no longer exist or are invalid, you can make root#localhost inherit them.
Give it a Try !!!
I had to remove and re-add the triggers for the affected tables. (I used phpMyAdmin to do this).

Randomise all password in MySQL table

I have a MySQL database with a table that contains usernames and passwords. I want a bash script or MySQL statement that will randomise all the passwords.
I can reset one password with something like
select md5(rand()) as password;
I can loop through with a bash read while loop. Just need help putting it all together.
Yews I know there should not be passwords stored in the clear, it's a legacy system we are moving people away from.
UPDATE `users` SET `password` = md5(rand())
I think you should be able to just CONCAT the current password into the md5, to keep them all unique.
UPDATE passwords SET password = md5(CONCAT(RAND(), password))