mariaDBの削除
mariaDB というDBga最初からCentOS7にインストールされていることが多いので削除。競合して誤動作の原因となるので。
# yum remove mariadb-libs
# rm -rf /var/lib/mysql/
MySQLのレポジトリをダウンロード
yumでインストールするために公式のレポジトリを追加します。
# yum localinstall http://dev.mysql.com/get/mysql57-community-release-el7-11.noarch.rpm
2021/4現在、MySQL5.7系はel-11が最新版のようです。
おまけ・レポジトリのバージョン調整
公式のyumレポジトリ
https://dev.mysql.com/downloads/repo/yum/
公式に掲載されているのは常に最新のレポジトリ。最新のレポジトリは過去のレポジトリもすべて含まれる。
ただ、デフォルトでインストールされるのが最新のMySQL8になってしまうので以下のようなコマンドを使って取得先を過去のバージョンのものに調整するといい
対象レポジトリのコントロール
# yum repolist all | grep mysql
# yum-config-manager --disable mysql80-community
# yum-config-manager --enable mysql57-community
MySQL Community Server5.7をyumインストール
ダウンロードできるバージョンを確認
# yum list | grep mysql-community-server
mysql-community-server.x86_64 5.7.33-1.el7 mysql57-community
実際のインスト―ル
# yum -y install mysql-community-server
数分かかります
バージョンの確認
# mysqld --version
mysqld Ver 5.7.33 for Linux on x86_64 (MySQL Community Server (GPL))
自動起動と停止、自動起動設定
自動起動を有効に
# systemctl enable mysqld
自動起動が有効になったか確認
# systemctl is-enabled mysqld
enabled
mysqlサーバーを起動
#systemctl start mysqld
起動の確認
# ps auxw | grep mysqld
polkitd 56074 0.4 0.0 1115204 384 ? Ssl 11:32 0:36 mysqld
mysql 59541 5.2 14.5 1122184 144868 ? Sl 13:52 0:02 /usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid
MySQLに接続
rootといえどパスワードなしでは入れません。
初期化された一時パスワードを確認
# grep "temporary password" /var/log/mysqld.log
2021-04-02T04:52:06.661371Z 1 [Note] A temporary password is generated for root@localhost: YDuqeuU9o=_M
この行の最後がパスワードです。これを使ってrootログイン
MySQLにrootで接続
# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.7.33
Copyright (c) 2000, 2021, Oracle and/or its affiliates.
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>
これが出れば接続成功。
このままログインしてるので今すぐにパスワードを変えましょう。
8文字以上かつ英大文字・英小文字・数字・記号必須です!
厳しすぎる・・
mysql> SET PASSWORD = PASSWORD('YDuqeuU9o=_M');
Query OK, 0 rows affected, 1 warning (0.09 sec)
MySQL設定ファイル(my.cnf)を編集
最低限の設定をしておきましょう
一応バックアップ
# cp /etc/my.cnf /etc/my.cnf.org
MySQL設定ファイル編集
# vi /etc/my.cnf
開いたファイルは
[****]という記述でブロックが区切られているので
[mysqld]というブロックの末尾に以下を追記。
~略~
[mysqld]
~略~
character-set-server=utf8
default_password_lifetime=0
~略~
編集したら再起動
# systemctl restart mysqld
コメント