Android

วิธีการติดตั้ง mysql บนเดเบียน 9

Связи по месту 145.500 МГц

Связи по месту 145.500 МГц

สารบัญ:

Anonim

ด้วยการเปิดตัว Debian 9 Stretch MySQL ระบบจัดการฐานข้อมูลเชิงสัมพันธ์แบบโอเพ่นซอร์สที่ได้รับความนิยมมากที่สุดในโลกไม่สามารถใช้งานได้ในพื้นที่เก็บข้อมูลของ Debian อีกต่อไปและ MariaDB ได้กลายเป็นระบบฐานข้อมูลเริ่มต้น MariaDB สามารถใช้แทน MySQL ในการแทนที่แบบดรอปดาวน์ได้

ในบทช่วยสอนนี้เราจะแสดงวิธีการติดตั้งและรักษาความปลอดภัยของ MySQL บนเครื่อง Debian 9 จาก MySQL Apt Repository หากแอปพลิเคชันของคุณไม่มีข้อกำหนดเฉพาะคุณควรใช้ MariaDB ซึ่งเป็นระบบฐานข้อมูลเริ่มต้นใน Debian 9

ข้อกำหนดเบื้องต้น

ก่อนดำเนินการกับบทช่วยสอนนี้ต่อให้แน่ใจว่าคุณได้เข้าสู่ระบบในฐานะผู้ใช้ที่มีสิทธิ์ sudo

ขั้นตอนที่ 1: กำหนดค่า MySQL Repository

ในการเพิ่มที่เก็บ MySQL APT ลงในระบบของคุณให้ไปที่หน้าดาวน์โหลดที่เก็บและดาวน์โหลดแพ็คเกจล่าสุดโดยใช้คำสั่ง wget ต่อไปนี้:

wget

เมื่อการดาวน์โหลดเสร็จสิ้นให้ติดตั้งแพ็กเกจรีลีสด้วยคำสั่งต่อไปนี้:

sudo dpkg -i mysql-apt-config_0.8.10-1_all.deb

คุณจะพบกับเมนูการตั้งค่าที่คุณสามารถเลือกเวอร์ชัน MySQL ที่คุณต้องการติดตั้ง

ขั้นตอนที่ 3: ตรวจสอบการติดตั้ง MySQL

เมื่อการติดตั้งเสร็จสิ้นบริการ MySQL จะเริ่มโดยอัตโนมัติ

เราสามารถตรวจสอบสถานะบริการ MySQL ได้โดยพิมพ์:

sudo systemctl status mysql

● mysql.service - MySQL Community Server Loaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset: Active: active (running) since Thu 2018-08-02 17:22:18 UTC; 18s ago Docs: man:mysqld(8) http://dev.mysql.com/doc/refman/en/using-systemd.html Process: 14797 ExecStartPre=/usr/share/mysql-8.0/mysql-systemd-start pre (co Main PID: 14832 (mysqld) Status: "SERVER_OPERATING" Tasks: 37 (limit: 4915) CGroup: /system.slice/mysql.service └─14832 /usr/sbin/mysqld

ขั้นตอนที่ 4: การรักษาความปลอดภัย MySQL

รันคำสั่ง mysql_secure_installation เพื่อตั้งค่ารหัสผ่านรูทและเพื่อปรับปรุงความปลอดภัยของการติดตั้ง MySQL:

sudo mysql_secure_installation

Securing the MySQL server deployment. Connecting to MySQL using a blank password. VALIDATE PASSWORD COMPONENT can be used to test passwords and improve security. It checks the strength of password and allows the users to set only those passwords which are secure enough. Would you like to setup VALIDATE PASSWORD component? Press y|Y for Yes, any other key for No:

คุณจะถูกขอให้กำหนดค่า VALIDATE PASSWORD PLUGIN ซึ่งใช้ในการทดสอบความแข็งแรงของรหัสผ่านผู้ใช้ MySQL นโยบายการตรวจสอบรหัสผ่านมีสามระดับต่ำปานกลางและรัดกุม กด ENTER หากคุณไม่ต้องการตั้งค่าปลั๊กอินรหัสผ่านที่ถูกต้อง

Please set the password for root here. New password: Re-enter new password:

ในพรอมต์ถัดไปคุณจะถูกขอให้ตั้งรหัสผ่านสำหรับผู้ใช้รูท MySQL

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

เมื่อคุณตั้งรหัสผ่านรูทแล้วสคริปต์จะขอให้คุณลบผู้ใช้ที่ไม่ระบุชื่อออกให้ จำกัด การเข้าถึงของผู้ใช้รูทไปยังเครื่องโลคัลและลบฐานข้อมูลทดสอบ คุณควรตอบ“ Y” (ใช่) สำหรับทุกคำถาม

ขั้นตอนที่ 5: เชื่อมต่อกับ MySQL จากบรรทัดคำสั่ง

ในการโต้ตอบกับ MySQL ผ่านเทอร์มินัลเราจะใช้ไคลเอนต์ MySQL ซึ่งติดตั้งเป็นการอ้างอิงของแพ็คเกจเซิร์ฟเวอร์ MySQL

ในการล็อกอินเข้าสู่เซิร์ฟเวอร์ MySQL ในฐานะผู้ใช้รูท:

mysql -u root -p

คุณจะได้รับแจ้งให้ป้อนรหัสผ่านรูทที่คุณตั้งไว้ก่อนหน้านี้เมื่อ mysql_secure_installation สคริปต์ mysql_secure_installation

เมื่อคุณป้อนรหัสผ่านคุณจะพบกับเปลือก MySQL ดังที่แสดงด้านล่าง:

Welcome to the MySQL monitor. Commands end with; or \g. Your MySQL connection id is 10 Server version: 8.0.12 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>

สร้างฐานข้อมูล

เมื่อคุณเชื่อมต่อกับเปลือก MySQL คุณสามารถสร้างฐานข้อมูลใหม่โดยพิมพ์คำสั่งต่อไปนี้:

CREATE DATABASE new_database;

Query OK, 1 row affected (0.00 sec)

สร้างตาราง

ตอนนี้เราได้สร้างฐานข้อมูลแล้วเราสามารถสร้างตารางเพื่อเก็บข้อมูลได้

ก่อนที่จะรันคำสั่ง SQL เพื่อสร้างตารางเราจำเป็นต้องเชื่อมต่อกับฐานข้อมูล:

use new_database;

ในตัวอย่างนี้เราจะสร้างตารางอย่างง่ายชื่อผู้ contacts มีสามเขตข้อมูล id name และ email :

CREATE TABLE contacts (id INT PRIMARY KEY, name VARCHAR(30), email VARCHAR(30));

Query OK, 1 row affected (0.00 sec)

ข้อสรุป

ในบทช่วยสอนนี้เราได้แสดงวิธีการติดตั้งและรักษาความปลอดภัยเซิร์ฟเวอร์ MySQL บนเซิร์ฟเวอร์ Debian 9 เราได้แสดงให้คุณเห็นถึงวิธีการเชื่อมต่อกับเชลล์ MySQL และวิธีสร้างฐานข้อมูลและตารางใหม่

ตอนนี้เซิร์ฟเวอร์ MySQL ของคุณเริ่มทำงานและคุณรู้วิธีเชื่อมต่อเซิร์ฟเวอร์ MySQL จากบรรทัดคำสั่งคุณอาจต้องการตรวจสอบคำแนะนำต่อไปนี้:

mysql debian