Access denied for user 'root@localhost' (u

2019-01-01 13:23发布

I'm new to mysql, I'm trying to run Wordpress inmy windows desktop and it need Mysql.

I install everything with Web Platform Installer which provided by microsoft. I never seta root password for mysql and in final step of installing wordpressit askfor root password of mysql.

What is the default password for root (if there is one) and how to change it?

I try

mysql -u root password '123'

but it show me

Access denied for user 'root@localhost' (using password:NO)

after this I try

mysql -u root -p

but it ask for a password which I don't have

Thank you in advance


Update : as Bozho said I did the following

 1 - I stoped MySql Service from Windows services
 2 - Open CMD
 3 - change location to cd c:\program files\mysql\bin
 4 - write this command

 mysqld --defaults-file="C:\\program files\\mysql\\mysql server 5.1\\my.ini" --init-files=C:\\root.txt

 5 - Command run with a warning about characterset which I mentioned below
 6 - I start MySql Service from windows services
 7 - in command line I write

mysql -u root -p
EnterPassword: 123  // 123 was the password

8 - the commandline shows following bug

Access denied for user 'root@localhost' (using password:**YES**)

I'm waiting to hear from you.

12条回答
像晚风撩人
2楼-- · 2019-01-01 13:27
mysqladmin -u root -p password

enter your current password

then

enter your new password

查看更多
旧时光的记忆
3楼-- · 2019-01-01 13:29

Some times it just happens due to installation of Wamp or changing of password options of root user. One can use privilages-->root (user) and then set password option to NO to run the things without any password OR set the password and use it in the application.

查看更多
长期被迫恋爱
4楼-- · 2019-01-01 13:35

1) You can set root password by invoking MySQL console. It is located in

C:\wamp\bin\mysql\mysql5.1.53\bin by default.

Get to the directory and type MySQL. then set the password as follows..

    > SET PASSWORD FOR root@localhost = PASSWORD('new-password');

2) You can configure wamp's phpmyadmin application for root user by editing

C:\wamp\apps\phpmyadmin3.3.9\config.inc.php 

It looks like this:

        $cfg['Servers'][$i]['verbose'] = 'localhost';
        $cfg['Servers'][$i]['host'] = 'localhost';
        $cfg['Servers'][$i]['port'] = '';
        $cfg['Servers'][$i]['socket'] = '';
        $cfg['Servers'][$i]['connect_type'] = 'tcp';
        $cfg['Servers'][$i]['extension'] = 'mysqli';
        $cfg['Servers'][$i]['auth_type'] = 'config';
        $cfg['Servers'][$i]['user'] = 'root';
        $cfg['Servers'][$i]['password'] = 'YOURPASSWORD';
        $cfg['Servers'][$i]['AllowNoPassword'] = false;

The error "Access denied for user 'root@localhost' (using password:NO)" will be resolved when you set $cfg['Servers'][$i]['AllowNoPassword'] to false

Note: phpmyadmin is a separate tool which comes with wamp. It just provide a interface to MySQL. if you change my sql root's password, then you should change the phpmyadmin configurations. Usually phpmyadmin is configured to root user.

查看更多
与风俱净
5楼-- · 2019-01-01 13:36

I was getting the same error on OS X El captain. Mysql version 5.7 . I was able to connect to mysql with root after executing these steps.

Stop the mysql server

sudo mysql.server stop

Start mysql in safe mode

sudo mysqld_safe --skip-grant-tables

Using mysqld, Change the database to mysql and update the details for user 'root'.

show databases;
use mysql;
UPDATE mysql.user 
    SET authentication_string = PASSWORD('MyNewPass'), password_expired = 'N'
    WHERE User = 'root' AND Host = 'localhost';
exit;

After that kill the 'mysqld_safe' process and start mysql normally. You should be able to login to mysql using root and new password. SQL docs for more details

查看更多
与君花间醉酒
6楼-- · 2019-01-01 13:38

For MySQL 5.7. These are the below steps:

Stop your MySQL server completely. This can be done by accessing the Services window inside Windows XP and Windows Server 2003, where you can stop the MySQL service.

Open your MS-DOS command prompt using "cmd" inside the Run window. Inside it navigate to your MySQL bin folder, such as C:\MySQL\bin using the cd command.

Execute the following command in the command prompt: mysqld.exe -u root --skip-grant-tables

Leave the current MS-DOS command prompt as it is, and open a new MS-DOS command prompt window.

Navigate to your MySQL bin folder, such as C:\MySQL\bin using the cd command.

Enter mysql and press enter.

You should now have the MySQL command prompt working. Type use mysql; so that we switch to the "mysql" database.

Execute the following command to update the password:

update user set authentication_string=password('1111') where user='root';

查看更多
人气声优
7楼-- · 2019-01-01 13:38

In your code replace the 'root' with your Server username and password with your server password. For example if you have DB and your php files on the server http://www.example.com then obviously you would have to enter into this server site using your username and password.

查看更多
登录 后发表回答