新手操作mySQL命令 必看经典图解

本文演示了如何使用命令行模式连接MySQL数据库并执行基本操作,包括显示数据库列表、创建数据库及表、插入数据、查询数据等。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Microsoft Windows XP [版本 5.1.2600]  //命令行模式下操作
(C) 版权所有 1985-2001 Microsoft Corp.

C:\Documents and Settings\reton.ma>d:

D:\>cd D:\Program Files\MySQL\MySQL Server 5.0\bin

D:\Program Files\MySQL\MySQL Server 5.0\bin>mysql -uroot -polcp
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 9
Server version: 5.0.67-community-nt MySQL Community Edition (GPL)

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

mysql> exit
Bye

D:\Program Files\MySQL\MySQL Server 5.0\bin>mysql -uroot -p
Enter password: ****
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 10
Server version: 5.0.67-community-nt MySQL Community Edition (GPL)

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

mysql> show databases
    -> ;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| book               |
| mysql              |
| orilore            |
| student            |
| test               |
+--------------------+
6 rows in set (0.00 sec)

mysql> select * from employee;
ERROR 1046 (3D000): No database selected
mysql> use orilore;
Database changed
mysql> select * from employee;
+-----+-----------+-------+---------+
| Id  | name      | grade | salary  |
+-----+-----------+-------+---------+
| 100 | wang      |     2 | 4000.00 |
| 101 | sdfds     |     1 | 3220.00 |
| 102 | ieuriouer |     2 | 5454.00 |
| 103 | sddf      |     1 | 4000.00 |
| 104 | wefer     |     2 | 4000.00 |
| 105 | rewq      |     2 | 4000.00 |
+-----+-----------+-------+---------+
6 rows in set (0.00 sec)

mysql> delete from employee where id=105;
Query OK, 1 row affected (0.42 sec)

mysql> select * from employee;
+-----+-----------+-------+---------+
| Id  | name      | grade | salary  |
+-----+-----------+-------+---------+
| 100 | wang      |     2 | 4000.00 |
| 101 | sdfds     |     1 | 3220.00 |
| 102 | ieuriouer |     2 | 5454.00 |
| 103 | sddf      |     1 | 4000.00 |
| 104 | wefer     |     2 | 4000.00 |
+-----+-----------+-------+---------+
5 rows in set (0.00 sec)

mysql> create database mydb charset=gb2312;
Query OK, 1 row affected (0.42 sec)

mysql> use mydb;
Database changed
mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| book               |
| mydb               |
| mysql              |
| orilore            |
| student            |
| test               |
+--------------------+
7 rows in set (0.00 sec)

mysql> show tables;
Empty set (0.00 sec)

mysql> create table student(
    -> id int primary key auto_increment,
    -> name varchar(20) not null,
    -> age int
    -> );
Query OK, 0 rows affected (0.48 sec)

mysql> show tables;
+----------------+
| Tables_in_mydb |
+----------------+
| student        |
+----------------+
1 row in set (0.00 sec)

mysql> insert into student values(100,'wang',20);
Query OK, 1 row affected (0.41 sec)

mysql> select * from studen;
ERROR 1146 (42S02): Table 'mydb.studen' doesn't exist
mysql> select * from student;
+-----+------+------+
| id  | name | age  |
+-----+------+------+
| 100 | wang |   20 |
+-----+------+------+
1 row in set (0.00 sec)

mysql> show tables;
+----------------+
| Tables_in_mydb |
+----------------+
| student        |
+----------------+
1 row in set (0.00 sec)

mysql> desc student;
+-------+-------------+------+-----+---------+----------------+
| Field | Type        | Null | Key | Default | Extra          |
+-------+-------------+------+-----+---------+----------------+
| id    | int(11)     | NO   | PRI | NULL    | auto_increment |
| name  | varchar(20) | NO   |     | NULL    |                |
| age   | int(11)     | YES  |     | NULL    |                |
+-------+-------------+------+-----+---------+----------------+
3 rows in set (0.00 sec)

