brewでいれたmysqlが壊れる件
講義でmysqlを使うのですが,ローカルなmacにbrewでinstallするまでは良いのですが
定期的に mysql -u root -p
すると正しいパスワードをいれても解決しない問題が出てきました.
具体的には
❯ mysql -u root ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
な感じですね. brew uninstall mysql
しても解決せず.四苦八苦していると
なblog記事が
この手順通りにやってもrm出来てないところがあって,そこは臨機応変にした. 以下作業ログ.
/v/empty ❯❯❯ sudo rm -rf /usr/local/var/mysql /v/empty ❯❯❯ brew uninstall mysql Uninstalling /usr/local/Cellar/mysql/5.7.16... (13,511 files, 439M) /v/empty ❯❯❯ brew cleanup Warning: Skipping boost: most recent version 1.63.0 not installed Warning: Skipping source-highlight: most recent version 3.1.8_4 not installed /v/empty ❯❯❯ brew update Already up-to-date. /v/empty ❯❯❯ brew install mysql ==> Downloading https://homebrew.bintray.com/bottles/mysql-5.7.16.el_capitan.bot Already downloaded: /Users/e155730/Library/Caches/Homebrew/mysql-5.7.16.el_capitan.bottle.1.tar.gz ==> Pouring mysql-5.7.16.el_capitan.bottle.1.tar.gz ==> Using the sandbox ==> /usr/local/Cellar/mysql/5.7.16/bin/mysqld --initialize-insecure --user=e1557 ==> Caveats We've installed your MySQL database without a root password. To secure it run: mysql_secure_installation To connect run: mysql -uroot To have launchd start mysql now and restart at login: brew services start mysql Or, if you don't want/need a background service you can just run: mysql.server start ==> Summary 🍺 /usr/local/Cellar/mysql/5.7.16: 13,511 files, 439M /v/empty ❯❯❯ mysqld --initialize --explicit_defaults_for_timestamp 2016-12-30T08:35:33.113558Z 0 [ERROR] --initialize specified but the data directory has files in it. Aborting. 2016-12-30T08:35:33.113992Z 0 [ERROR] Aborting /v/empty ❯❯❯ ⏎ /v/empty ❯❯❯ sudo rm -rf /usr/local/var/mysql ⏎ /v/empty ❯❯❯ mysqld --initialize --explicit_defaults_for_timestamp 2016-12-30T08:36:03.921480Z 0 [Warning] Setting lower_case_table_names=2 because file system for /usr/local/var/mysql/ is case insensitive 2016-12-30T08:36:04.125426Z 0 [Warning] InnoDB: New log files created, LSN=45790 2016-12-30T08:36:04.157283Z 0 [Warning] InnoDB: Creating foreign key constraint system tables. 2016-12-30T08:36:04.217534Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: 003ca31c-ce6b-11e6-ab71-0e9de9b7da21. 2016-12-30T08:36:04.231309Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened. 2016-12-30T08:36:04.827665Z 0 [Warning] CA certificate ca.pem is self signed. 2016-12-30T08:36:04.886195Z 1 [Note] A temporary password is generated for root@localhost: J/nhD5rss3yx
なのだが,どうもここの root@localhost:
以下に表示されるpasswordを覚えておく必要があるらしい
今回は
2016-12-30T08:36:04.886195Z 1 [Note] A temporary password is generated for root@localhost: J/nhD5rss3yx
であるので J/nhD5rss3yx
ですね
/v/empty ❯❯❯ mysql_secure_installation Securing the MySQL server deployment. Enter password for user root: Error: Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2) /v/empty ❯❯❯ mysql_secure_installation ⏎ Securing the MySQL server deployment. Enter password for user root: Error: Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2) /v/empty ❯❯❯ mysql.server start ⏎ Starting MySQL . SUCCESS! /v/empty ❯❯❯ mysql_secure_installation Securing the MySQL server deployment. Enter password for user root: Error: Access denied for user 'root'@'localhost' (using password: NO)
でさっきのパスワードをこれをした後に入力
/v/empty ❯❯❯ mysql_secure_installation ⏎ Securing the MySQL server deployment. Enter password for user root: (ここで入力する) The existing password for the user account root has expired. Please set a new password. New password: Sorry, you can't use an empty password here. New password: Re-enter new password: VALIDATE PASSWORD PLUGIN can be used to test passwords and improve security. It checks the strength of password and allows the users to set only those passwords which are secure enough. Would you like to setup VALIDATE PASSWORD plugin? Press y|Y for Yes, any other key for No: n Using existing password for root. Change the password for root ? ((Press y|Y for Yes, any other key for No) : y New password: Re-enter new password: By default, a MySQL installation has an anonymous user, allowing anyone to log into MySQL without having to have a user account created for them. This is intended only for testing, and to make the installation go a bit smoother. You should remove them before moving into a production environment. Remove anonymous users? (Press y|Y for Yes, any other key for No) : y Success. Normally, root should only be allowed to connect from 'localhost'. This ensures that someone cannot guess at the root password from the network. Disallow root login remotely? (Press y|Y for Yes, any other key for No) : n ... skipping. By default, MySQL comes with a database named 'test' that anyone can access. This is also intended only for testing, and should be removed before moving into a production environment. Remove test database and access to it? (Press y|Y for Yes, any other key for No) : y - Dropping test database... Success. - Removing privileges on test database... Success. Reloading the privilege tables will ensure that all changes made so far will take effect immediately. Reload privilege tables now? (Press y|Y for Yes, any other key for No) : y Success. All done! /v/empty ❯❯❯ mysql -u root ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO) /v/empty ❯❯❯ mysql -u root ^p ⏎ ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO) /v/empty ❯❯❯ mysql -u root -p ⏎ Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 9 Server version: 5.7.16 Homebrew Copyright (c) 2000, 2016, 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> exit exit ^C mysql> exit; Bye
な感じで解決した
追記(2017/01/03)
かくとぅふ氏からコメントが
上のlogに追記しておくと人によってはクリーンインストールした際にrootでのログインの際にpassを設定していない場合にうまくログインできない場合があるみたいです. その場合passを変更しなきゃいけないのですが, http://qiita.com/ahaha0807_alg/items/7323a5d2dd365308cb94 を参考にすると幸せになれるみたいです.ほとんどがpasswordでの記述で自分のところのelcapitanではずっと ERROR 1054 (42S22): Unknown column 'Password' in 'field list' みたいなエラーはいていたんで.もしpass変更の際にひっかかるようであればこちらも参考にするとよいかと.
なるほど.パスワードカラムを変更する場合もある様です
UNIXという考え方
- 作者: Mike Gancarz,芳尾桂
- 出版社/メーカー: オーム社
- 発売日: 2001/02
- メディア: 単行本
- 購入: 40人 クリック: 498回
- この商品を含むブログ (143件) を見る
UNIXという考え方を読みました. しばらく本の解説や文章を書いてないので上手く纏まってないですが…
nal先生のサイトにあったオススメ書籍だったので前々から気になっていました. 琉大図書館の蔵書になったので,借りて3章ほど.その後購入して帰省のバスで読了しました.
版が変わってないこともあり,中に書かれている情報としては大分古い (CDROMが最新の環境と書かれている)ですが,bassとなっているUNIX思想は今でも通じると思います.
中では「small is Beautiful」な UNIX思想やUNIXの定理についての解説がなされています. UNIX思想の解説本ではありますが,UNIXの歴史を解説した本という側面も強く,歴史好きとしてはそういった面でも面白かったです. ただし所謂コマンドの解説本では無いので,実用的なTipsを求めている方にはオススメできないかもしれません.
本文中では「C言語よりシェルスクリプトの方が移植性が高い」と再三提唱されていました. 自分としてはシェルスクリプトの方が移植性低いと認識していたので思わぬ発見でした. 筆者が「アセンブラが~」などと再三言っているので,おそらくそこまで言語の種類自信も無かった時代だったからだとも思いますが…
かなり進化したアーキテクチャ,Linuxからこの世界に入ったので温故知新な勉強になりました. 言語に頼らず小さい処理が出来るプログラムこそUNIXの美徳は教訓ですね.
Fedora24でLinuxのkernelをbuildする
さて作業レポート. dockerの課題を先にやれと言われそうだが….
とりあえずKVMにあげてからの話.
まずLinuxのkernelを kernel.orgから持ってくる. …のだが,hostの都合で今回は4.8.6を使う
vmで
$wget https://cdn.kernel.org/pub/linux/kernel/v4.x/linux-4.8.6.tar.xz
バージョンは適当に変えよう. 落としてきたのはtar.xzファイルであるので解凍して展開する.
$tar Jxfv linux-4.9.tar.xz
(この展開している時スーパーハカー感あってすごく楽しい)
あとは公式サイトに書いてある通りにやっていく
$ dnf install fedpkg fedora-packager rpmdevtools ncurses-devel pesign $ dnf install ncurses-devel
はずなのだが…?
これで通るはずだが,何故か1つずつやっていかないとinstall出来なかった….
しかし pesign-rh-test-certs
は無いらしい.おいおい.
でめでたくbuild出来ると思いきや openssl/bio.h: No such file or directoryなエラーがmakeしてると出る. なので
dnf install openssl-devel
を行う必要がある.
履歴によると実際に僕がやったのはこの辺
22 | install openssl-devel | 2016-12-24 18:34 | Install | 8 21 | install pesign | 2016-12-24 18:27 | Install | 3 20 | install fedora-packager | 2016-12-24 18:23 | Install | 86 19 | install kernel-devel | 2016-12-24 18:17 | Install | 1 18 | install zlib-devel | 2016-12-24 17:07 | Install | 1 17 | update | 2016-12-24 16:48 | E, I, U | 86 EE 16 | install ncurses-devel | 2016-12-24 16:42 | Install | 2
ここまで行くと多分build出来るので
$make clean $make mrproper
して設定を消去(ゴミ削除)して
$make menuconfig
する.kernel debugにチェックをいれないといけないが,実はデフォルトで入っている.そのままsaveして
$ make >& ers & $ disown %m exit
あたりすれば大丈夫らしい.
心配ならtmuxをinstallして起動した状態で
$ make >& ers &
を行えばバックグラウンドでmakeが行われていく筈. logはersに入っているのでmoreとかで確認すると1~2時間くらいでbuild出来ている.
続いて
make modules_install
とするのだがエラーが出る. どうも
dnf install elfutils-libelf-devel
しないとダメらしい.
あとは
make install
すればokなのだが,この後gdbで追う様の設定が結構キツイ.それはまた次回で
(追記 2017/01/15)
kernelのbuildで失敗することが多くなり(具体的には make manuconfigが出来ない)
色々試したのですが
dnf reinstall ncurses-devel
したら解決しました.コンパイラでマクロが読めてなかったのは,このライブラリ群が破損していたからだそうです.
VirtualBoxを使って(気合で)Fedora24のパーティションを拡張する
わりと辛かったのでメモ
講義でqcow2な形式を拡張して,LinuxのKarnelをbuildする必要があったのだが,root権限が使えない一般ユーザーなので 自分で出来るVirtualBoxでやってみる. 気合と書いてるのはその為.
なぜVirtualBoxを使わないといけないのか
どうもVirtualBoxで初期に振ったHDD容量以外は
fdisk /dev/sda
しても降ることが出来ないらしい….今回は2時間くらいそこで悩んだ
VirtualBoxでの操作
まずは拡張したいVirtualBoxのイメージをCloneしておく. 右クリックでClone押せば出来るっぽい.(なぜかCloneする時のアイコンが羊です) それで拡張する為に一旦shut downしておく.
ターミナル上での操作
まずはローカルで ~/VirtualBox VMs
にcd.
続いて容量の確認
$ VBoxManage showhdinfo anagura.vdi UUID: 4e7f002a-a846-4880-a960-c59912501cd0 Parent UUID: base State: created Type: normal (base) Location: /Users/e155730/VirtualBox VMs/anagura/anagura.vdi Storage format: VDI Format variant: dynamic default Capacity: 50000 MBytes Size on disk: 4898 MBytes Encryption: disabled In use by VMs: anagura (UUID: c4dfd1e7-5ebd-44d6-abb3-c12a3494529d)
ここの Capacityが問題.今回はやった後なんでわりとでかいが,8Gb程度になってるはず. さて変換 30Gほどあれば良いか
$ VBoxManage modifyhd clone-disk1.vdi --resize 30720 0%...10%...20%...30%...40%...50%...60%...70%...80%...90%...100%
多分確認すれば増えている筈.
実際に反映させていく
さてこれでHDDを物理的に増やした(仮想的だけど)ので,それを実際にマシン側に反映させていく.
とりあえず先程反映させたVMを起動,rootあたりで入っておく.(一応suとかしてrootになっとく)
まずは今現在のパーティション環境を確認したいので
$ fdisk /dev/sda fdisk (util-linux 2.28.2) へようこそ。 ここで設定した内容は、書き込みコマンドを実行するまでメモリのみに保持されます。 書き込みコマンドを使用する際は、注意して実行してください。 コマンド (m でヘルプ):
な画面を表示させる.ここで確認はpだからおもむろにpを押すと
デバイス 起動 開始位置 最後から セクタ サイズ Id タイプ /dev/sda1 * 2048 1026047 1024000 500M 83 Linux /dev/sda2 1026048 16777215 15751168 7.5G 8e Linux LVM
な画面が表示される. これは後々使うのでメモっておいてください
ここでsda2の方を拡張するのでsda2を消す.(先の段階でサイズが直ってたら変更する必要ない) fdisk内でdを選択
コマンド (m でヘルプ): d パーティション番号 (1,2, 既定値 2): 2 パーティション 2 を削除しました
な感じで削除. 続いて サイズ変更fdisk内でnを選択して作る この時 開始位置を最初の通りに設定する こと.多分デフォルトでそうなってる. 終了位置を書かれてるMAXに設定して,再びp をすると大きくなっている.
ここでファイルに反映させるので必ずwを推して書き込ませること.
で,実際に反映させる.
$pvresize /dev/sda2 Physical volume "/dev/sda2" changed 1 physical volume(s) resized / 0 physical volume(s) not resized
さて変更されているか.
$ pvdisplay --- Physical volume --- PV Name /dev/sda2 VG Name fedora_401 PV Size 48.34 GiB / not usable 2.00 MiB Allocatable yes PE Size 4.00 MiB Total PE 12374 Free PE 10452 Allocated PE 1922 PV UUID QmA0cN-CnqX-2nFy-2FoX-JFh0-cWhP-V51KUs
やっためう!! さて続いては論理的に拡張
今回は /dev/mapper/fedora(fedora_401)-root
に対して行う
$ lvextend -l +100%FREE /dev/mapper/fedora_401-root Size of logical volume fedora_401/root changed from 6.71 GiB (1717 extents) to 47.54 GiB (12169 extents). Logical volume root successfully resized.
確認しとく
[root@401]/home/anagura# lvdisplay --- Logical volume --- LV Path /dev/fedora_401/swap LV Name swap VG Name fedora_401 LV UUID RyM5Tj-qGQN-PM13-gMUo-Uy7R-SdDd-4Id4Yt LV Write Access read/write LV Creation host, time 401.pc.ie.u-ryukyu.ac.jp, 2016-10-14 20:13:39 +0900 LV Status available # open 2 LV Size 820.00 MiB Current LE 205 Segments 1 Allocation inherit Read ahead sectors auto - currently set to 256 Block device 253:1 --- Logical volume --- LV Path /dev/fedora_401/root LV Name root VG Name fedora_401 LV UUID LJZan7-IpRp-7ssR-0BbZ-rovN-LcLz-7QMzpR LV Write Access read/write LV Creation host, time 401.pc.ie.u-ryukyu.ac.jp, 2016-10-14 20:13:39 +0900 LV Status available # open 1 LV Size 47.54 GiB Current LE 12169 Segments 1 Allocation inherit Read ahead sectors auto - currently set to 256 Block device 253:0
おーけー.
ここで resize2fs /dev/mapper/fedora_401-root
したさはあるが,これは古いらしく
$xfs_growfs /dev/mapper/fedora_401-root meta-data=/dev/mapper/fedora_401-root isize=512 agcount=4, agsize=439552 blks = sectsz=512 attr=2, projid32bit=1 = crc=1 finobt=1 spinodes=0 data = bsize=4096 blocks=1758208, imaxpct=25 = sunit=0 swidth=0 blks naming =version 2 bsize=4096 ascii-ci=0 ftype=1 log =internal bsize=4096 blocks=2560, version=2 = sectsz=512 sunit=0 blks, lazy-count=1 realtime =none extsz=4096 blocks=0, rtextents=0 data blocks changed from 1758208 to 12461056
で行う.
$ df -h ファイルシス サイズ 使用 残り 使用% マウント位置 devtmpfs 359M 0 359M 0% /dev tmpfs 371M 0 371M 0% /dev/shm tmpfs 371M 584K 370M 1% /run tmpfs 371M 0 371M 0% /sys/fs/cgroup /dev/mapper/fedora_401-root 48G 3.8G 44G 8% / tmpfs 371M 8.0K 371M 1% /tmp /dev/sda1 477M 155M 293M 35% /boot tmpfs 75M 0 75M 0% /run/user/1000
無事変更されてる.良かった.
この辺参考にすると良い? qiita.com
mkdirしたら自動でリモートのmercurialにcloneする
というわけでzshrcあたりに記述するシェル芸を久々に書いた.
いちいちcloneしたりpushする時にパス書くのも面倒くさいし
ディレクトリ作るためだけにリモート行くのもやや面倒くさい….
その為に osmkdir ex2.11
とかするとディレクトリ生成とclone,ついでにhgrcを書いてpush出来るようにする関数を作ってみました.
osmkdirするとディレクトリとpathを記述したhgrcを作り,mercurialにcloneす ...
やってることはただコマンド並べてるだけなのでわりかし簡単…. SSH変数のとこを適当に変えてください
perlの()
最近Perl勉強しています.楽しいです. 今日の発見なんですが
#!/usr/bin/env perl use strict; use warnings; chomp (my $input = <STDIN>); sub reject{ my $number = @_; if ($number == 0) { $number =1; } else { $number *= &reject($number-1); } } print reject($input) ."\n";
なコードがエラーを吐いて? だったのですが. Perl入学式で質問してみると
いわゆるコンテキストなアレ 問題だったらしい.要素数だけが返されてたのね…
どうもただ ()
使っているだけに感じていた
my($foo,$hoo) = @_;
は
($foo,hoo)
がリストとして解釈されたから上手く行っていたらしい.
なるほど…Perlは奥が深い…
ぴかぴか(自称)のPerl1ねんせい
この記事は Perl入学式 Advent Calendar 2016 12日目の記事です。
自己紹介
今年から始まりましたPerl入学式 in 沖縄の受講生です.アナグラといいます.in沖縄は第2回まで開催されてますが,第1回の第三部から参加させて頂いてます.
情報工学系を勉強している大学2年次です.CodeHex先生の後輩に相応します.力の差があるので気楽に後輩と言えない.
受講したきっかけ
ぶっちゃけ詳しく覚えてないです. 確かCodeHex先生がニュースサイトに投稿しているので知ったような気がします.
当時は大学でC言語とjava,あとpythonをちょろっと触ったのですが,どれも今一踏み込んで書けるLevelではなく.
スラスラ書けるのがシェルスクリプトだけ という状態だったので 母国語(プログラミング的な意味で) が欲しくて受講を決めました.
ちなみに当時のPerlに対する認知レベルは Perl? 真珠? レベルです.
第2回までの流れ
in 沖縄では第二回の時に第三回も纏めて行ったので,知識としてはリファレンスあたりまで勉強しました. 講師はpapixさんやOkinawa.pmの皆さんが中心だと思います. perl入学式は勉強したことをすぐコードに起こすので,知識と実装が同時に入ってくる感じがあり勉強しやすいです. 何より楽しい.
papixさんを始めサポーターの皆さんが優しいのですごい助かっています. Slackの方でも質問に答えて頂いて,ここまでしていただいて良いのかと思っています.
perlについて
復習と予習がてらリャマ本も進めていますが,正直リファレンスを初めとして未知の部分が多いです. コンテキストの違いはこないだ少しわかってきました.(多分)
今書いているコードはハッシュとpush,popなど以外はperlらしいコードをあまり書いていないんじゃないかなぁというレベルです. なのでよりPerlらしい(?)コードを書けるように勉強します!!
後はpaizaとかやってます.入学式に参加してからPerlでB問題が解けるようになりました…!嬉しい…!
懇談会
in 沖縄では毎回Perl入学式終了後にOkinawa.pmさんとの懇談会が行われます. 懇談会ではLTが行われたり,技術トークで盛り上がったり,相談に乗っていただいたりしています.
技術トークは技術力がないのでまだ追いついていけない事が多いですが,後々トークにあがっていたwordを聞くことがあり,いつか混ざりたいです.
それと前回の懇談会では自己紹介のLTさせて頂きました.温かい空気ありがとうごうざいます.
まとめ
まだin沖縄の全日程を走りきってないので卒業していないPerl 1年生ですが Perlはいいぞおじさん(Perl Monger) になれるようにコードガリガリ書いていきたいです.
とりあえずはアルパカ本を読み切るのがしばらくの目標です. 後は何か作ってみたいですね.はてなブログにターミナルから投稿できるプログラムとかとか….
なのでperl入学式in 沖縄卒業まで頑張っていきます!
後は彼女がいないので,いつか「Perl入学式に参加したら彼女が出来た件について」書けるようになりたいですね.