คุณสามารถเชื่อมต่อฐานข้อมูล MySQL โดยใช้ไบนารี mysql ที่คำสั่งพรอมป์ต์ สามารถเข้าใจได้จากตัวอย่างต่อไปนี้
ตัวอย่าง
เราสามารถใช้คำสั่งต่อไปนี้เพื่อเชื่อมต่อกับเซิร์ฟเวอร์ MySQL จากคำสั่งพรอมป์ต์
[root@host]# mysql -u root -p Enter password:******
สิ่งนี้จะให้พรอมป์ต์คำสั่ง mysql> ซึ่งเราจะสามารถรันคำสั่ง SQL ใดๆ ได้ ผลลัพธ์ของคำสั่งข้างต้นคือ
Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 4 Server version: 5.7.20 MySQL Community Server (GPL) Copyright (c) 2000, 2017, 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.
ในตัวอย่างข้างต้น เราใช้ root เป็นผู้ใช้ แต่คุณสามารถใช้ผู้ใช้อื่นได้เช่นกัน ผู้ใช้ทุกคนจะสามารถดำเนินการ SQL ทั้งหมดที่ได้รับอนุญาตให้ผู้ใช้นั้นๆ
เราสามารถตัดการเชื่อมต่อจากฐานข้อมูล MySQL ได้ทุกเมื่อโดยใช้คำสั่ง exit ที่พรอมป์ต์ mysql>
mysql> exit Bye