Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in SQL by (6.1k points)

I installed a web server on Ubuntu 16.04. It worked fine, but I am unable to access the database. If I create a new user and grant all privileges, I can't create database In PHP I'm getting the following error:

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

Phpmyadmin is not working. 

PHP Code:

protected $host = '127.0.0.1';

protected $db = 'dbname';

protected $name = 'root';

protected $pass = 'root';

protected $conn;

private static $settings = array(

    PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8'

);

public function __construct() {

    try {

        $this->conn = new PDO("mysql:host=$this->host;dbname=$this->db", $this->name, $this->pass, self::$settings);

    } catch (PDOException $e) {

        echo $e->getMessage();

    }

}

1 Answer

0 votes
by (11.7k points)

It is pretty simple that you cannot use root user in 5.7 anymore without becoming a sudoer. This signifies that you cannot run mysql -u root anymore and have to do sudo mysql -u root instead.

It also signifies that it won't work if you're using the root user in a GUI. To run it you need to create a new user with the required privileges and use that instead.

If you want to get more insights into SQL, check out this SQL Course from Intellipaat.

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...