How to use "RENAME USER" in MySQL 4.1.12? - mysql

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.

Related

MySql: Restrict update permission on one column in one table

I have a table, lets call it student, in a schema called enrollment. Table student has a column called address that I don't want a certain user to update (other permissions are fine such as select, insert). All other columns in that table AND in that schema should have the update privilege.
Is this doable?
You can set privileges on database / table / column. But I really would not try to use MySQL's privilege mechanism at that level. I would instead write application code to decide who can see/change what. This is more flexible in the long run. And more graceful to the user -- instead of getting a cryptic MySQL error message about permissions, the UI would simply not show what should not be shown. For updating, the UI would not even give the user the option.
In my case, I wanted a specific application to be able to update only 1 field (my_field) in only 1 table (table_name) while being able to read the entire database.
I created a special user for that purpose:
CREATE USER 'restrictedUser'#'%' IDENTIFIED BY 'PASSWORD_HERE';
SET PASSWORD FOR 'restrictedUser'#'%' = PASSWORD('PASSWORD_HERE');
GRANT USAGE ON *.* TO 'restrictedUser'#'%';
GRANT SELECT ON DATABASE_NAME.* TO 'restrictedUser'#'%';
GRANT UPDATE (my_field) ON DATABASE_NAME.table_name TO 'restrictedUser'#'%';
Documentation for Column privilege can be found here for mariaDb and here for mysql

Note Code : 1973 Can't create user 'user'#'localhost'; it already exists, Mysql

once I created a user named 'dscl' and deleted afer few days. Now when I am trying to create a user named 'dscl'it is showing me an error message as below.
Note Code : 1973 Can't create user 'dscl'#'localhost'; it already exists
I executed a query (select * from mysql.user;) to check user list and it is not showing any user named 'dscl'.
What could be the cause?
Did you forget to FLUSH PRIVILEGES after altering the grant table?
You should do so now, so that the change (deleting dscl) is loaded into the server's memory.
Re-adding the user should then work.

MyBB Multiple user creation using mysql

Multiple user creation mysql
I and some friends created a forim a long time ago. We had some users and made a list with their usernames but unfortunately our website was hijacked and lost access to the database. The question I want to know is if there is a possibility that a command on phpmyadmin exists that will create multiple users at the same time from a list.
My steps so far:
CREATE USER 'jeffrey'#'localhost' IDENTIFIED BY 'mypass';
All you have to do is :-
Insert into mybb_users SET username='some_username', email='email_of_person' , password = '098f6bcd4621d373cade4e832627b4f6', salt = '';
You can also fill other column of user table of your choice.

Mysql temporary table for different users

Is there any table type that can only be accessed by a particular user?
This table can only be viewed and accessed only by the user who created it
Yes you can.
But you can create a table that has user created column so you can use it on your where condition.
I think the answer is Yes
You can set privileges for that particular table like who can access that table. Like,
SELECT, INSERT, UPDATE, DELETE, .
I have tried in via phpmyadmin.
I was wrong. Yes you can set user specific access for particular table. Its syntax is as follow
GRANT SELECT ON db2.invoice TO 'jeffrey'#'localhost';
Temporary tables are available under particular session and not accessible by any other session. It will be dropped on session close.
For more information read http://dev.mysql.com/doc/refman/5.5/en/grant.html

How can I set a password for user in 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.