LoginSignup
0
1

UbuntuでMySQL起動時にエラー

Posted at

Ubuntu 20.04でMySQLを起動しようとしてエラーで詰まったときの解決方法を記録しておきます。

まずはMySQLをインストール。

$ sudo apt update
$ sudo apt install mysql-server

バージョン確認できました。

$ mysql --version
mysql  Ver 8.0.34-0ubuntu0.20.04.1 for Linux on x86_64 ((Ubuntu))

MySQLに接続、、っと。エラーが出ました。

$ sudo mysql -u root -p
Enter password:
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)

そもそも起動していないからか。と思い起動を試みるも、コマンドが見つからんと。
インストールしたはずなのに、おかしい。

$ systemctl mysql start
Unknown operation mysql.
$ sudo mysql.server restart
sudo: mysql.server: command not found

調べていくと、以下の記述を見つけました。
https://www.digitalocean.com/community/tutorials/how-to-install-mysql-on-ubuntu-20-04-ja

MySQL 5.7(またそれ以降のバージョン)を実行しているUbuntuシステムでは、rootMySQLユーザーはデフォルトによりパスワードではなくauth_socketプラグインを使用して認証するように設定されています。ただしこのプラグインを使うには、MySQLクライアントを呼び出すオペレーティングシステムユーザー名と、コマンドで指定したMySQLユーザー名を一致させる必要があるため、root MySQLユーザーにアクセスできるようにするには sudo 権限でmysqlを呼び出す必要があります。
$ sudo mysql

なるほど?
とりあえずやってみました。

$ sudo mysql
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 8.0.34-0ubuntu0.20.04.1 (Ubuntu)

Copyright (c) 2000, 2023, Oracle and/or its affiliates.

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>

起動しました。
MySQLのバージョンは8だったので、今回はこれに当てはまったのではないかと思います。

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