Skip to main content

Access denied for user 'root'@'localhost'

f you have that same problem in MySql 5.7.+ :
Access denied for user 'root'@'localhost'
it's because MySql 5.7 by default allow to connect with socket, which means you just connect with sudo mysql. If you run sql :
SELECT user,authentication_string,plugin,host FROM mysql.user;
then you will see it :
+------------------+-------------------------------------------+-----------------------+-----------+
| user             | authentication_string                     | plugin                | host      |
+------------------+-------------------------------------------+-----------------------+-----------+
| root             |                                           | auth_socket           | localhost |
| mysql.session    | *THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE | mysql_native_password | localhost |
| mysql.sys        | *THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE | mysql_native_password | localhost |
| debian-sys-maint | *497C3D7B50479A812B89CD12EC3EDA6C0CB686F0 | mysql_native_password | localhost |
+------------------+-------------------------------------------+-----------------------+-----------+
4 rows in set (0.00 sec)
To allow connection with root and password, then update the values in the table with command :
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'Current-Root-Password';
FLUSH PRIVILEGES;
Then run the select command again and you'll see it has changed :
+------------------+-------------------------------------------+-----------------------+-----------+
| user             | authentication_string                     | plugin                | host      |
+------------------+-------------------------------------------+-----------------------+-----------+
| root             | *2F2377C1BC54BE827DC8A4EE051CBD57490FB8C6 | mysql_native_password | localhost |
| mysql.session    | *THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE | mysql_native_password | localhost |
| mysql.sys        | *THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE | mysql_native_password | localhost |
| debian-sys-maint | *497C3D7B50479A812B89CD12EC3EDA6C0CB686F0 | mysql_native_password | localhost |
+------------------+-------------------------------------------+-----------------------+-----------+
4 rows in set (0.00 sec)
And that's it. You can run this process after running and completing the sudo mysql_secure_installation command.

Comments

Popular posts from this blog

Magento 2 generate custom log

the custom log file created using below code for Magento 2.4.2 before version use this :  $writer = new \Zend\Log\Writer\Stream (BP . '/var/log/custom.log' ); $logger = new \Zend\Log\Logger (); $logger -> addWriter ( $writer ); $logger -> info ( 'Custom message' ); $logger -> info ( print_r ( $object -> getData (), true )); for Magento 2.4.2 or after version use this :  $writer = new \Laminas\Log\Writer\Stream (BP . '/var/log/custom.log' ); $logger = new \Laminas\Log\Logger (); $logger -> addWriter ( $writer ); $logger -> info ( 'text message' ); $logger -> info ( print_r ( $object -> getData (), true )); for Magento 2.4.3 version use this $writer = new \Zend_Log_Writer_Stream (BP . '/var/log/custom.log' ); $logger = new \Zend_Log (); $logger -> addWriter ( $writer ); $logger -> info ( 'text message' ); $logger -> info ( print_r ( $object -> getData (), true )); Or you can try this : f...

TO Execute Multiple Raw Query In Magento 2

<?php         /*          *          * TO Execute Multiple Raw Query In Magento 2          *          * */ $objectManager = \Magento\Framework\App\ObjectManager::getInstance(); $resource = $objectManager->get('Magento\Framework\App\ResourceConnection'); $conn = $resource->getConnection('write'); $sqlScript = file($sqlFile); $query = ''; foreach ($sqlScript as $line) { $startWith = substr(trim($line), 0 ,2); $endWith = substr(trim($line), -1 ,1); if (empty($line) || $startWith == '--' || $startWith == '/*' || $startWith == '//') continue; $query = $query . $line; if ($endWith == ';') { $conn->query($query); $query= ''; } } echo '<div class="success-response sql-import-response">SQL file imported successfully</div>';

Magento 2 Change Core Config Value Programmatically

$objectManager = \Magento\Framework\App\ObjectManager::getInstance(); // Instance of object manager $cacheTypeList = $objectManager->get('\Magento\Framework\App\Cache\TypeListInterface'); $cacheFrontendPool = $objectManager->get('\Magento\Framework\App\Cache\Frontend\Pool'); $resource = $objectManager->get('Magento\Framework\App\ResourceConnection'); $connection = $resource->getConnection(); $table = $resource->getTableName('core_config_data'); $select = $connection->select()->from( $table, ['config_id', 'value'] )->where( 'path = ?', 'carriers/storepickup/active' ); $data = $connection->fetchAll($select); if ($data) { try { $connection->beginTransaction(); foreach ($data as $value) { if($storeId == 1){ $dvalue = !(bool)1; }else{ $dvalue = 1; } $bind = ['path' => 'carriers/storepickup/active', 'value' => $dvalue]; $whe...