mysql 操作sql语句 操作数据表
#2. 操作文件
先切换到文件夹下:use db1 查看当前所在的数据库
mysql> select database();
+------------+
| database() |
+------------+
| db1 |
+------------+
1 row in set (0.00 sec)
每创建一个表每个字段都有相应类型
int 整数类型
char 字符类型
增:create table t1(id int,name char); 创建的数据库都在 在 /var/lib/mysql目录下
[root@mysql mysql]# cat /etc/my.cnf
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
user=mysql
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
default-character-set=utf8 [client]
default-character-set=utf8 [mysql]
default-character-set=utf8 [mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid [root@mysql mysql]# cd /var/lib/mysql
[root@mysql mysql]# ll
总用量 20492
drwx------. 2 mysql mysql 4096 10月 6 03:55 db1
-rw-rw----. 1 mysql mysql 10485760 10月 6 03:49 ibdata1
-rw-rw----. 1 mysql mysql 5242880 10月 6 03:49 ib_logfile0
-rw-rw----. 1 mysql mysql 5242880 10月 6 02:16 ib_logfile1
drwx------. 2 mysql mysql 4096 10月 6 02:16 mysql
srwxrwxrwx. 1 mysql mysql 0 10月 6 03:47 mysql.sock
drwx------. 2 mysql mysql 4096 10月 6 02:15 test
db1 数据库下面有 新创建的 t1 数据表
[root@mysql mysql]# cd db1/ [root@mysql db1]# ll
总用量 20
-rw-rw----. 1 mysql mysql 61 10月 6 03:50 db.opt
-rw-rw----. 1 mysql mysql 8586 10月 6 03:55 t1.frm
-rw-rw----. 1 mysql mysql 0 10月 6 03:55 t1.MYD
-rw-rw----. 1 mysql mysql 1024 10月 6 03:55 t1.MYI
查看当前数据库所有表
查:show tables 查表结构 根据数据表名字
show create table t1;
mysql> show create table t1;
+-------+---------------------------------------------------------------------------------------------------------------------+
| Table | Create Table |
+-------+---------------------------------------------------------------------------------------------------------------------+
| t1 | CREATE TABLE `t1` (
`id` int(11) DEFAULT NULL,
`name` char(1) DEFAULT NULL
) ENGINE=MyISAM DEFAULT CHARSET=utf8 |
+-------+---------------------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)
modify 修改意思 只能改字段类型 字段名不能改
改哪个字段
alter table 表名 modify 要改的字段 数据类型 和长度
改:alter table t1 modify name char(3);
mysql> alter table t1 modify name char(3);
Query OK, 0 rows affected (0.05 sec)
Records: 0 Duplicates: 0 Warnings: 0 mysql> show create table t1;
+-------+---------------------------------------------------------------------------------------------------------------------+
| Table | Create Table |
+-------+---------------------------------------------------------------------------------------------------------------------+
| t1 | CREATE TABLE `t1` (
`id` int(11) DEFAULT NULL,
`name` char(3) DEFAULT NULL
) ENGINE=MyISAM DEFAULT CHARSET=utf8 |
+-------+---------------------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)
另外一种方式查表 查看表结构
desc 表名;
desc t1;
mysql> desc t1;
+-------+---------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+---------+------+-----+---------+-------+
| id | int(11) | YES | | NULL | |
| name | char(3) | YES | | NULL | |
+-------+---------+------+-----+---------+-------+
2 rows in set (0.00 sec)
change 可以改字段名 alter table 表名 change 要改的字段 改后的字段 数据类型 和长度
alter table t1 change name name1 char(2);
删:drop table t1;
mysql> alter table t1 change name NAME char(2);
Query OK, 0 rows affected (0.02 sec)
Records: 0 Duplicates: 0 Warnings: 0 mysql>
mysql> desc t1;
+-------+---------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+---------+------+-----+---------+-------+
| id | int(11) | YES | | NULL | |
| NAME | char(2) | YES | | NULL | |
+-------+---------+------+-----+---------+-------+
2 rows in set (0.00 sec) mysql> show create table t1;
+-------+---------------------------------------------------------------------------------------------------------------------+
| Table | Create Table |
+-------+---------------------------------------------------------------------------------------------------------------------+
| t1 | CREATE TABLE `t1` (
`id` int(11) DEFAULT NULL,
`NAME` char(2) DEFAULT NULL
) ENGINE=MyISAM DEFAULT CHARSET=utf8 |
+-------+---------------------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)
删:drop table t1;
mysql 操作sql语句 操作数据表的更多相关文章
- mysql 操作sql语句 操作数据表中的内容/记录
#3. 操作文件中的内容/记录 往哪张表去插入 insert into 表名指定字段(id,name) 插入要加values(针对前面字段插入)(2,mike); insert into t1(id, ...
- mysql 操作sql语句 目录
mysql 操作sql语句 操作数据库 mysql 操作sql语句 操作数据表 mysql 操作sql语句 操作数据表中的内容/记录
- mysql操作SQL语句
二.数据库操作SQL语句1.显示服务器上当前存在什么数据库SHOW DATABASES; 2.创建名称为rewin的数据库CREATE DATABASE rewin; 3.删除名称为rewin的数据库 ...
- MySQL常用sql语句-----数据表的查询操作
常用的sql语句如下,应对工作足以 1.查询指定字段 select c_id,c_age,c_name from t_student; select c_id as 编号,c_name as 姓名,c ...
- mysql 操作sql语句 操作数据库
sql语句 #1. 操作文件夹 创建数据库:create database db1 charset utf8; 查数据库:show databases; mysql> create databa ...
- MySQL常用sql语句-----数据表的增删改操作
常用sql操作如下: 1.查看当前数据库的所有表 show tables; 2.创建表 create table stu(sid int,sname char(20),sage int default ...
- mysql用sql语句创建表和数据 设置字符编码为utf-8
简而言之 CREATE DATABASE xx CHARACTER SET utf8 COLLATE utf8_general_ci; USE xx; ),qname ) ) ) ) )); ) ,t ...
- MySQL数据库-表操作-SQL语句(一)
1. 数据库操作与存储引擎 1.1 数据库和数据库对象 数据库对象:存储,管理和使用数据的不同结构形式,如:表.视图.存储过程.函数.触发器.事件等. 数据库:存储数据库对象的容器. 数据库分两种 ...
- Mysql常用sql语句(二)- 操作数据表
21篇测试必备的Mysql常用sql语句,每天敲一篇,每次敲三遍,每月一循环,全都可记住!! https://www.cnblogs.com/poloyy/category/1683347.html ...
随机推荐
- Kafka一些常见资源汇总
终于下定决心写一点普及类的东西.很多同学对Kafka的使用很感兴趣.如果你想参与到Kafka的项目开发中,很多资源是你必须要提前准备好的.本文罗列了一些常用的Kafka资源,希望对这些develope ...
- mysql错误:got error 28 from storage engine
今天碰到数据库出错 Got error 28 from storage engine 查了一下,数据库文件所在的盘应该没事,应该是数据库用的临时目录空间不够 引用 磁盘临时空间不够导致.解决办法:清空 ...
- codeforces水题100道 第十四题 Codeforces Round #321 (Div. 2) A. Kefa and First Steps (brute force)
题目链接:http://www.codeforces.com/problemset/problem/580/A题意:求最长连续非降子序列的长度.C++代码: #include <iostream ...
- cp自动创建层级结构的例子
一个拷贝命令的技巧,不仅拷贝文件,而且拷贝目录结构.记录下来. *拷贝的时候,自动创建参数中源文件的路径:#cp --parents parentdir1/parentdir2/sourcefile ...
- cygwin设置NDK环境变量ANDROID_NDK_ROOT
cygwin安装目录下的“home/当前用户名”的.bash_profile下以UltraEdit(Unix方式)或者eclipse打开,最后添加一句: ANDROID_NDK_ROOT=/cygdr ...
- JDBC批量执行executeBatch
JDBC事务 在数据库中,所谓事务是指一组逻辑操作单元,使数据从一种状态变换到另一种状态.为确保数据库中数据的一致性,数据的操纵应当是离散的成组的逻辑单元:当它全部完成时,数据的一致性可以保持,而当这 ...
- SqlServer中循环查询结果集
); begin ; open c_test_main;--打开游标 --开始循环 begin fetch next from c_test_main into @id,@value; --赋值到变量 ...
- springboot---->springboot中的校验器(一)
这里面我们简单的学习一下springboot中关于数据格式化的使用.冬天花败,春暖花开,有人离去,有人归来. springboot中的校验器 我们的测试环境是springboot,对请求的person ...
- DXP 内电层分割
多层电路板中间层设置与内电层如何分割 多层电路板与一般的电路板不同之处在于,多层电路板除了顶层和底层之外,还有若干中间层,这些中间层可以是信号层(mid layer),也可以是内部电源/接地层(int ...
- Android 应用内切换语言
extends :http://bbs.51cto.com/thread-1075165-1.html,http://www.cnblogs.com/loulijun/p/3164746.html 1 ...