Windows XP Windows 7 Windows 2003 Windows Vista Windows 綜合教學 Linux 系統教學
Windows 10 Windows 8 Windows 2008 Windows NT Windows Server 電腦軟體教學

Linux MySQL 快速進入與常用指令速查表

編輯:Linux 系統常見問題解答

Linux 下 MySQL 客戶端常用連線、切換資料庫、查看結構指令整理。

1. 連線指令


mysql -h 127.0.0.1 -u root -p123456   # 指定 IP、用戶、密碼
mysql -u root -p                      # 本地 root,回車後輸入密碼
  • -h:主機 IP/主機名
  • -u:用戶名
  • -p:密碼 (緊跟 -p 直接寫密碼不安全,建議只寫 -p 互動輸入)

2. 進入資料庫


SHOW DATABASES;          # 列出所有資料庫
USE nserver;             # 進入 nserver 資料庫
SHOW TABLES;             # 列出當前資料庫所有表

3. 常用操作

  • DESC table_name; — 查看表結構
  • SELECT * FROM table_name LIMIT 10; — 查詢前 10 筆
  • EXIT 或 QUIT — 退出客戶端

建議配合 mysql -u root -p -e "SQL語句" 在腳本中非互動執行。

Copyright © Windows教程網 All Rights Reserved