【自分用メモ】MySQLのエラー色々「ERROR 1045」「ERROR 2002 」

エラーと攻略方法

雑にメモ。

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

MySQLを停止

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

$ sudo touch /tmp/mysql.sock
$ mysql -u root
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (38)

$ mysql.server restart
ERROR! The server quit without updating PID file (/usr/local/var/mysql/Saneatsus-MacBook-Pro.local.pid).

$ sudo chown mysql:mysql /tmp # 実行しなくていい場合も
$ sudo chown -R _mysql:_mysql /usr/local/var/mysql
$ sudo mysql.server start
Starting MySQL
. SUCCESS!

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

$ mysql -u root                                                                                                                                          
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.

mysql> 
$ sudo ps aux|grep mysql
$ sudo kill 9999

mysql -u root
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)

$ sudo rm -rf /usr/local/var/mysql
$ brew uninstall mysql
$ brew install mysql
$ mysql.server start
Starting MySQL
.. ERROR! The server quit without updating PID file (/usr/local/var/mysql/Saneatsus-MacBook-Pro.local.pid).

$ mysql -u root -p
Enter password: 
ERROR 1045 (28000): Access denied for user ‘root’@‘localhost’ (using password: YES)

$ mysql -u root 
:
:
mysql> 

その他

Railsでは config/settings/development.local.yml の中でpasswordを空にしちゃう。

db:
  default:
    username: "root"
    password: ""

参考

【Rails】rake db:create時にMysql2のエラーが発生(ERROR! The server quit without updating PID file)

問題内容

以下のコマンドを実行した結果,MySQL2のエラーが発生した.

$ rake db:create
:
Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)
Couldn't create database for {"adapter"=>"mysql2", "encoding"=>"utf8", "pool"=>5, "timeout"=>5000, "username"=>"sane", "password"=>"sane", "database"=>"sales_aggregator_dev"}
rake aborted!
Mysql2::Error: Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)
:

発生手順

rake db:createを実行すると,上記エラーが発生する
mysqlのサーバをリスタートしてみたところPIDファイルが確認出来ないといわれる

$ sudo mysql.server restart
Password:
 ERROR! MySQL server PID file could not be found!
Starting MySQL
.Logging to '/usr/local/var/mysql/Saneatsus-MacBook-Pro.local.err'.
 ERROR! The server quit without updating PID file (/usr/local/var/mysql/Saneatsus-MacBook-Pro.local.pid).

Qiitaの記事を参考にpidファイルを作成した後,sudo mysql.server restartを実行したが,結果は変わらなかった.

解決方法

こっちのQiitaの記事を参考に以下を実行して解決!

$ rm -rf /usr/local/mysql
$ rm -rf /Library/StartupItems/MYSQL
$ rm -rf /Library/PreferencePanes/MySQL.prefPane
$ rm -rf /Library/Receipts/mysql-.pkg
$ rm -rf /usr/local/Cellar/mysql*
$ rm -rf /usr/local/bin/mysql*
$ rm -rf /usr/local/var/mysql*
$ rm -rf /usr/local/etc/my.cnf
$ rm -rf /usr/local/share/mysql*
$ rm -rf /usr/local/opt/mysql 

$ brew install mysql@5.7
$ echo 'export PATH="/usr/local/opt/mysql@5.7/bin:$PATH"' >> ~/.zshrc 
$ source ~/.zshrc
$ mysql --version
mysql  Ver 14.14 Distrib 5.7.23, for osx10.13 (x86_64) using  EditLine wrapper

$ mysql.server start
Starting MySQL
. SUCCESS!

【自分用メモ】利用規約を作成する時に参考にしたサイト

テンプレート

利用規約

プライバシーポリシー

その他

色々探している時に面白かったサイト

【自分用メモ】RubyでNokogiriを使ってスクレイピングする時に役に立ったサイトまとめ

大体ここらへんを見れば書き方がわかった。

【Keras】ResourceExhaustedError: OOM when allocating tensor with shape[16,64,256,512]

問題点

学習時の画像サイズを256x256から、256x512に変更したところ、エラーが発生した。

tensorflow.python.framework.errors_impl.ResourceExhaustedError: OOM when allocating tensor with shape[16,64,256,512] and type float on /job:localhost/replica:0/task:0/device:GPU:0 by allocator GPU_0_bfc
         [[Node: loss_1/conv2d_1_loss/model_1/vgg16/block1_conv2/convolution = Conv2D[T=DT_FLOAT, _class=["loc:@train...kpropInput"], data_format="NCHW", dilations=[1, 1, 1, 1], padding="SAME", strides=[1, 1, 1, 1], use_cudnn_on_gpu=true, _device="/job:localhost/replica:0/task:0/device:GPU:0"](loss_1/conv2d_1_loss/model_1/vgg16/block1_conv1/Relu, block1_conv2/kernel/read)]]
Hint: If you want to see a list of allocated tensors when OOM happens, add report_tensor_allocations_upon_oom to RunOptions for current allocation info.

         [[Node: loss_1/mul/_1677 = _Recv[client_terminated=false, recv_device="/job:localhost/replica:0/task:0/device:CPU:0", send_device="/job:localhost/replica:0/task:0/device:GPU:0", send_device_incarnation=1, tensor_name="edge_11171_loss_1/mul", tensor_type=DT_FLOAT, _device="/job:localhost/replica:0/task:0/device:CPU:0"]()]]
Hint: If you want to see a list of allocated tensors when OOM happens, add report_tensor_allocations_upon_oom to RunOptions for current allocation info.

原因

[16,64,256,512]は、右からバッチ数、チャンネルサイズ、画像の高さ、画像の幅を表す。
この合計が、16x64x256x512= 134,217,728(単位はbyteではない)となり、これがメモリサイズを超えた値となっているためエラーとなっている。

解決策

画像サイズは変更できないのでバッチサイズを8に変更した。

参考

ssh接続の際に「The authenticity of host [XX....] can't be established.」が発生

問題点

sshでサーバに接続する際に以下のようなエラー文が発生

The authenticity of host '[XX.XX.XX.XX]:XX [XX.XX.XX.XX]:XX' can't be established.
ECDSA key fingerprint is SHA256:hogehogehogehogehogehogehogehogehogehogheog.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '[XX.XX.XX.XX]:XXXX' (ECDSA) to the list of known hosts.

解決策

~/.ssh/config ファイルのパーミッションの権限の問題だったよう。
configは600にするものらしい。

$ chmod 600 ~/.ssh/config

参考

フォルダ内のファイルをランダムにサンプリングして別のフォルダへコピーしたい

取り敢えずプログラムを動かすために、全ての画像が入っているフォルダから、
学習用、テスト用のフォルダにランダムにサンプリングして移動させたい。

find ./FROM_DIR/ | grep *.jpg | sort -R | tail -n NUM | xargs -n 1 sh -c 'cp -v $0 ./TO_DIR'
コマンド 説明
find ./FROM_DIR/ FROM_DIR以下にあるファイル・フォルダをすべて列挙
grep *.jpg 〜.jpgとなっているファイルを検索
sort -R ランダムに並び替え
tail -n NUM NUM個のファイルを取得
xargs -n 1 sh -c 'cp -v $0 ./TO_DIR' $0に取得した文字列(ファイル名)を入れてTO_DIRへコピーする

参考