首頁 資料庫 mysql教程 mysql常用命令案例_MySQL

mysql常用命令案例_MySQL

Jun 01, 2016 pm 01:10 PM

Microsoft Windows [版本 6.1.7601]
版权所有 (c) 2009 Microsoft Corporation。保留所有权利。

C:/Users/Administrator>net start mysql56
MySQL56 服务正在启动 ..
MySQL56 服务已经启动成功。


C:/Users/Administrator>mysql -u root -p
Enter password: *****
Welcome to the MySQL monitor.  Commands end with ; or /g.
Your MySQL connection id is 1
Server version: 5.6.10 MySQL Community Server (GPL)

Type 'help;' or '/h' for help. Type '/c' to clear the buffer.

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| bbs                |
| book               |
| connect            |
| db_bbs             |
| db_database25      |
| dreamtimenews      |
| hibernate          |
| hrsystem           |
| jeebbs             |
| jeecmsv5           |
| meiupic            |
| mysql              |
| news               |
| nmsdb              |
| oscommerce         |
| performance_schema |
| sakila             |
| test               |
| vote               |
| world              |
+--------------------+
21 rows in set (0.23 sec)

mysql> use test;
Database changed
mysql> show tables;
+----------------+
| Tables_in_test |
+----------------+
| employees      |
| student        |
+----------------+
2 rows in set (0.00 sec)

mysql> select * from employees;
+---------+----------+--------+
| empname | title    | salary |
+---------+----------+--------+
| 中签    | 职员     |   5000 |
| 公共    | 职员     |   4500 |
| 寝室    | 职员     |   3500 |
| 就是    | 职员     |   5500 |
| 张三    | 部门经理 |   8000 |
| 李四    | 职员     |   4000 |
| 李帅    | 职员     |   3000 |
| 李波    | 职员     |   3000 |
| 王五    | 职员     |   4000 |
| 高就    | 经理     |   6000 |
+---------+----------+--------+
10 rows in set (0.10 sec)

mysql> create table persons
    -> (
    -> id int not null,
    -> name varchar(20),
    -> mgrid varchar(20)
    -> );
Query OK, 0 rows affected (0.11 sec)


mysql> insert into persons(id,name) values(1,'zwh1');
Query OK, 1 row affected (0.01 sec)

mysql> insert into persons(id,name) values(2,'zwh2');
Query OK, 1 row affected (0.00 sec)

mysql> alter table persons
    -> modify column mgrid
    -> int;
Query OK, 2 rows affected (0.07 sec)
Records: 2  Duplicates: 0  Warnings: 0

mysql> desc persons;
+-------+-------------+------+-----+---------+-------+
| Field | Type        | Null | Key | Default | Extra |
+-------+-------------+------+-----+---------+-------+
| id    | int(11)     | NO   |     | NULL    |       |
| name  | varchar(20) | YES  |     | NULL    |       |
| mgrid | int(11)     | YES  |     | NULL    |       |
+-------+-------------+------+-----+---------+-------+
3 rows in set (0.06 sec)

mysql> select * from persons;
+----+------+-------+
| id | name | mgrid |
+----+------+-------+
|  1 | zwh1 |  NULL |
|  2 | zwh2 |  NULL |
+----+------+-------+
2 rows in set (0.00 sec)

mysql> insert into persons(id,name,mgrid) values(2,'zwh2','1');
Query OK, 1 row affected (0.00 sec)

mysql> insert into persons(id,name,mgrid) values(4,'zwh4','2');
Query OK, 1 row affected (0.00 sec)

mysql> select * from persons;
+----+------+-------+
| id | name | mgrid |
+----+------+-------+
|  1 | zwh1 |  NULL |
|  2 | zwh2 |  NULL |
|  2 | zwh2 |     1 |
|  4 | zwh4 |     2 |
+----+------+-------+
4 rows in set (0.00 sec)

mysql> update persons set id=3 where mgrid=1;
Query OK, 1 row affected (0.03 sec)
Rows matched: 1  Changed: 1  Warnings: 0

mysql> update persons set name='zwh3' where mgrid=1;
Query OK, 1 row affected (0.01 sec)
Rows matched: 1  Changed: 1  Warnings: 0

mysql> select * from persons;
+----+------+-------+
| id | name | mgrid |
+----+------+-------+
|  1 | zwh1 |  NULL |
|  2 | zwh2 |  NULL |
|  3 | zwh3 |     1 |
|  4 | zwh4 |     2 |
+----+------+-------+
4 rows in set (0.00 sec)

mysql> select id,name,person2.mgrid,person2.name as mgrname
    -> from persons inner join persons as person2
    -> on persons.id=person2.mgrid;
ERROR 1052 (23000): Column 'id' in field list is ambiguous
mysql> select persons.id,persons.name,person2.mgrid,person2.name as mgrname
    -> from persons inner join persons as person2
    -> on persons.id=person2.mgrid;
+----+------+-------+---------+
| id | name | mgrid | mgrname |
+----+------+-------+---------+
|  1 | zwh1 |     1 | zwh3    |
|  2 | zwh2 |     2 | zwh4    |
+----+------+-------+---------+

