Сначала я создаю каталог базы данных:
$ mysql_install_db --datadir=./foo
Затем я запускаю демон mysql:
$ mysqld --port=5555 --datadir=./foo &
Он запускается нормально, и я могу подключиться к нему, например, с помощью Navicat. Я пытаюсь подключиться из оболочки:
$ mysql --user=root --port=5555 --password=
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
Что делать? Я также попытался сначала сменить пароль для пользователя root:
$ mysqladmin -u root -P 5555 password foo
mysqladmin: connect to server at 'localhost' failed
error: 'Access denied for user 'root'@'localhost' (using password: NO)'
Опять же, соединение отлично работает в автономном приложении SQL, таком как Navicat.
В MySQL учетные записи пользователей включают хост, с которого вы подключаетесь. Следовательно, root@localhost
и root@192.168.0.1
являются разными пользователями и могут иметь разные пароли. Любой из них тоже не может существовать.
Попробуйте этот запрос и проверьте, разные ли пароли у ваших пользователей root.
SELECT user, host, password FROM mysql.user WHERE user = 'root';
Если они это сделают, войдите в систему любым из подходящих способов и измените пароль root@localhost
пользователь того, что вы хотите. (Пустая строка не будет паролем, однако отсутствие пароля, особенно для привилегированных пользователей, обычно считается плохой идеей.)
Вот уловка:
$ mysqld --port=5555 --datadir=./foo --socket=./sock &
А потом позже:
$ mysql --socket=./sock --user=root --port=5555
Работает отлично.
Есть два известных мне способа войти в учетную запись с пустым или пустым паролем. Во-первых, просто не указывайте пароль.
$ mysql -u root
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 163714
Server version: 5.6.38 MySQL Community Server (GPL)
Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql>
Другой способ - указать -p
вариант и просто нажмите клавишу ввода, когда будет предложено.
$ mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 163719
Server version: 5.6.38 MySQL Community Server (GPL)
Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql>