Perfect solution: Accessdeniedforuser 'root' @ 'localhost'

Source: Internet
Author: User
This problem has been around me for several hours. check the problem. Summary: permission issues. So how to authorize? Step 1: stop the service. command line:/etc/init. d/mysqlstop if not, execute the next line: servicemysqldstop report: Stoppingmysqld: [OK] Step 2: Skip password verification and execute the command line: #/usr/bin/mys this problem has been around for several hours. check the problem.

Summary: permission issues. So how to authorize?
Step 1: stop the service
Command line:
/Etc/init. d/mysql stop
If not, execute the following line:
Service mysqld stop
Report:
Stopping mysqld: [OK]

Step 2: Skip password verification
Execute the command line:
#/Usr/bin/mysqld_safe -- skip-grant-tables
Report:
151104 09:07:56 mysqld_safe Logging to '/var/lib/mysql/iZ23dq2wm0jZ. err '.
151104 09:07:56 mysqld_safe Starting mysqld daemon with databases from/var/lib/mysql

Step 3: log on without a password
Execute the command line:
Mysql-u root

Step 4: authorize
Mysql> grant all privileges on *. * to 'root' @ 'localhost' identified by 'root' with grant option;
Key words:
Root '@ 'localhost: User
Root: password

Problem 1: no authorized write permission is found without a password
The MySQL server is running with the -- skip-grant-tables option so it cannot execute this statement
Solution:
Mysql> set global read_only = 0; // (disable the read-only attribute of the new master database)
Mysql> flush privileges;

 

Mysql> set global read_only = 1; // (read/write attribute)
Mysql> flush privileges; (note that refresh is required)

Step 5: Restart the database
Service mysqld stop
Report:
Stopping mysqld: [OK]

Service mysqld start
Report:
Starting mysqld: [OK]
Or
Service mysqld restart
Related Article

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.