2 rows in set (0.03 sec)

mysql> select persons.id as mgrid,persons.name as mgrname,person2.id,person2.name
    -> from persons inner join persons as person2
    -> on persons.id=person2.mgrid;
+-------+---------+----+------+
| mgrid | mgrname | id | name |
+-------+---------+----+------+
|     1 | zwh1    |  3 | zwh3 |
|     2 | zwh2    |  4 | zwh4 |
+-------+---------+----+------+
2 rows in set (0.00 sec)



mysql>
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn

熱AI工具

Undresser.AI Undress

Undresser.AI Undress

人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover

AI Clothes Remover

用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool

Undress AI Tool

免費脫衣圖片

Clothoff.io

Clothoff.io

AI脫衣器

AI Hentai Generator

AI Hentai Generator

免費產生 AI 無盡。

熱門文章

R.E.P.O.能量晶體解釋及其做什麼(黃色晶體)
1 個月前 By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O.最佳圖形設置
1 個月前 By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O.如果您聽不到任何人,如何修復音頻
1 個月前 By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O.聊天命令以及如何使用它們
1 個月前 By 尊渡假赌尊渡假赌尊渡假赌

熱工具

記事本++7.3.1

記事本++7.3.1

好用且免費的程式碼編輯器

SublimeText3漢化版

SublimeText3漢化版

中文版,非常好用

禪工作室 13.0.1

禪工作室 13.0.1

強大的PHP整合開發環境

Dreamweaver CS6

Dreamweaver CS6

視覺化網頁開發工具

SublimeText3 Mac版

SublimeText3 Mac版

神級程式碼編輯軟體(SublimeText3)

說明InnoDB全文搜索功能。 說明InnoDB全文搜索功能。 Apr 02, 2025 pm 06:09 PM

InnoDB的全文搜索功能非常强大,能够显著提高数据库查询效率和处理大量文本数据的能力。1)InnoDB通过倒排索引实现全文搜索,支持基本和高级搜索查询。2)使用MATCH和AGAINST关键字进行搜索,支持布尔模式和短语搜索。3)优化方法包括使用分词技术、定期重建索引和调整缓存大小,以提升性能和准确性。

如何使用Alter Table語句在MySQL中更改表? 如何使用Alter Table語句在MySQL中更改表? Mar 19, 2025 pm 03:51 PM

本文討論了使用MySQL的Alter Table語句修改表,包括添加/刪除列,重命名表/列以及更改列數據類型。

與MySQL中使用索引相比,全表掃描何時可以更快? 與MySQL中使用索引相比,全表掃描何時可以更快? Apr 09, 2025 am 12:05 AM

全表掃描在MySQL中可能比使用索引更快,具體情況包括:1)數據量較小時;2)查詢返回大量數據時;3)索引列不具備高選擇性時;4)複雜查詢時。通過分析查詢計劃、優化索引、避免過度索引和定期維護表,可以在實際應用中做出最優選擇。

可以在 Windows 7 上安裝 mysql 嗎 可以在 Windows 7 上安裝 mysql 嗎 Apr 08, 2025 pm 03:21 PM

是的,可以在 Windows 7 上安裝 MySQL,雖然微軟已停止支持 Windows 7,但 MySQL 仍兼容它。不過,安裝過程中需要注意以下幾點:下載適用於 Windows 的 MySQL 安裝程序。選擇合適的 MySQL 版本(社區版或企業版)。安裝過程中選擇適當的安裝目錄和字符集。設置 root 用戶密碼,並妥善保管。連接數據庫進行測試。注意 Windows 7 上的兼容性問題和安全性問題,建議升級到受支持的操作系統。

如何為MySQL連接配置SSL/TLS加密? 如何為MySQL連接配置SSL/TLS加密? Mar 18, 2025 pm 12:01 PM

文章討論了為MySQL配置SSL/TLS加密,包括證書生成和驗證。主要問題是使用自簽名證書的安全含義。[角色計數:159]

哪些流行的MySQL GUI工具(例如MySQL Workbench,PhpMyAdmin)是什麼? 哪些流行的MySQL GUI工具(例如MySQL Workbench,PhpMyAdmin)是什麼? Mar 21, 2025 pm 06:28 PM

文章討論了流行的MySQL GUI工具,例如MySQL Workbench和PhpMyAdmin,比較了它們對初學者和高級用戶的功能和適合性。[159個字符]

InnoDB中的聚類索引和非簇索引(次級索引)之間的差異。 InnoDB中的聚類索引和非簇索引(次級索引)之間的差異。 Apr 02, 2025 pm 06:25 PM

聚集索引和非聚集索引的區別在於:1.聚集索引將數據行存儲在索引結構中,適合按主鍵查詢和範圍查詢。 2.非聚集索引存儲索引鍵值和數據行的指針,適用於非主鍵列查詢。

您如何處理MySQL中的大型數據集? 您如何處理MySQL中的大型數據集? Mar 21, 2025 pm 12:15 PM

文章討論了處理MySQL中大型數據集的策略,包括分區,碎片,索引和查詢優化。

See all articles