CentOS7 MySQL インストール

CENTOS

以下アクセスできました(2019.09.25)
kakukukeko.work
$mysql -uroot -p
pwd: MyNewPass4!

hogeUser
pwd: MyNewPass6!
————————

WEBの参照ばかりでやってるから、問題が起きると・・・なかなか。やることはそちらではないからね突っ込んでやることができない(反省)。
ということで以下まとめておくことに。新たに借りたサーバーはインストール実験用で使うというのもブラシュアップのためと今後のランニングコストのための準備ということで。
Window10のubutuのターミナルでやってみた。このところラズパイでlinuxライクな生活だったから便利に操作できる。Windowsプロンプトは返って面倒。macでもいいけど、Windowsでubuntuでは便利な時代。hostsの設定をするとIP sakura で楽することができる。OSをインストールすると以前の名前と同じでは受け付けないことでクライアント側のsshのキーはすべて削除して構築し直すことになる。全部の~/.ssh/.Know_hostsファイル内の内容削除でいい。

1.インストール

# yum update <—今回一からなのでまずはやっておく
# yum localinstall http://dev.mysql.com/get/mysql57-community-release-el7-7.noarch.rpm

# yum install mysql-community-server
# systemctl start mysqld.service
# systemctl enable mysqld.service

# cat /var/log/mysqld.log | grep password
2019-08-30T13:05:43.903246Z 1 [Note] A temporary password is generated for root@localhost: -!AlbW7-i%_P (最初のハイフン含む。勘違いしそうなデフォルトパスワードだな。コピペで入力した)
2019-08-30T13:06:40.246642Z 2 [Note] Access denied for user ‘root’@’localhost’ (using password: NO)
2019-08-30T13:08:19.632990Z 3 [Note] Access denied for user ‘root’@’localhost’ (using password: YES)

以下の初期化がよくわからない・・・。
# mysql_secure_installation

[root@ik1-406-35138 ~]# mysql_secure_installation

Securing the MySQL server deployment.

Enter password for user root: -!AlbW7-i%_P <–実際には表示されないがコピペで入力

The existing password for the user account root has expired. Please set a new password.

New password: MyNewPass4!  <– 規約がある。大文字・小文字・数字・記号があること

Re-enter new password:MyNewPass4!

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 No) :

… skipping.
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.

●MySQLにユーザー追加(パスワードは規約を守らないと設定できなくなってる)
> grant all privileges on *.* to test_user1@”%” identified by ‘MyNewPass5!‘ with grant option;
以下で確認してみる。OKだ。
> select user,host from mysql.user;

●HeidiSQLからのアクセス
localhostであるrootへならsshでアクセスできるツール。幸い接続できた。設定は以下でOKだった。ありがたい。


●既存のデータベースサーバーからのEXPORT
importはファイルの読み取りから行う。(うまく行かないときがあるが、今回はWarning4個でOKだった・・・)exportはデータベースごとできる。
書き出されたものにはDB名を付ければいいのだろうが、
そうでないときは引っ越し側のDBでDBを作成して、そこを選択で読み取ればいい。

2.他のクライアントからの接続
まだfirewallを許可していないので設定する

#firewallの設定

#状態チェック
firewall-cmd --list-services --zone=public  --permanent
dhcpv6-client ftp http https ssh

#mysqlが無いので、追加
# firewall-cmd --add-service=mysql --zone=public --permanent

#もう一度チェック
# firewall-cmd --list-services --zone=public  --permanent
dhcpv6-client ftp http https mysql ssh

#mysqlが表示されましたね。
#リロードして有効に。
firewall-cmd --reload

$mysql -hsakura -utest_user -p
password:
駄目だ。IPでやってみる。
$mysql -h153.127.xxx.xx -utest_user -p
駄目だ・・・。何が不足だ??
ということで、CentOS7で外部のもう1台借りているサーバーのMySQLに接続できるかやってみらる。
$ mysql -hmk.jp -utest_user -pkxx6
問題なく接続できる。
firewallでポートというかサービスは許可されている。なぜ外部からの接続を許さないのか?
パケットをキャプチャしてみるか・・・。そこまではやる気が起きないな。

3.外部からのMySQLへの接続(c#やpython)

4.別のサーバーのバックアップをインポートする
HeidiSQLで行えた。

PDOドライバ
# php -m | grep pdo
pdo_sqlite

確かにSQLiteのドライバしか無い。
yumでPHPを7.2にアップデートしたのが原因っぽいので、同じくyumでドライバもインストール。

# yum install --enablerepo=remi,remi-php73 php-mysql

●うまく行かない
1.rootにパスワードを設定できない
これは最初のインストール後でログ内にある初期パスワードを使用して設定していなかったからのようだ。
2.外部から接続できない
$mysql -h(host name) -uroot -p

No tags for this post.
タイトルとURLをコピーしました