(28000): Access denied for user 'root' @ '1970. 0.0.1 '(using password: YES), 127 denied

Source: Internet
Author: User

(28000): Access denied for user 'root' @ '1970. 0.0.1 '(using password: YES), 127 denied

 

When you test the Python script on a test server, the following error is reported when you execute the Python script:

 

 

The main error message is "operation the SQL fail! 1045 (28000): Access denied for user 'root' @ '2017. 0.0.1 '(using password: YES )". Some test scripts are as follows. The host of mysql. connector. connect is 127.0.0.1 and other account information is desensitized.

 

def record_server_info():
    try:
        server_ip = get_host_ip();
 
        server_name= str.strip(get_host_name());
 
        server_system=platform.system();
 
        linux_dis =platform.linux_distribution();
        os_version =''
        os_version = ' '.join(linux_dis)
 
        os_bitinfo = platform.architecture()
        os_bit =os_bitinfo[0][0:2]
 
        processor = str.strip(commands.getoutput("cat /proc/cpuinfo | grep name | cut -f2 -d: | uniq -c"))
 
        cpu_slot= commands.getoutput("cat /proc/cpuinfo | grep 'model name' | sort | uniq | wc -l");
 
        cpu_core =  multiprocessing.cpu_count();
 
        processor_core =int(cpu_core)/int(cpu_slot);
 
        memory = get_physical_memory()
 
        disk_space = get_disk_info()["capacity"]/1024/1024;
  
 
        dbcon = mysql.connector.connect(
            host='127.0.0.1',
            user='root',
            passwd='123456',
            database='mysql'
        )
        cursor = dbcon.cursor()
        sql_tex =( "insert into db_server_info("
                   "factory_cd      ,"
                   "server_name     ,"
                   "server_ip       ,"
                   "server_type     ,"
                   "server_system   ,"
                   "is_production   ,"
                   "os_version      ,"
                   "os_patch        ,"
                   "os_bit          ,"
                   "processors      ,"
                   "cpu_slot        ,"
                   "processors_core ,"
                   "memory          ,"
                   "disk_space      ,"
                   "server_purpose)  "
                   "values(%(factory_cd)s,%(server_name)s,%(server_ip)s,%(server_type)s,%(server_system)s,%(is_production)s,%(os_version)s,%(os_patch)s,%(os_bit)s,%(processors)s,%(cpu_slot)s,%(processors_core)s,%(memory)s,%(disk_space)s,%(server_purpose)s)")
        data={'factory_cd':factory_cd, 'server_name':server_name, 'server_ip':server_ip,"server_type":server_type,"server_system":server_system,"is_production":is_productin,"os_version":os_version, "os_patch":'',"os_bit":int(os_bit), "processors":processor,"cpu_slot":cpu_slot, "processors_core":processor_core,"memory":memory,"disk_space":disk_space,"server_purpose":''}
 
        cursor.execute('truncate table db_server_info')
        dbcon.commit()
        cursor.execute(sql_tex, data)
        dbcon.commit()
 
    except mysql.connector.Error as e:
        print('operation the sql fail!{0}'.format(e))
    finally:
        cursor.close;
        dbcon.close;

 

 

Mysql-u root-p test login to MySQ found no problem, but a check found that if the host is not specified, the current user is root @ localhost, while root @ '127. 0.0.1 'password is blank.

 

mysql> select current_user();
+----------------+
| current_user() |
+----------------+
| root@localhost |
+----------------+
1 row in set (0.00 sec)
 
mysql> show grants for root@'localhost';
+---------------------------------------------------------------------------------------------------------------------------+
| Grants for root@localhost                                                                                                 |
+---------------------------------------------------------------------------------------------------------------------------+
| GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' IDENTIFIED BY PASSWORD '*9B67EF98D94F2B81011D6D2CEDE4' WITH GRANT OPTION|
| GRANT PROXY ON ''@'' TO 'root'@'localhost' WITH GRANT OPTION                                                              |
+---------------------------------------------------------------------------------------------------------------------------+
2 rows in set (0.00 sec)
 
mysql> show grants for root@'127.0.0.1';
+---------------------------------------------------------------------+
| Grants for root@127.0.0.1                                           |
+---------------------------------------------------------------------+
| GRANT ALL PRIVILEGES ON *.* TO 'root'@'127.0.0.1' WITH GRANT OPTION |
+---------------------------------------------------------------------+
1 row in set (0.00 sec)
 
mysql> 

 

Check the configuration of my. cnf immediately and find that the skip-name-resolve parameter is set for a test. Because the '-- skip-name-resolve' parameter is used to start mysqld, 127.0.0.1 and localhost are different hosts for mysql Databases because domain name resolution is not performed, and root @ '100. 0.0.1 'is an empty password, so the error "(28000): Access denied for user 'root' @ '127" is returned when the Python script is executed. 0.0.1 '(using password: YES )"

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.