MySQLにハマった
こんばんわ。
centOS7.1の設定コマンドまとめと、
MySQLの導入の仕方だけまとめておきます。
たぶんメモに書きまくったので何がなんだかさっぱりって人が続出しますが
ご了承ください。
ちなみにハマったのは
mysql -u root とコマンドを打つと、パスワードを求められ、
"vagrant"だろうと、打つと、
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
こういうエラーです。
その後
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だけはうっておきます。(全部試しましたが解決しませんでした。)
ただ僕の場合MySQLの設定が不十分で、
インストールだけで何の設定もしていなかったのが
このエラーの原因だと思います。
権限すら与えてないのでやはりこういうエラーが出たのかと。
こういうエラーが出て
永遠にハマったのでvagrantの削除とcentOSの再導入から
やりました。
--------------------------------------------------------------------------------------
設定コマンドまとめ(centOS7.1の初期設定)
詳細はここ参照
Password: vagrant← rootのパスワード応答(表示はされない)
パスワード: vagrant← rootのパスワード応答
[root@localhost ~]# vi /etc/pam.d/su
#auth required pam_wheel.so use_uid
↓
↓
auth required pam_wheel.so use_uid ← コメント解除
[ESC]キー + :w + :q
※大量のパッケージのダウンロード/アップデートを行うため時間がかかる
# 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 ← ダウンロード&アップデートを自動で行うようにする
# that download_updates must also be yes for the update to be applied.
apply_updates = yes ← ダウンロード&アップデートを自動で行うようにする
--------------------------------------------------------------------------------------
MySQLの導入
MariaDBがデフォで入っているため、まず競合を防ぐため消去
[root@localhost ~]#
rm -rf /var/lib/mysql/
消えているか確認
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 が停止コマンド
”MySQL 5.7 では、管理者ユーザである root のパスワードはランダムな文字のものが初期状態で設定されます。 パスワードはインストールの終了とともに /var/log/mysqld.log に出力されます。 初期パスワードは変更するのを忘れないようにしましょう。”
というわけでpassを設定
まずは、初期のパスを確認
へんな大文字英数字小文字英字が絡んでるパスがあるはず
変更するために覚えておくこと。
これを変更するために 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種類を含む必要がある。
参照。
なにを設定したかはここを参照
あとから簡単なパスに再設定します。
その前に文字コードの設定だけ、
character_set_server=utf8
skip-character-
set
-client-handshake
[ESC]キー + :w + :q
ちゃんと変更できているか確認
> show variables like
'char%'
;
character_set_filesystem | binary
以外utf8になっていればok
最後に簡単なパスに再設定します。
/etc/my
.cnfの最後の行に追加
validate_password_policy=LOW
再起動
ログインし、パスワード設定(小文字英語+数字でおkになっている)
これで大丈夫なはず。
いやーーはまったわ怒