mysql> descibe student;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that
corresponds to your MySQL server version for the right syntax to use near 'desci
be student' at line 1
mysql> describe student;
+-------+-------------+------+-----+---------+----------------+
| Field | Type        | Null | Key | Default | Extra          |
+-------+-------------+------+-----+---------+----------------+
| id    | int(11)     | NO   | PRI | NULL    | auto_increment |
| name  | varchar(20) | NO   |     | NULL    |                |
| age   | int(11)     | YES  |     | NULL    |                |
+-------+-------------+------+-----+---------+----------------+
3 rows in set (0.00 sec)

mysql> Bye

D:\Program Files\MySQL\MySQL Server 5.0\bin>mysqldump -uroot -p mydb>d:\mydb.dum
p
Enter password: ****

D:\Program Files\MySQL\MySQL Server 5.0\bin>mysql -uroot -p
Enter password: ****
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 12
Server version: 5.0.67-community-nt MySQL Community Edition (GPL)

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

mysql> drop database mydb;
Query OK, 1 row affected (0.05 sec)

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| book               |
| mysql              |
| orilore            |
| student            |
| test               |
+--------------------+
6 rows in set (0.00 sec)

mysql> create database mydb2 charset=gb2312;
Query OK, 1 row affected (0.45 sec)

mysql> exit
Bye

D:\Program Files\MySQL\MySQL Server 5.0\bin>mysql -uroot -p mydb2<d:\mydb.dump  //注意路径
Enter password: ****

D:\Program Files\MySQL\MySQL Server 5.0\bin>mysql -uroot -p      //注意路径
Enter password: ****
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 14
Server version: 5.0.67-community-nt MySQL Community Edition (GPL)

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

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| book               |
| mydb2              |
| mysql              |
| orilore            |
| student            |
| test               |
+--------------------+
7 rows in set (0.00 sec)

mysql> use mydb2;
Database changed
mysql> show tables;
+-----------------+
| Tables_in_mydb2 |
+-----------------+
| student         |
+-----------------+
1 row in set (0.00 sec)

mysql> select * from student;
+-----+------+------+
| id  | name | age  |
+-----+------+------+
| 100 | wang |   20 |
+-----+------+------+
1 row in set (0.00 sec)

mysql>

 

### PyCharm 打开文件显示全的解决方案 当遇到PyCharm打开文件显示全的情况时,可以尝试以下几种方法来解决问题。 #### 方法一:清理缓存并重启IDE 有时IDE内部缓存可能导致文件加载异常。通过清除缓存再启动程序能够有效改善此状况。具体操作路径为`File -> Invalidate Caches / Restart...`,之后按照提示完成相应动作即可[^1]。 #### 方法二:调整编辑器字体设置 如果是因为字体原因造成的内容显示问题,则可以通过修改编辑区内的文字样式来进行修复。进入`Settings/Preferences | Editor | Font`选项卡内更改合适的字号大小以及启用抗锯齿功能等参数配置[^2]。 #### 方法三:检查项目结构配置 对于某些特定场景下的源码视图缺失现象,可能是由于当前工作空间未能正确识别全部模块所引起。此时应该核查Project Structure的Content Roots设定项是否涵盖了整个工程根目录;必要时可手动添加遗漏部分,并保存变更生效[^3]。 ```python # 示例代码用于展示如何获取当前项目的根路径,在实际应用中可根据需求调用该函数辅助排查问题 import os def get_project_root(): current_file = os.path.abspath(__file__) project_dir = os.path.dirname(current_file) while not os.path.exists(os.path.join(project_dir, '.idea')): parent_dir = os.path.dirname(project_dir) if parent_dir == project_dir: break project_dir = parent_dir return project_dir print(f"Current Project Root Directory is {get_project_root()}") ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值