1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

【MariaDB(MySQL)】インストール直後にrootでログインしたい

Posted at

はじめに

MariaDB(MySQL)のインストール直後にrootでログインしようと以下を実行しましたが、認証されなかったため、ログイン方法を調べました。

$ mysql -u root -p

環境

  • MariaDB 11.4

結論

OSのroot権限で単に# mariadb(MySQLの場合は# mysql)とすればログインできます。

解説

10.4と古いバージョンしか見つからず恐縮ですが、MariaDBの公式ドキュメントを見ていきます。

以降の引用は全て本公式ドキュメントからであり、翻訳は機械翻訳を利用しました

First, it is configured to try to use the unix_socket authentication plugin. This allows the root@localhost user to login without a password via the local Unix socket file defined by the socket system variable, as long as the login is attempted from a process owned by the operating system root user account.

まず、unix_socket 認証プラグインを使用するように構成されています。これにより、ログインがオペレーティング システムの root ユーザー アカウントによって所有されているプロセスから試行される限り、root@localhost ユーザーは socket システム変数によって定義されたローカル Unix ソケット ファイルを介してパスワードなしでログインできるようになります。

デフォルトでunix_socket認証となっているため、rootユーザーであればパスワードなしでMariaDB(MySQL)にログインできるようです。

rootパスワードの設定方法

ログイン後、必要であればrootのパスワードを設定することも可能です。

Second, if authentication fails with the unix_socket authentication plugin, then it is configured to try to use the mysql_native_password authentication plugin. However, an invalid password is initially set, so in order to authenticate this way, a password must be set with SET PASSWORD.

次に、unix_socket 認証プラグインで認証に失敗した場合、mysql_native_password 認証プラグインを使用するように設定されます。ただし、無効なパスワードが最初に設定されるため、この方法で認証するには、SET PASSWORD を使用してパスワードを設定する必要があります。

パスワードを設定するSQLの例です。

SET PASSWORD for root@localhost = PASSWORD('');

しかし、特に必要でなければrootのパスワードは設定しないことが推奨されているようです。

However, just using the unix_socket authentication plugin may be fine for many users, and it is very secure. You may want to try going without password authentication to see how well it works for you. Remember, the best way to keep your password safe is not to have one!

ただし、多くのユーザーにとっては、unix_socket 認証プラグインを使用するだけで十分であり、非常に安全です。パスワード認証なしで試してみて、それがどの程度機能するかを確認することもできます。パスワードを安全に保つ最善の方法は、パスワードを持たないことです。

おわりに

rootの初期パスワードを確認する方法を調べると、/var/log/mysqld.logを確認する記事が多かったのですが、筆者の環境ではこのファイルは存在せず上手くいきませんでした。

結局# mariadbするだけなので解決策としては簡単なのですが、誰かの役に立てばと思い記録しておきます。

1
0
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
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?