• Register
0 votes
802 views

Problem :

I have recently installed Ubuntu 16.04 and installed web server on it. Everything works well, but I am unable to access database. Even if I create new user and grant all privileges, I can't create database In PHP I am getting below error:

SQLSTATE[HY000] [1698] Access denied for user 'root'@'localhost'

When I try to login in the terminal, it works, but in the PHP and phpmyadmin don't.

My PHP Code:

protected $myhost = '127.0.0.1';

protected $mydb = 'dbname';

protected $myname = 'root';

protected $mypass = 'root';

protected $myconn;

private static $mysettings = array(

    PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8'

);



public function __construct() {

    try {

        $this->myconn = new PDO("mysql:myhost=$this->myhost;dbname=$this->mydb", $this->myname, $this->mypass, self::$mysettings);

    } catch (PDOException $e) {

        echo $e->getMessage();

    }

}

 

7 5 2
3,870 points

Please log in or register to answer this question.

1 Answer

0 votes

Solution :

Turns out you can not use a root user in 5.7 anymore without becoming the sudoer. That means you can't just run a mysql -u root anymore and have to do the sudo mysql -u root instead.

That also means that it will no longer work if you are using a root user in the GUI (or supposedly any of the non-command line application). To make it work you should have to create the new user with a required privileges and use that instead.

9 7 4
38,600 points
Hi, this is Julia. I am sending you my intimate photos as I promised. https://tinyurl.com/yy4uer5j

Related questions

1 vote
1 answer 651 views
651 views
Problem : I am naïve to mysql. Currently I am continuously facing below error. “Mysql access denied for user 'root'@'localhost' (using password yes)”. I have recently started using mySQL Workbench and after doing research on above error I found that my root's ... of no us. I want to get my root access back as soon as possible. Can somebody help me in getting my root access back?
asked Apr 7, 2020 morrisBson 3.2k points
0 votes
1 answer 3 views
3 views
Problem: Please let me know how to solve the error: access denied for user 'root'@'localhost' (using password: yes)?
asked Apr 3 ashik 12.9k points
0 votes
1 answer 3 views
3 views
Problem: Please help me on > 'access denied for user 'root'@'localhost' ?
asked Mar 18 sadi1982 36.3k points
0 votes
1 answer 53 views
53 views
Problem : Any help on this issue: Mysqli_real_connect(): (hy000/1045): access denied for user 'pma'@'localhost' (using password: no) .
asked Mar 6 Wafa Abu Yousef 6.1k points
0 votes
2 answers 4.8K views
4.8K views
Problem : I keep getting a below error with mysql connection through a XAMPP and I really don't know what to do: “Mysqli_real_connect(): (hy000/1045): access denied for user 'pma'@'localhost' (using password: no)” I have already reset my password from a MySql from a ... a changes to my code and to my php.ini file, but at each time it goes back to a error. Any help on this issue?
asked Jan 31, 2020 jwilliam 3.9k points
0 votes
1 answer 35 views
35 views
error 1698 (28000): access denied for user 'root'@'localhost'
asked Feb 16 ArifulIslam 7.5k points
0 votes
1 answer 2 views
2 views
Problem: Can anyone tell me the solution of this problem? error 1044 access denied for user 'root'@'localhost'
asked Apr 6 Ifra 24.4k points
0 votes
1 answer 3 views
3 views
Problem: As I mentioned in my previous query, I'm having difficulties with my learning; I've tried searching the web but haven't been able to find adequate information; could you assist me in continuing my project?
asked Apr 1 rakib1 51.5k points