23

I have installed MySQL Server 5.0 on my machine (Windows-7 OS).

My existing USERNAME And PASSWORD for MySQL is root. I want to change both USERNAME And PASSWORD.

Many people have asked this question before but none was useful for me. Can anybody
tell me HOW and from WHERE can I change it?

Community
  • 1
  • 1
Dnyanesh M
  • 1,349
  • 4
  • 18
  • 46

6 Answers6

41

Just execute this query from mysql console:

 UPDATE mysql.user SET user='newusername',
 password=PASSWORD('newpassword') WHERE user='root';
 FLUSH PRIVILEGES;
Mad Dog Tannen
  • 7,129
  • 5
  • 31
  • 55
Ghigo
  • 2,312
  • 1
  • 18
  • 19
8

Instructions

  1. Click the Windows "Start" button and type "cmd" in the search text box. Press Enter to open the Windows command line.

  2. Type "mysql" and press Enter to start the MySQL command line utility. Using the MySQL command line, you can update the tables on the database.

  3. Type the following SQL code to update the root user:
    UPDATE mysql.user SET user='newuser' WHERE User = 'root';
    Change newuser with the value you want to use in place of root

  4. Type the following SQL code to change the default user's password:
    UPDATE mysql.user SET authentication_string = password('pass') WHERE User = 'newuser';
    Replace pass with the new password, and replace newuser with the name of the user you set up in the previous step.

Read more

To change UserName and Password from mysql console

Louys Patrice Bessette
  • 33,375
  • 6
  • 36
  • 64
Amarnath Balasubramanian
  • 9,300
  • 8
  • 34
  • 62
4

USE THIS CMD IN MYSQL CONSOLE OR CMD

STEP 1: mysql> use mysql;

STEP 2: CREATE USER 'username'@'localhost' IDENTIFIED BY 'mypass';

Nambi
  • 11,944
  • 3
  • 37
  • 49
3

I'll suggest to stay with a root user and change the password if you want. Having a root user is convenient and renaming it is debatable (see this conversation). Plus, calling it 'root' is not that "unsecured" if you respect good practices (such as IP/hostname restriction).

Conclusion : change the root password and secure access to your server if you still feel unconfortable. Then, create another user with USERNAME as the login and PASSWORD as the password.

  1. To change the root password (in a MySQL Console) :

    UPDATE mysql.user SET Password=PASSWORD('YOURPASSWORDHERE') WHERE User='root'; FLUSH PRIVILEGES;

  2. To create a new user : http://dev.mysql.com/doc/refman/5.0/fr/create-user.html

  3. If your root user has a lot of privileges you don't want to replicate manually to the newly created user, then using a stored procedure could be a good solution : Copy user privileges between databases on the same server

Community
  • 1
  • 1
foobar
  • 926
  • 6
  • 21
3

There are special MySQL commands:

  1. RENAME USER
  2. SET PASSWORD
Devart
  • 119,203
  • 23
  • 166
  • 186
1

I not sure if you can change the username, you could drop it and create antoher one instead but not sure if update is possible.

Login to the commandline promt.

Set the mysql database

USE mysql;

Create the new user first if root is your only username

CREATE USER 'newusername'@'localhost' IDENTIFIED BY 'newpass';

Then drop the old root

DROP user root;

http://dev.mysql.com/doc/refman/5.0/en/user-names.html

http://dev.mysql.com/doc/refman/5.0/en/create-user.html

Mad Dog Tannen
  • 7,129
  • 5
  • 31
  • 55