K
K
Konstantin2020-02-27 22:47:32
linux
Konstantin, 2020-02-27 22:47:32

Mysql in the console starts up through root with any password. How to fix?

Hello.
mysql 5.7.29
Password set to root.
Privileges:

mysql> SHOW GRANTS FOR 'root'@'localhost';
+---------------------------------------------------------------------+
| Grants for [email protected]                                           |
+---------------------------------------------------------------------+
| GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' WITH GRANT OPTION |
+---------------------------------------------------------------------+
1 row in set (0.00 sec)

mysql> SHOW GRANTS FOR 'root'@'%';
+-------------------------------------------------------------+
| Grants for [email protected]%                                           |
+-------------------------------------------------------------+
| GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' WITH GRANT OPTION |
+-------------------------------------------------------------+
1 row in set (0.00 sec)


From the linux console it starts up with any password, even with an empty one
mysql --host=localhost --user=root --password=qwe1
mysql --host=localhost --user=root -p


To the request "show databases;" shows all databases.

But executing this script
<?php

$link = mysqli_connect("localhost", "root", "");

if (!$link) {
    echo "Ошибка: Невозможно установить соединение с MySQL." . PHP_EOL;
    echo "Код ошибки errno: " . mysqli_connect_errno() . PHP_EOL;
    echo "Текст ошибки error: " . mysqli_connect_error() . PHP_EOL;
    exit;
}

$query = mysqli_query($link, "show databases;");

if(mysqli_num_rows($query) > 0)
{
  $data = mysqli_fetch_assoc($query);
  print_r($data);
}
else {
  echo "empty";
}

returns only the information_schema database, also with any passwords.
php sql.php
Array
(
    [Database] => information_schema
)


From a browser via phpMyAdmin and adminer does not authorize the root user at all, even with a password.

Please tell me how to fix?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question