ติดตั้ง Mysql บน CentOS7
การติดตั้ง mysql บน enterprise centos 7 สามารถเลือกติดตั้ง ได้จาก MySQL community yum repository หรือ mariadb
MYSQL community เปิด browser ไปที่ https://dev.mysql.com/downloads/repo/yum/
Download file และทำการติดตั้ง
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
$ wget https://dev.mysql.com/get/mysql57-community-release-el7-11.noarch.rpm $ md5sum mysql57-community-release-el7-11.noarch.rpm c070b754ce2de9f714ab4db4736c7e05 mysql57-community-release-el7-11.noarch.rpm $ sudo rpm -ivh mysql57-community-release-el7-11.noarch.rpm $ sudo yum install mysql-server $ sudo systemctl start mysqld $ sudo systemctl enable mysqld $ sudo systemctl status mysqld ● mysqld.service - MySQL Server Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled) Active: active (running) since Mon 2018-02-12 04:10:30 UTC; 7min ago Docs: man:mysqld(8) http://dev.mysql.com/doc/refman/en/using-systemd.html Main PID: 4378 (mysqld) CGroup: /system.slice/mysqld.service └─4378 /usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid Feb 12 04:10:25 localhost.localdomain systemd[1]: Starting MySQL Server... Feb 12 04:10:30 localhost.localdomain systemd[1]: Started MySQL Server. |
security firewall
ตั้งค่า ไฟล์วอล ที่ พอร์ต 3306 โดยกำหนดให้กับ interface eth1 ใน zone truested การ active โซนใน ไฟล์วอลจะเกิดขึ้นโดยอัตโนมัติทันทีที่มีการ add interace ให้แก่ โซน ในคำสั่ง firewall-cmd จะต้อง ระบุบ –permanent ทุกครั้ง และจึงทำการ –reload
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
$ sudo systemctl start firewalld $ sudo systemctl enable firewalld $ sudo firewall-cmd --get-zones $ sudo firewall-cmd --get-default-zone $ sudo firewall-cmd --list-all public (active) target: default icmp-block-inversion: no interfaces: eth0 eth1 sources: services: dhcpv6-client ssh ports: protocols: masquerade: no forward-ports: sourceports: icmp-blocks: rich rules: $ sudo firewall-cmd --permanent --add-interface=eth1 --zone=trusted $ sudo firewall-cmd --permanent --zone=trusted --add-source=192.168.30.0/24 $ sudo firewall-cmd --permanent --zone=trusted --add-port=3306/tcp $ sudo firewall-cmd --reload $ firewall-cmd --get-active-zones public interfaces: eth0 trusted interfaces: eth1 sources: 192.168.30.0/24 |
หลังการติดตั้ง installer ได้ทำการสร้าง temporary password ให้ตรวจสอบดังนี้
1 2 3 4 5 6 7 8 9 10 |
$ sudo grep 'temporary password' /var/log/mysqld.log 2018-02-12T04:10:28.290165Z 1 [Note] A temporary password is generated \ for root@localhost: ?eUbcipl:8E8 <--- แต่ละเครื่องผลที่ได้จะไม่เหมือนกัน $ sudo mysql_secure_installation Securing the MySQL server deployment. Enter password for user root: |
หลังจากกรอก รหัสชั่วคราวเรียบร้อย ระบบจะให้เราทำการเปลี่ยน password อีกครั้งword อีกครั้ง
1 2 3 |
The existing password for the user account root has expired. Please set a new password. New password: |
1 2 |
Estimated strength of the password: 100 Change the password for root ? (Press y|Y for Yes, any other key for No) : |
1 2 3 4 5 6 7 8 9 10 |
... skipping. 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. |
ยกเลิก root login remote
1 2 3 4 5 6 7 8 9 10 11 |
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
1 2 3 4 5 6 7 8 9 |
Remove test database and access to it? (Press y|Y for Yes, any other key for No) : 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
1 2 3 4 |
Reload privilege tables now? (Press y|Y for Yes, any other key for No) : y Success. All done! |
Login mysql -u root -p -h localhost
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
$ mysql -u root -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 7 Server version: 5.7.21 MySQL Community Server (GPL) Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved. 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> |