MacOS Mojave - brew install mysql@5.7 - Доступ запрещен для пользователя 'root' @ 'localhost' - PullRequest
0 голосов
/ 04 декабря 2018

При установке mysql с помощью homebrew (то есть brew install mysql@5.7) в MacOS Mojave, при кажущейся успешной установке выводятся следующие инструкции:

We've installed your MySQL database without a root password. To secure it run:
    mysql_secure_installation

MySQL is configured to only allow connections from localhost by default

To connect run:
    mysql -uroot

При mysql -uroot или mysql_secure_installation запущен, я получаю следующую ошибку:

ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)

Как мне войти в систему mysql, чтобы изменить пароль для root?

Ответы [ 2 ]

0 голосов
/ 22 марта 2019

После новой установки brew mysql:

1) Убедитесь, что mysql запущен: brew services start mysql

2) Измените пароль mysql: mysqladmin -uroot --password = ""пароль 'NEWPASSWORD'

3) Безопасный mysql: mysql_secure_installation (с использованием нового пароля)

0 голосов
/ 04 декабря 2018

Похоже, что использование пароля «пустая строка» через флаг --password решает эту проблему:

mysql -uroot --password=""

В качестве альтернативы, вы можете вручную запустить mysqld с --skip-grant-tables:

$ mysql.server --skip-grant-tables
$ mysql
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.24 Homebrew

Copyright (c) 2000, 2018, 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.

$ 

И, наконец, измените пароль с помощью:

mysqladmin -uroot --password="" password NEW_PASSWORD
...