
MySQL学习之《操作数据库》
发布日期:2021-05-15 01:24:03
浏览次数:12
分类:精选文章
本文共 2636 字,大约阅读时间需要 8 分钟。
MySQL Operations Guide
1. Database Operations
MySQL operations can be broken down into three main categories: database management, table operations, and data manipulation.
1.1 Understanding Databases
Databases are collections of tables, and tables are collections of columns. Here are some fundamental operations:
Create a Database
create database IF NOT EXISTS westos;
Delete a Database
drop database IF EXISTS westos;
Use a Database
use `westos`; -- Note: Use backticks for special characters
List All Databases
show databases;
1.2 Database Data Types
Data Type | Description | Example Usage |
---|---|---|
int | Integer type with default size of 4 bytes | id INT AUTO_INCREMENT |
varchar | Variable-length string (1-65535 characters) | name VARCHAR(100) |
text | Long variable-length string (2^16 – 1024 bytes) | description TEXT |
datetime | Date and time combined (YYYY-MM-DD HH:mm:ss) | birth_date DATETIME |
timestamp | Exact timestamp with precision to the millisecond | timestamp TIMESTAMP |
1.3 Database Field Properties
Unsigned
- Disallows negative values.
- Useful for storing numbers that cannot be negative.
Zero Fill
- Pads the values with zeros if they don't fill the entire width.
Auto Increment
- Automatically assigns the next value in a sequence.
- Best for primary keys.
Non-Null
- Ensures that the database won't accept NULL values for this column.
2. Creating a Table
CREATE TABLE IF NOT EXISTS student ( id INT NOT NULL AUTO_INCREMENT COMMENT 'Student ID', name VARCHAR(100) NOT NULL DEFAULT '匿名'COMMENT 'Student Name', pwd VARCHAR(50) NOT NULL DEFAULT '123456' COMMENT 'Password', sex VARCHAR(10) NOT NULL DEFAULT '男' COMMENT 'Sex', birth_date DATETIME DEFAULT NULL COMMENT 'Birthday', address VARCHAR(255) DEFAULT NULL COMMENT 'Address', email VARCHAR(100) DEFAULT NULL COMMENT 'Email', PRIMARY KEY (id)) ENGINE=InnoDB DEFAULT CHARSET=utf8;
Table Attributes
- InnoDB:TECHNIQUEكزمان Font Awesome Free
3. Modifying and Deleting Tables
Rename a Table
ALTER TABLE teacher RENAME AS teacher1;
Add a Column
ALTER TABLE teacher1 ADD COLUMN age INT(5);
Modify a Column
ALTER TABLE teacher1 CHANGE age idade INT(3);
Delete a Column
ALTER TABLE teacher1 DROP idade;
Delete a Table
DROP TABLE IF EXISTS teacher1;
4. Table Types
Attribute | MYISAM | InnoDB |
---|---|---|
Transactional | ❌ | ✔ |
Locking | ❌ | ✔ |
Foreign Key | ❌ | ✔ |
Indexes | ✔ | ❌ |
5. Character Set
- Default:
utf8
- Configure in
my.ini
:character-set-server=utf8
6. Database Location
- All databases stored in the
data
directory. - Each database corresponds to a single file.
This guide covers essential MySQL operations for database management. Stay curious and keep exploring! If you have any questions, feel free to discuss them below!
发表评论
最新留言
关注你微信了!
[***.104.42.241]2025年05月02日 18时52分39秒
关于作者

喝酒易醉,品茶养心,人生如梦,品茶悟道,何以解忧?唯有杜康!
-- 愿君每日到此一游!
推荐文章
计算机网络之第三章笔记--数据链路层
2019-03-09
创建型模式之简单工厂模式实例及代码操作
2019-03-09
广东外语外贸大学第三届网络安全大赛Writeup
2019-03-09
VS2019 报错: LINK Error 无法找到 MSCOREE.lib的解决办法
2019-03-09
2021-04-23
2019-03-09
hadoop 分布式文件系统的计算和高可用
2019-03-09
【Linux】VMware Workstation 不可恢复错误: (vcpu-0)
2019-03-09
VS中 fatal error LNK1123: 转换到 COFF 期间失败 的解决方法
2019-03-09
ant design pro v5去掉右边content区域的水印
2019-03-09
JavaScript——使用iterator遍历迭代map,set集合元素
2019-03-09
IAR调试卡顿的解决办法
2019-03-10
Course Schedule II
2019-03-10
Django ORM操作
2019-03-10
京喜小程序体验评分优化实践
2019-03-10
C#中文转换成拼音
2019-03-10
C++错误笔记
2019-03-10
【无线通信模块】GPRS DTU不稳定和容易掉线原因
2019-03-10
SpringBoot使用RedisTemplate简单操作Redis的五种数据类型
2019-03-10
国标流媒体服务器以ROOT身份运行提示“permission denide”报错解决
2019-03-10