HONDAのAndroid アプリ, Web アプリ開発備忘録

このブログはHONDAがAndroidアプリの開発開始と同時に作成したもので備忘録として記しています。最近Web系に就職が決まったのでwebアプリも勉強していきます。

MySQLにハマった

こんばんわ。

VagrantcentOSMySQLにはまりましたので

centOS7.1の設定コマンドまとめと、

MySQLの導入の仕方だけまとめておきます。

たぶんメモに書きまくったので何がなんだかさっぱりって人が続出しますが

ご了承ください。

 

ちなみにハマったのは

mysql -u root とコマンドを打つと、パスワードを求められ、

"vagrant"だろうと、打つと、

ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
こういうエラーです。

www.goofoo.jp

 

その後

mysql -u root とコマンドを打つと、


ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (13)

ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)

のようなエラーでした。

そっから二時間はまってました(笑)

 

調べたURLだけはうっておきます。(全部試しましたが解決しませんでした。)

d.hatena.ne.jp

misos.hatenablog.com

ただ僕の場合MySQLの設定が不十分で、

インストールだけで何の設定もしていなかったのが

このエラーの原因だと思います。

 

 権限すら与えてないのでやはりこういうエラーが出たのかと。

 

こういうエラーが出て

永遠にハマったのでvagrantの削除とcentOSの再導入から

やりました。

 

--------------------------------------------------------------------------------------
設定コマンドまとめ(centOS7.1の初期設定)
詳細はここ参照
 
centos login: vagrant ← ログインユーザ名としてrootと入力
Password:  vagrant← rootのパスワード応答(表示はされない)
 
[vagrant@localhost ~]$ su - ← suコマンドでrootになる(-を忘れずに)
パスワード: vagrant← rootのパスワード応答
 
[root@localhost ~]# usermod -G wheel vagrant ← 管理者ユーザ(vagrantというユーザ名)をwheelグループに追加
 
[root@localhost ~]# vi /etc/pam.d/su
#auth       required     pam_wheel.so use_uid
auth       required     pam_wheel.so use_uid ← コメント解除
[ESC]キー + :w + :q
 
[root@localhost ~]# yum -y update ← インストール済パッケージの一括アップデート
※大量のパッケージのダウンロード/アップデートを行うため時間がかかる
 
[root@localhost ~]# yum -y install yum-cron ← yum-cronインストール
 
[root@localhost ~]# vi /etc/yum/yum-cron.conf ← yum-cron設定
# Whether updates should be applied when they are available.  Note
# that download_updates must also be yes for the update to be applied.
apply_updates = yes ← ダウンロード&アップデートを自動で行うようにする

[root@localhost ~]# systemctl start yum-cron ← パッケージ自動更新起動
 
[root@localhost ~]# systemctl enable yum-cron ← パッケージ自動更新自動起動設定
 
[root@localhost ~]# yum -y groupinstall base "Development tools" ← ベース、開発ツールパッケージ群インストール
 
--------------------------------------------------------------------------------------
MySQLの導入

 

 
MariaDBがデフォで入っているため、まず競合を防ぐため消去
[root@localhost ~]#  sudo yum remove mariadb-libs.x86_64
[root@localhost ~]#  rm -rf /var/lib/mysql/
消えているか確認
[root@localhost ~]#  yum list installed | grep maria
 
MySQL Community Server 5.7のインストール
[root@localhost ~]#   yum -y install mysql-community-server
入っているか確認
[root@localhost ~]#   mysqld --version
mysqld Ver 5.7.10 for Linux on x86_64 (MySQL Community Server (GPL))
↑が出てれば入ってます。
 
サーバーを起動したら自動的に MySQL Server が起動するように設定
[root@localhost ~] # systemctl enable mysqld.service
 
MySQL Server が起動コマンド
[root@localhost ~] # systemctl start mysqld.service
MySQL Server が停止コマンド
[root@localhost ~] # systemctl stop mysqld.service
 
MySQL 5.7 では、管理者ユーザである root のパスワードはランダムな文字のものが初期状態で設定されます。 パスワードはインストールの終了とともに /var/log/mysqld.log に出力されます。 初期パスワードは変更するのを忘れないようにしましょう。”
 
というわけでpassを設定
まずは、初期のパスを確認
 
[root@localhost ~] # sudo cat /var/log/mysqld.log | grep root
 
へんな大文字英数字小文字英字が絡んでるパスがあるはず
変更するために覚えておくこと。
 
これを変更するために mysql_secure_installationをつかう
対話形式でパスワードを変更していく
 
[root@localhost ~] #  mysql_secure_installation
 
Securing the MySQL server deployment.
 
Enter password for user root: [先ほど調べたrootパスワード]
 
The existing password for the user account root has expired. Please set a new password.
 
New password: [新しいパスワード]
Re-enter new password: [新しいパスワード]
 
The 'validate_password' plugin is installed on the server.
The subsequent steps will run with the existing configuration
of the plugin.
Using existing password for root.
 
Estimated strength of the password: 100
Change the password for root ? ((Press y|Y for Yes, any other key for No) : [y入力]
 
New password: [新しいパスワード]
Re-enter new password: [新しいパスワード]
 
Estimated strength of the password: 100
Do you wish to continue with the password provided?(Press y|Y for Yes, any other key for No) : [y入力]
 
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) : [y入力]
Success.
 
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 N : [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!
 
新しいパスだが
デフォルトでは8文字以上、英大文字小文字数字記号の4種類を含む必要がある。
 
 

 

参照。

 
なにを設定したかはここを参照
 
あとから簡単なパスに再設定します。
 
その前に文字コードの設定だけ、
[root@localhost ~] #  sudo vi /etc/my.cnf
character_set_server=utf8
skip-character-set-client-handshake
[ESC]キー + :w + :q
 
ちゃんと変更できているか確認
[root@localhost ~] # systemctl restart mysqld.service
> show variables like 'char%';
 
character_set_filesystem | binary
以外utf8になっていればok
 
最後に簡単なパスに再設定します。
 
/etc/my.cnfの最後の行に追加
[root@localhost ~] #  sudo vi /etc/my.cnf
validate_password_policy=LOW
 
再起動
[root@localhost ~] # systemctl restart mysqld.service
 
ログインし、パスワード設定(小文字英語+数字でおkになっている)
[root@localhost ~] # mysql -u root -p
mysqlset password for root@localhost=password('新しいパスワード');
 
これで大丈夫なはず。
いやーーはまったわ怒