インストール MySQL to CentOS7
対象OS
CentOS Linux release 7.8.2003 (Core)
対象MySQLバージョン
mysqld Ver 5.7.34 for Linux on x86_64 (MySQL Community Server (GPL))
1. rpm インストール
$ sudo yum localinstall http://dev.mysql.com/get/mysql57-community-release-el7-7.noarch.rpm Loaded plugins: fastestmirror, langpacks mysql57-community-release-el7-7.noarch.rpm | 8.8 kB 00:00:00 Examining /var/tmp/yum-root-DL1Hb9/mysql57-community-release-el7-7.noarch.rpm: mysql57-community-release-el7-7.noarch Marking /var/tmp/yum-root-DL1Hb9/mysql57-community-release-el7-7.noarch.rpm to be installed Resolving Dependencies --> Running transaction check ---> Package mysql57-community-release.noarch 0:el7-7 will be installed --> Finished Dependency Resolution base/7/x86_64 | 3.6 kB 00:00:00 docker-ce-stable/x86_64 | 3.5 kB 00:00:00 epel/x86_64/metalink | 6.0 kB 00:00:00 epel/x86_64 | 4.7 kB 00:00:00 epel/x86_64/updateinfo | 1.0 MB 00:00:00 epel/x86_64/primary_db | 6.9 MB 00:00:00 extras/7/x86_64 | 2.9 kB 00:00:00 jenkins | 2.9 kB 00:00:00 updates/7/x86_64 | 2.9 kB 00:00:00 updates/7/x86_64/primary_db | 8.8 MB 00:00:00 Dependencies Resolved ===================================================================================================================================================== Package Arch Version Repository Size ===================================================================================================================================================== Installing: mysql57-community-release noarch el7-7 /mysql57-community-release-el7-7.noarch 7.8 k Transaction Summary ===================================================================================================================================================== Install 1 Package Total size: 7.8 k Installed size: 7.8 k Is this ok [y/d/N]: y Downloading packages: Running transaction check Running transaction test Transaction test succeeded Running transaction Installing : mysql57-community-release-el7-7.noarch 1/1 Verifying : mysql57-community-release-el7-7.noarch 1/1 Installed: mysql57-community-release.noarch 0:el7-7 Complete!
2. レポジトリ登録確認
$ ls /etc/yum.repos.d | grep mysql mysql-community.repo mysql-community-source.repo
3. mysql-server パッケージ情報の確認
$ yum info mysql-community-server Loaded plugins: fastestmirror, langpacks Determining fastest mirrors * base: ftp-srv2.kddilabs.jp * epel: ftp.riken.jp * extras: ftp-srv2.kddilabs.jp * updates: ftp-srv2.kddilabs.jp mysql-connectors-community | 2.6 kB 00:00:00 mysql-tools-community | 2.6 kB 00:00:00 mysql57-community | 2.6 kB 00:00:00 (1/3): mysql-tools-community/x86_64/primary_db | 88 kB 00:00:00 (2/3): mysql-connectors-community/x86_64/primary_db | 80 kB 00:00:00 (3/3): mysql57-community/x86_64/primary_db | 268 kB 00:00:00 Available Packages Name : mysql-community-server Arch : x86_64 Version : 5.7.34 Release : 1.el7 Size : 173 M Repo : mysql57-community/x86_64 Summary : A very fast and reliable SQL database server URL : http://www.mysql.com/ License : Copyright (c) 2000, 2021, Oracle and/or its affiliates. All rights reserved. Under GPLv2 license as shown in the Description field. Description : The MySQL(TM) software delivers a very fast, multi-threaded, multi-user, : and robust SQL (Structured Query Language) database server. MySQL Server : is intended for mission-critical, heavy-load production systems as well : as for embedding into mass-deployed software. MySQL is a trademark of : Oracle and/or its affiliates : : The MySQL software has Dual Licensing, which means you can use the MySQL : software free of charge under the GNU General Public License : (http://www.gnu.org/licenses/). You can also purchase commercial MySQL : licenses from Oracle and/or its affiliates if you do not wish to be bound by the terms of : the GPL. See the chapter "Licensing and Support" in the manual for : further info. : : The MySQL web site (http://www.mysql.com/) provides the latest news and : information about the MySQL software. Also please see the documentation : and the manual for more information. : : This package includes the MySQL server binary as well as related utilities : to run and administer a MySQL server.
4. mysql-server インストール
$ sudo yum install -y mysql-community-server Loaded plugins: fastestmirror, langpacks Determining fastest mirrors * base: ty1.mirror.newmediaexpress.com * epel: ftp.riken.jp * extras: ty1.mirror.newmediaexpress.com * updates: ty1.mirror.newmediaexpress.com mysql-connectors-community | 2.6 kB 00:00:00 mysql-tools-community | 2.6 kB 00:00:00 mysql57-community | 2.6 kB 00:00:00 (1/3): mysql-connectors-community/x86_64/primary_db | 80 kB 00:00:00 (2/3): mysql-tools-community/x86_64/primary_db | 88 kB 00:00:00 (3/3): mysql57-community/x86_64/primary_db | 268 kB 00:00:00 Resolving Dependencies --> Running transaction check ---> Package mysql-community-server.x86_64 0:5.7.34-1.el7 will be installed --> Processing Dependency: mysql-community-common(x86-64) = 5.7.34-1.el7 for package: mysql-community-server-5.7.34-1.el7.x86_64 --> Processing Dependency: mysql-community-client(x86-64) >= 5.7.9 for package: mysql-community-server-5.7.34-1.el7.x86_64 --> Running transaction check ---> Package mysql-community-client.x86_64 0:5.7.34-1.el7 will be installed --> Processing Dependency: mysql-community-libs(x86-64) >= 5.7.9 for package: mysql-community-client-5.7.34-1.el7.x86_64 ---> Package mysql-community-common.x86_64 0:5.7.34-1.el7 will be installed --> Running transaction check ---> Package mariadb-libs.x86_64 1:5.5.65-1.el7 will be obsoleted --> Processing Dependency: libmysqlclient.so.18()(64bit) for package: 2:postfix-2.10.1-9.el7.x86_64 --> Processing Dependency: libmysqlclient.so.18(libmysqlclient_18)(64bit) for package: 2:postfix-2.10.1-9.el7.x86_64 ---> Package mysql-community-libs.x86_64 0:5.7.34-1.el7 will be obsoleting --> Running transaction check ---> Package mysql-community-libs-compat.x86_64 0:5.7.34-1.el7 will be obsoleting --> Finished Dependency Resolution Dependencies Resolved ===================================================================================================================================================== Package Arch Version Repository Size ===================================================================================================================================================== Installing: mysql-community-libs x86_64 5.7.34-1.el7 mysql57-community 2.4 M replacing mariadb-libs.x86_64 1:5.5.65-1.el7 mysql-community-libs-compat x86_64 5.7.34-1.el7 mysql57-community 1.2 M replacing mariadb-libs.x86_64 1:5.5.65-1.el7 mysql-community-server x86_64 5.7.34-1.el7 mysql57-community 173 M Installing for dependencies: mysql-community-client x86_64 5.7.34-1.el7 mysql57-community 25 M mysql-community-common x86_64 5.7.34-1.el7 mysql57-community 310 k Transaction Summary ===================================================================================================================================================== Install 3 Packages (+2 Dependent packages) Total download size: 203 M Downloading packages: warning: /var/cache/yum/x86_64/7/mysql57-community/packages/mysql-community-common-5.7.34-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY Public key for mysql-community-common-5.7.34-1.el7.x86_64.rpm is not installed (1/5): mysql-community-common-5.7.34-1.el7.x86_64.rpm | 310 kB 00:00:00 (2/5): mysql-community-libs-5.7.34-1.el7.x86_64.rpm | 2.4 MB 00:00:00 (3/5): mysql-community-libs-compat-5.7.34-1.el7.x86_64.rpm | 1.2 MB 00:00:00 (4/5): mysql-community-client-5.7.34-1.el7.x86_64.rpm | 25 MB 00:00:04 (5/5): mysql-community-server-5.7.34-1.el7.x86_64.rpm | 173 MB 00:00:17 ----------------------------------------------------------------------------------------------------------------------------------------------------- Total 11 MB/s | 203 MB 00:00:18 Retrieving key from file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql Importing GPG key 0x5072E1F5: Userid : "MySQL Release Engineering <mysql-build@oss.oracle.com>" Fingerprint: a4a9 4068 76fc bd3c 4567 70c8 8c71 8d3b 5072 e1f5 Package : mysql57-community-release-el7-7.noarch (@/mysql57-community-release-el7-7.noarch) From : /etc/pki/rpm-gpg/RPM-GPG-KEY-mysql Running transaction check Running transaction test Transaction test succeeded Running transaction Installing : mysql-community-common-5.7.34-1.el7.x86_64 1/6 Installing : mysql-community-libs-5.7.34-1.el7.x86_64 2/6 Installing : mysql-community-client-5.7.34-1.el7.x86_64 3/6 Installing : mysql-community-server-5.7.34-1.el7.x86_64 4/6 Installing : mysql-community-libs-compat-5.7.34-1.el7.x86_64 5/6 Erasing : 1:mariadb-libs-5.5.65-1.el7.x86_64 6/6 Verifying : mysql-community-libs-compat-5.7.34-1.el7.x86_64 1/6 Verifying : mysql-community-common-5.7.34-1.el7.x86_64 2/6 Verifying : mysql-community-client-5.7.34-1.el7.x86_64 3/6 Verifying : mysql-community-server-5.7.34-1.el7.x86_64 4/6 Verifying : mysql-community-libs-5.7.34-1.el7.x86_64 5/6 Verifying : 1:mariadb-libs-5.5.65-1.el7.x86_64 6/6 Installed: mysql-community-libs.x86_64 0:5.7.34-1.el7 mysql-community-libs-compat.x86_64 0:5.7.34-1.el7 mysql-community-server.x86_64 0:5.7.34-1.el7 Dependency Installed: mysql-community-client.x86_64 0:5.7.34-1.el7 mysql-community-common.x86_64 0:5.7.34-1.el7 Replaced: mariadb-libs.x86_64 1:5.5.65-1.el7 Complete!
5. インストールされた mysql バージョン確認
$ mysqld --version mysqld Ver 5.7.34 for Linux on x86_64 (MySQL Community Server (GPL))
6. mysqld 開始
$ sudo systemctl start mysqld
7. mysqld プロセス確認
$ systemctl status mysqld ● mysqld.service - MySQL Server Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled) Active: active (running) since xxxx; 29s ago Docs: man:mysqld(8) http://dev.mysql.com/doc/refman/en/using-systemd.html Process: 31991 ExecStart=/usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid $MYSQLD_OPTS (code=exited, status=0/SUCCESS) Process: 31932 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS) Main PID: 31995 (mysqld) Tasks: 27 Memory: 321.3M CGroup: /system.slice/mysqld.service └─31995 /usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid
8. mysqld 自動起動確認
$ systemctl is-enabled mysqld enabled ※もし enabled でなかったら、以下のコマンドで有効にする $ sudo systemctl enable mysqld
9. mysql 初期root パスワード確認
$ sudo cat /var/log/mysqld.log | grep root [Note] A temporary password is generated for root@localhost: XXXXXX
10. ログインしてパスワード変更
$ mysql -u root -p mysql> SET PASSWORD = PASSWORD('something_you_like');
$ vi /etc/my.cnf #以下を追記 character_set_server=utf8 skip-character-set-client-handshake
12. 文字コードチェック
mysql> show variables like "chara%"; +--------------------------+----------------------------+ | Variable_name | Value | +--------------------------+----------------------------+ | character_set_client | utf8 | | character_set_connection | utf8 | | character_set_database | utf8 | | character_set_filesystem | binary | | character_set_results | utf8 | | character_set_server | utf8 | | character_set_system | utf8 | | character_sets_dir | /usr/share/mysql/charsets/ | +--------------------------+----------------------------+ 8 rows in set (0.01 sec)
13. Database 新規作成
mysql> CREATE DATABASE mydb;
14. ユーザ新規作成
mysql> create user myuser@localhost identified by 'mypass';
15. データベースへの権限設定
mysql> show grants for myuser@localhost; mysql> grant create on mydb.* to myuser@localhost;