Score:0

เชื่อมต่อกับ mysql db ที่ติดตั้งไว้

ธง in

ฉันได้ติดตั้งบนแอปพลิเคชันเซิร์ฟเวอร์ mysql แล้ว mysql Ver 8.0.23-0ubuntu0.20.04.1 สำหรับ Linux บน x86_64 ((Ubuntu)). ระบบปฏิบัติการของฉันบน VPS คือ อูบุนตู 20.04.1 LTS.

เพื่อจัดการฐานข้อมูลนี้ ฉันเชื่อมต่อในเครื่องผ่าน SSH ไปยังเซิร์ฟเวอร์ จากนั้นจึงเข้าถึงฐานข้อมูล

อย่างไรก็ตาม บริการต่างๆ เช่น google data studio จำเป็นต้องมี jdbc url หรือชื่อโฮสต์ของฐานข้อมูล

ป้อนคำอธิบายรูปภาพที่นี่

ฉันลองใช้ IP ของเซิร์ฟเวอร์เป็นชื่อโฮสต์ แล้วใช้พอร์ต ชื่อผู้ใช้ pwd ที่ถูกต้อง อย่างไรก็ตาม ฉันได้รับ:

ป้อนคำอธิบายรูปภาพที่นี่

ฉันคิดว่าชื่อโฮสต์ของฉันผิดเนื่องจากอยู่ในเซิร์ฟเวอร์ โลคัลโฮสต์ และไม่ใช่ IP ของเซิร์ฟเวอร์

ข้อเสนอแนะใด ๆ เกี่ยวกับวิธีการเชื่อมต่อกับฐานข้อมูลหรือค้นหาชื่อโฮสต์ที่ถูกต้อง?

ฉันขอขอบคุณสำหรับคำตอบของคุณ!

อัปเดต

วิ่ง ss -nlp ฉันเข้าใจ:

root@myVPS:~# sudo ss -nlp | grep mysql
u_str ฟัง 0 70 /var/run/mysqld/mysqlx.sock 190906736 * 0 ผู้ใช้:(("mysqld",pid=1668517,fd=33))                                           
u_str LISTEN 0 151 /var/run/mysqld/mysqld.sock 190906739 * 0 ผู้ใช้:(("mysqld",pid=1668517,fd=36))                                           
u_dgr UNCONN 0 0 * 190906575 * 12685 ผู้ใช้:(("mysqld",pid=1668517,fd=3))                                            
tcp ฟัง 0 70 127.0.0.1:33060 0.0.0.0:* ผู้ใช้:(("mysqld",pid=1668517,fd=32))                                           
tcp LISTEN 0 151 *:3306 *:* ผู้ใช้:(("mysqld",pid=1668517,fd=34))                                           

Score:2
ธง ws

(Mysql on Ubuntu? I thought this had been replaced in the repos with Mariadb).

You'll notice that you are being asked for a username and password. Did you create one in MySQL? Did you create a database to use? This can seem like a chicken and egg problem (it is). You should start by creating a database aand a user to access it.

I believe the default build of MySQL currently uses so_peer authentication, so you can connect as root without a password using the mysql cli tool:

user@host ~$ sudo mysql
...
mysql > CREATE USER `testuser`@`localhost` IDENTIFIED BY 's3cr3t';
mysql > CREATE USER `testuser`@`%` IDENTIFIED BY 's3cr3t';
mysql > CREATE DATABASE example1;
mysql > GRANT ALL ON example1.* TO `testuser`@`localhost`;
mysql > GRANT ALL ON example1.* TO `testuser`@`%`;
mysql > FLUSH PRIVILEGES;
mysql > quit

In the context above '%' means any IP address. MySQL attaches a special meaning to 'localhost'. It DOES NOT describe the loopback network interface - it means the access is via a filesystem socket. This can cause a lot of confusion.

Usually MySQL comes configured to listen on the filesystem socket and sometimes the loopback interface. You can check this (and indeed if the mysql service is running at all with....

user@host ~$ sudo ss-nlp | grep mysql
u_str  LISTEN     0      128    /var/run/mysqld/mysqld.sock 842576                * 0                   users:(("mysqld",pid=16463,fd=20))
tcp    LISTEN     0      128    127.0.0.1:3306                  *:*

Here I can see that the server is using the filesystem socket at /var/run/mysqld/mysqld.sock and port 3306 on the loopback interface.

The dialog you've shown us above does not obviously accomodate a filesystem socket - so you'll need to use the loopback interface. In order to connect to the network socket, you MUST tell the mysql client the host is at "127.0.0.1", not localhost.

in flag
ขอบคุณสำหรับการตอบกลับของคุณ! อย่างไรก็ตาม google data studio ต้องการชื่อโฮสต์ไปยังเซิร์ฟเวอร์ mysql ถ้าฉันลอง `127.0.0.1:33060` ฉันไม่สามารถเชื่อมต่อกับเซิร์ฟเวอร์อื่นและไม่ใช่บนเซิร์ฟเวอร์ของ Google มีวิธี "ปรับปรุง" การติดตั้ง mysql ปัจจุบันของฉันด้วยความสามารถของเซิร์ฟเวอร์หรือไม่?
ws flag
ใช่ - แต่คุณกำลังทำเกินขอบเขตของคำถามของคุณที่นี่ ฉันจะพบว่า * พิเศษมาก * ที่ Google Data Studio จะไม่ยอมรับ `127.0.0.1` เป็นชื่อโฮสต์ (ควรป้อนพอร์ตในฟิลด์แยกต่างหาก) แต่มันเป็นเรื่องเล็กน้อยที่จะเหลวไหลนามแฝงอื่นในไฟล์โฮสต์ (เนื่องจาก นี่คือ Linux ไม่ใช่โฮสต์ MS-Windows) เมื่อคุณได้จัดเรียงแล้ว ให้ใช้ Google สำหรับ "mysql bind_address" เพื่อค้นหาวิธีเปิดเผยบริการทั่วทั้งเครือข่าย

โพสต์คำตอบ

คนส่วนใหญ่ไม่เข้าใจว่าการถามคำถามมากมายจะปลดล็อกการเรียนรู้และปรับปรุงความสัมพันธ์ระหว่างบุคคล ตัวอย่างเช่น ในการศึกษาของ Alison แม้ว่าผู้คนจะจำได้อย่างแม่นยำว่ามีคำถามกี่ข้อที่ถูกถามในการสนทนา แต่พวกเขาไม่เข้าใจความเชื่อมโยงระหว่างคำถามและความชอบ จากการศึกษาทั้ง 4 เรื่องที่ผู้เข้าร่วมมีส่วนร่วมในการสนทนาด้วยตนเองหรืออ่านบันทึกการสนทนาของผู้อื่น ผู้คนมักไม่ตระหนักว่าการถามคำถามจะมีอิทธิพลหรือมีอิทธิพลต่อระดับมิตรภาพระหว่างผู้สนทนา