0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

mysqlエラー対処忘備録(rootへの権限付与)

Last updated at Posted at 2021-02-26

db環境設定で最も基本的なアクセス権限の付与について 

~ % mysql -u root
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)

~ % mysql -u root -p
Enter password: 
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)

rootにアクセス権限がないようだ...

https://qiita.com/yummy888/items/25621bc1451f218e010a
この記事を参考にしよう。

 % mysql.server stop 
Shutting down MySQL
.. SUCCESS! 

~ % mysqld_safe --skip-grant-tables
2021-02-26T03:02:12.6NZ mysqld_safe Logging to '/usr/local/var/mysql/MacBook-Pro.local.err'.
2021-02-26T03:02:13.6NZ mysqld_safe A mysqld process already exists

...。mysqld_safe A mysqld process already existsとはなんぞや?

この記事を参考にしよう。
mysqld_safe A mysqld process already existsの対処法【MySQL】
https://yaba-blog.com/mysqld_safe-a-mysqld-process-already-exists-mysql/

mysql.server stop だとMySQLが勝手に再起動するらしい
mysql.server statusで確認。

~ % mysql.server stop 
Shutting down MySQL
.. SUCCESS! 
~ % mysql.server status
 SUCCESS! MySQL running (53818)

たしかに、再起動されている。

~ % brew services stop mysql
Stopping `mysql`... (might take a while)
==> Successfully stopped `mysql` (label: homebrew.mxcl.mysql)

再度こちらの記事に戻るhttps://qiita.com/yummy888/items/25621bc1451f218e010a#%E6%A8%A9%E9%99%90%E7%A2%BA%E8%AA%8D

権限なしでアクセス

 ~ % mysqld_safe --skip-grant-tables
2021-02-26T03:22:53.6NZ mysqld_safe Logging to '/usr/local/var/mysql/MacBook-Pro.local.err'.
2021-02-26T03:22:53.6NZ mysqld_safe Starting mysqld daemon with databases from /usr/local/var/mysql

成功

mysqlへ接続

~ %  mysql -u root
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 7
Server version: 8.0.22 Homebrew

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

-以下記事通り

権限確認

Userテーブル削除

rootユーザーを作成し、権限付与

mysqld_sefe プロセス終了
ps
-> 現在実行されているプロセス一覧表示

KILL (PID)
-> プロセス終了

~ % mysql.server start
Starting MySQL
. SUCCESS! 
yuto@MacBook-Pro ~ %  mysql -u root -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 8.0.22 Homebrew

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

またrootアカウントで作業するのは抵抗がある場合MySQLユーザーの作成を行います。
セキュリティ設定(rootのパスワード変更等)

~%mysql_secure_installation

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?