JackSun
JackSun

Reputation: 1478

How to change mysql username and password

I have installed MySQL on my mac v10.8.5, with the default username='' and password=''.

How do I change these to username='root' and password='root'?

Upvotes: 1

Views: 8698

Answers (2)

Devart
Devart

Reputation: 121922

You cannot rename user. In your case you need to add new user using such statements -

CREATE USER 'root'@'%';
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' WITH GRANT OPTION;
SET PASSWORD FOR 'root'@'%' = PASSWORD ('root');

Upvotes: 3

neshpro9
neshpro9

Reputation: 434

Follow thid step:

Stop MySQL

sudo /usr/local/mysql/support-files/mysql.server stop

Start it in safe mode:

sudo mysqld_safe --skip-grant-tables

This will be an ongoing command until the process is finished so open another shell/terminal window, log in without a password:

mysql -u root

UPDATE mysql.user SET Password=PASSWORD('password') WHERE User='root';

Change the lowercase password to what you want – with single quotes.

FLUSH PRIVILEGES;

 \q

Start MySQL

sudo /usr/local/mysql/support-files/mysql.server start

Reference

Upvotes: 6

Related Questions