Computer >> Hướng Dẫn Máy Tính >  >> Lập Trình >> MySQL

Kết nối MySQL bằng binary mysql tại command prompt

Bạn có thể kết nối MySQL sử dụng binary mysql tại command prompt. Ví dụ minh họa:

Ví dụ

Sử dụng câu lệnh sau để kết nối MySQL server từ command prompt:

[root@host]# mysql -u root -p Enter password:******

Sau khi nhập mật khẩu đúng, bạn sẽ nhận được dấu nhắc mysql> nơi có thể thực thi bất kỳ lệnh SQL nào. Kết quả như sau:

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.

Ví dụ dùng user root, nhưng bạn có thể dùng user khác. Mọi user đều có thể thực hiện các thao tác SQL được phép.

Để ngắt kết nối, dùng lệnh exit tại dấu nhắc mysql>:

mysql> exit
Bye