Error java. SQL. sqlexception: Access denied for user 'root' @ 'localhost' (using PA

Source: Internet
Author: User

I found some ways on the Internet:

 

 

  1. C: \> mysql-u root-P
  2. Enter Password :******
  3. Welcome to the MySQL monitor. Commands
    End;
    Or \ G.
  4. Your MySQL connection ID is 2
  5. Server version: 5.1.22-RC-Community-log MySQL Community Server (GPL)
  6. Type 'help; 'or
    '\ H' for help. Type
    '\ C' to clear the buffer.
  7. Mysql> grant all
    Privileges on *.*
    To 'username' @ '%' identified
    By 'Password ';
  8. Query OK, 0 rows affected (0.05 Sec)
  9. Mysql> flush privileges;
  10. Query OK, 0 rows affected (0.06 Sec)
  11. Mysql> exit
  12. Bye
C:\>mysql -u root -p  Enter password: ******  Welcome to the MySQL monitor.  Commands end with ; or \g.  Your MySQL connection id is 2  Server version: 5.1.22-rc-community-log MySQL Community Server (GPL)  Type 'help;' or '\h' for help. Type '\c' to clear the buffer.  mysql> grant all privileges on *.* to 'username'@'%' identified  by'password';  Query OK, 0 rows affected (0.05 sec)  mysql> flush privileges;  Query OK, 0 rows affected (0.06 sec)  mysql> exit  Bye  

The better solution is to change the user name. Do not use root as a good solution.

Code 1045
Access denied for user 'root' @ 'localhost' (using password: Yes)

If the above prompt appears in your MySQL, I suggest you read this article one by one and try the following methods to solve the problem.

This is a problem that occurs frequently in MySQL databases. There are many solutions available on the Internet. Some people can solve the problem by following these methods, but many people cannot solve the problem by following these methods! The reason is that there is no right remedy !!!

Many of the methods on the Internet do not explicitly specify the version of MySQL. Therefore, the problem cannot be solved.

This problem can be solved by stopping/restarting the MySQL service. This is the simplest solution! For those who do not know what it is called "Stop/restart MySQL service", the simplest way is to restart the server host (that is, restart your computer ).

The above is method! (This method is suitable for any version of MySQL)

The following is method B: (The method only applies to MySQL 4.0.26 !!! (I guess other versions of 4.0 should also work ))

It is also said on the Internet that it is to re-change the password of the root user. It is also feasible to change the password circulating on the Internet. refer to the following:

Change the root password under DOS: of course, after phpMyAdmin is installed, you can also change the password through phpMyAdmin.

Format: mysqladmin-u username-P old Password New Password

For example, add the password ideacmblog to the root user.

First, go to the CMD command line, go to the bin directory under the MySQL directory, and then type the following command

Mysqladmin-uroot password ideacmblog

Note: because the root account does not have a password at the beginning, the old-P password can be omitted.

D: \ PHP \ mysql \ bin> mysqladmin-uroot password ideacmblog press enter and set the root password to ideacmblog.

However, please note that the above method only applies to MySQL 4.0.26 !!! (I guess other versions of 4.0 should also work)

Method C:

Okay, so much. None of the above two methods have been tested by me. I am not responsible for authenticity!

Now I will talk about the methods I personally tried for your reference:

Today, all PHP and MySQL database websites on my server are suspended! Unable to open, with the following prompt:

Code 1045
Access denied for user 'root' @ 'localhost' (using password: Yes)

At the beginning, I also kept searching for Google (I do not like Baidu !), Find a solution. after reading a lot of data, I also referred to the execution. In fact, it cannot solve the problem. later I thought about the version issue. The solutions for different MySQL versions are not necessarily the same !! Remember...

My mysql version is: 5.0.22 (mysql-essential-5.0.22-win32)

All these PHP websites went on strike all day today. It was not until tonight that I had time to go to the server to continue searching for a solution, but it still could not be solved.

Finally, I decided to uninstall MySQL and reinstall it!

Unmount quickly and do not need to restart the computer.

So, continue to install.

Step 1: Open this mysql-essential tial-5.0.22-win32.exe file;

Step 2: In the displayed window, clickNEXT> proceed to the next step;

Step 3: Select CuSTom item, and click
NEXT> proceed to the next step;

Step 4: Pay attention to this step. ClickCHange... select the directory of your original MySQL installation. ClickNEXT> proceed to the next step;

Step 5: ClickIInstall nstall...

After the installation is completed to the next step, you will be prompted to register. Select the last entry, that is, skip the registration and go to the next step to complete the installation.

After the installation is complete, a window is displayed, prompting you to configure immediately. Select next

Select standard configuration. Click Next to go to the next step.

In this step, the above line is removed, only the include... path line is checked, continue to click Next to go to the next step.

In this step, click "Ex *****" in the middle and complete the configuration!

Now, are you going to see if your MySQL is normal ?? !!

So OK !!!

 

 

Several possibilities:
1. the user name and password are incorrect, so they cannot be accessed.
2. IP access permissions are set on the Database End and cannot be accessed using localhost. Try changing to a specific IP address.
3. Related operation permissions are set on the database. the user does not have the create permission.

 

 

In fact, this may be because I did not notice that some passwords were not set during MySQL installation:

To start mysqld at boot time you have to copy
Support-files/MySQL. Server to the right place for your system

Please remember to set a password for the MySQL Root User!
To do so, start the server, then issue the following commands:

/Usr/bin/mysqladmin-u Root Password 'new-password'
/Usr/bin/mysqladmin-u root-H istore01 password 'new-password'

Alternatively you can run:
/Usr/bin/mysql_secure_installation

Which will also give you the option of removing the test
Databases and anonymous user created by default. This is
Stronugly recommended for production servers.

 

You just need to execute the red part, that is, re-set the password, and find a lot of methods on the internet, regardless of the use, it seems that it is better to install the software later.

 

 

 

 

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.