Xshell怎么連接數據庫


 之前一直用Navicat Premium鏈接數據庫,其實在xshell也可以鏈接數據庫,本文將先介紹如何用xshell鏈接數據庫的方法。

1.打開xshell,連接上

輸入指令:mysql -h 192.168.10.120 -u root -p 回車,-h后面是數據庫hostname,-u后面是數據庫用戶名,-p后面是密碼

 1 root@VM-0-12-centos[14:05:47]:~
 2 $ mysql -h ** -u ** -p
 3 Enter password: 
 4 Welcome to the MySQL monitor.  Commands end with ; or \g.
 5 Your MySQL connection id is 52674
 6 Server version: 5.6.25 Source distribution
 7 
 8 Copyright (c) 2000, 2021, Oracle and/or its affiliates. All rights reserved.
 9 
10 Oracle is a registered trademark of Oracle Corporation and/or its
11 affiliates. Other names may be trademarks of their respective
12 owners.
13 
14 Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
15 
16 mysql>

這樣就表示連接上了。里面輸入SQL語句就和MySQL一樣使用,注意SQL語句的結尾分號“;”必須有!,否則會報錯。

 1 #查看數據庫
 2 mysql> show databases;
 3 +--------------------+
 4 | Database           |
 5 +--------------------+
 6 | n_schema |
 7 | ao_students |
 8 | students |
 9 | aoshi          |
10 | test_ab            |
11 +--------------------+
12 5 rows in set (0.02 sec)

2.查看數據表:

 1 mysql> use test_ab;
 2 Reading table information for completion of table and column names
 3 You can turn off this feature to get a quicker startup with -A
 4 
 5 Database changed
 6 mysql> show tables;
 7 +-------------------+
 8 | Tables_in_test_ab |
 9 +-------------------+
10 | mytb1             |
11 | tb                |
12 | tb_emp1           |
13 | tb_emp2           |
14 | tg                |
15 | tt                |
16 | tt1               |
17 | ty                |
18 +-------------------+
19 8 rows in set (0.03 sec)

 表格查詢:

 1 mysql> select * from ty;
 2 +----+--------------+--------+-------+
 3 | id | nam          | deptid | slary |
 4 +----+--------------+--------+-------+
 5 |  1 | 嗯嗯呃呃 |      1 | 20000 |
 6 |  2 |              |      2 | 33434 |
 7 |  3 | 嗯嗯       |      1 | 20000 |
 8 |  4 | 開          |      2 | 33434 |
 9 |  5 | erew         |      1 | 20000 |
10 |  6 |              |      2 | 33434 |
11 |  7 |              |      5 | 25000 |
12 |  8 | 張三       |      1 | 20000 |
13 |  9 | 李四       |      2 | 33434 |
14 | 10 | 王五       |      1 | 20000 |
15 | 11 | 人          |      2 | 33434 |
16 | 12 | 有          |      1 | 20000 |
17 | 13 |              |      5 | 25000 |
18 | 14 | 張三       |      3 |  1984 |
19 | 15 | 李四       |     45 |  1982 |
20 | 16 | 王五       |     76 |  1982 |
21 | 17 | 人          |     48 |  1988 |
22 | 18 | 有          |     90 |  1928 |
23 | 19 |              |     23 |  1988 |
24 +----+--------------+--------+-------+
25 19 rows in set (0.03 sec)

出現中文亂碼問題,可以用以下命令臨時解決,為什么是臨時解決?重新登入后還是有有亂碼問題。表格沒有對齊—現在各大網站還沒有更好的解決方案。

1 mysql> set names utf8;
2 Query OK, 0 rows affected (0.03 sec)

今天先寫這些,后面再更。

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM