Mysql数据库基础
MySQL 数据库
基本命令
在命令行登录:
1 | mysql -u root -p |
基本操作
1 | show databases; #查看数据库 |
创建数据表
首先 use test1;
调整到要加的数据库里,然后
1 | create table users( |
于是就建立了一个users的数据表,可以 desc users;
来查看刚才建立的表。

修改数据表
alter修改名字
把user
表中的name
字段重命名为username
.
注意后面要跟上对应变量的类型varchar(50)
.
1 | alter table users change name username varchar(50); |
update修改
把id
为3
的改成1
1 | update users set id=1 where id=3; |
insert添加数据
添加到users
表中一条数据,括号里的数据要一一对应
1 | insert into users values (1, "zhangsan"); |
delete删除数据
在表users
中删除username
是"zhangsan"
的数据
1 | delete from users where username="zhangsan"; |
查询表
查询 users
表的所有信息
1 | select * form users; |
基本数据类型
数值类型

时间和日期

字符串

函数
database()
返回当前数据库
1 | select database(); |

user()
返回正在使用的用户
1 | select user(); |

version()
返回数据库当前版本
1 | select version(); |
读写文件
LOAD_FILE()
读取文件
首先在my.ini
里的mysqld
下面加上这个配置secure_file_priv="/"
否则读取文件会出现NULL情况

之后重启一下mysql数据库
1 | select load_file("C:/Users/fyind/Desktop/123.txt"); |
然后就可以读取文件内容了

dumpfile
写入文件
1 | select "hello world" into dumpfile "C:/Users/fyind/Desktop/hello.txt"; |

All articles in this blog are licensed under CC BY-NC-SA 4.0 unless stating additionally.