MySQL database user permission table loss Solution

Source: Internet
Author: User

When installing software, you need to useMysql databaseTo create a database and corresponding users in the database, execute the database creation script. The database is successfully created, but an error occurs during user authorization:

 
 
  1. createdatabasecactidb;  
  2.  
  3. grantalloncactidb.*toroot@localhost;  
  4.  
  5. grantalloncactidb.*tocactiuser; 

This is nothing, but I alreadyRoot @ localhostThis user has been deleted. I have left only the user with the username "root" and the host name "%". For convenience, I only use the root user to log on to the local machine, my mysql only listens to the address 127.0.0.1. Result 1: grantalloncactidb is executed. * toroot @ localhost; the command is finished immediately. I can only log on to the root account of the root @ localhost user in this instance, instead of the common root @ % user, however, root @ localhost basically has no permissions. According to the Mysql authorization mechanism, I can use root @ % only when logging on to other hosts, and I cannot log on from other addresses at all, I am in a hurry. Due to the strict firewall policy, it is impossible for me to open the mysql port. Later, I found relevant information on the Internet and used the following methods to solve the problem:

1. Close the mysql service: servicemysqldstop.

2../mysqld_safe -- skip-grant-tables to restart mysql.

3. log on to the Apsara stack console again with the root account. No Password is required.

4. After logging on, delete the root @ local user.

5. Use ps to find the mysqld process and kill it to stop the mysql process.

6. Restart the mysql process: servicemysqldstart.

7. You can also reset the root password by using this method: setpasswordforroot = passwordyourpass ');

8. You can also reset the root user permission.

 
 
  1. updatedbsetSelect_priv='Y'whereuser='root';  
  2.  
  3. updatedbsetInsert_priv='Y'whereuser='root';  
  4.  
  5. updatedbsetUpdate_priv='Y'whereuser='root';  
  6.  
  7. updatedbsetDelete_priv='Y'whereuser='root';  
  8.  
  9. updatedbsetCreate_priv='Y'whereuser='root';  
  10.  
  11. updatedbsetDrop_priv='Y'whereuser='root';  
  12.  
  13. updatedbsetReferences_priv='Y'whereuser='root';  
  14.  
  15. updatedbsetGrant_priv='Y'whereuser='root';  
  16.  
  17. updatedbsetIndex_priv='Y'whereuser='root';  
  18.  
  19. updatedbsetAlter_priv='Y'whereuser='root';  
  20.  
  21. updatedbsetCreate_tmp_table_priv='Y'whereuser='root';  
  22.  
  23. updatedbsetLock_tables_priv='Y'whereuser='root';  
  24.  
  25. updatedbsetCreate_view_priv='Y'whereuser='root';  
  26.  
  27. updatedbsetGrant_priv='Y'whereuser='root';  
  28.  
  29. updatedbsetShow_view_priv='Y'whereuser='root';  
  30.  
  31. updatedbsetCreate_routine_priv='Y'whereuser='root';  
  32.  
  33. updatedbsetAlter_routine_priv='Y'whereuser='root';  
  34.  
  35. updatedbsetExecute_priv='Y'whereuser='root'; 

Set all fields of the root user in the mysql. user table to 'y '.

Note:When you use -- skip-grant-tables to start mysql, you cannot use the grant command. Therefore, you only need to manually set the permission table.

For more information about the MySQL permission table

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.