数据库基础

  • 进入MySQL的方法:在MySQL的bin目录下cmd,mysql.exe -h 主机名(IP) -u 用户名 -p回车输入密码
  • 显示数据库:show databases;
  • 增加数据库:create database 数据库名;
  • 删除数据库:drop database 数据库;
  • 打开数据库:use 数据库名;
  • 显示当前打开的数据库名:select database();
  • 查看指定数据库中的所有表:show tables;
  • 查看特定表的详细设计信息:describe 表名;
  • 这数据库中创建一个表:create table 表名;
  • 查看表的结构:desc 表名;

增删查改

  • 添加:insert into 表名 values (,,,,顺序排列的数据);(如果数据是字符型,必须使用单引号或者双引号)【insert into users(id,username.password) values(3,'admin3','admin3');】
  • 查询:selec * from 表名 where 条件;【条件如:username='admin'】
  • 删除:delete from 表名 where 条件;
  • 修改:update 表名 set 修改内容 where 条件;【如:update users set id=2 where id=3;】

常用函数

  • select database();当前使用的数据库
  • select user();当前数据库用户
  • select version(); 数据库版本
  • select load_file("文件的绝对路径");写入文件到数据库【用反斜杠"/"】
  • show global variables like "%secure% ";查看secure_file_priv变量指向的允许上传文件的位置【默认的为NULL。即不允许导入导出。修改mysql.ini 文件,在[mysqld] 下加入“secure_file_priv =”保存,重启mysql。5.5版本前不需要】
  • select ("十六进制字符串") into dumpfile "目标路径/01.txt";在目标路径下创建01.txt【只能写一行】
  • select …… into outfile "目标路径"; 同上【可写多行】

end.

results matching ""

    No results matching ""