1
2

More than 3 years have passed since last update.

UbuntuでMySQLをインストールした後、rootユーザでログインしようとすると【Access denied for user 'root'@'localhost'】と出て弾かれる

Posted at

インストール

mysql 5.7.28

事象

$ sudo apt update
$ sudo apt install mysql-server

上記コマンドで、UbuntuでMySQLインストール後に mysql -u root -p でログインしようとすると Access denied for user 'root'@'localhost' と出て弾かれる。

解決

MySQLインストール後、セキュリティ設定をしなきゃいけないみたいですね^^;

Ubuntu18.04にMySQLをインストールする手順

上記のページを参考にさせていただきました。

上記ページを読んでいて分かったのですが、前提として

MySQL 5.7以降では、MySQLのrootユーザはデフォルトではそもそもパスワードによるログインができないようになっています。パスワードの代わりに、システムのrootユーザ(ここではOSがUbuntuなのでUbuntuのrootユーザ)情報でログインする必要があります。すなわち、以下のようにsudoでMySQLのrootユーザとしてもMySQLにログインできます。

と記載してあるので、 sudo mysql でログイン

$ sudo mysql
[sudo] password for XXXXXXXX:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 20
Server version: 5.7.28-0ubuntu0.18.04.4 (Ubuntu)

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

入れました!

1
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
2