1.每条语句输入完毕末尾加上 ; 或 \g 2.显示所有数据库: mysql> show databases; 3.创建数据库: mysql> create database mysqldata; 4.删除数据库: mysql> drop database mysqldata; 5.选中数据库: mysql> use databaseName; (按回车键出现Database changed 时说明操作成功!) 6.查看选中的数据库的表: mysql> show tables; 7.创建表是先判断表是否存在: mysql> create table if not exists students(……); 8.创建数据库表: mysql> create table mytable (id int,name varchar(20)); 9.增加一个字段: mysql> alter table tabelName add column fieldName dateType; 10.增加多个字段: mysql> alter table tabelName add column fieldName1 dateType,add columns fieldName2 dateType; 11.显示表的结构: mysql> describe mytable; 12.显示表格列的属性: mysql> show columns from tableName; 13.复制表: mysql> create table table2 select * from table1; 14.从已经有的表中复制表的结构: mysql> create table table2 select * from table1 where 1<>1; 15.对表重新命名: mysql> alter table table1 rename as table2; 16.修改列的类型: mysql> alter table table1 modify id int unsigned; // 修改列id的类型为int unsigned mysql> alter table table1 change id sid int unsigned; // 修改列id的名字为sid,而且把属性修改为int unsigned 17.往表中插入数据: mysql> insert into mytable values ("1","name"); mysql> insert into mytable(id,name) values (1,"tom"),(2,"mao"); // 同时插入多条数据 18.用文本方式将数据插入到数据库表中:(文本里的数据字段值用键盘 Tab 隔开) mysql> load data local infile“D:/mysql.txt” into table mytable; 19.导入.sql文件命令: mysql> source d:/mysql.sql; 20.删除表: mysql> drop table mytable; 21.清空表: mysql> delete from mytable; 22.更新表中数据: mysql> update mytable set name="tom" where id=1; 23.查询时间: mysql> select now(); 24.查询当前用户: mysql> select user(); 25.查询数据库版本: mysql> select version(); 26.查询当前使用的数据库: mysql> select database(); 27.分页查询语句数据库查询: mysql> select * from mytable limit 0,5; // 下标从0开始,从第1条记录开始检索5条记录(适合有几千上万数据查询) mysql> select * from mytable where id>=(select id from mytable limit 4900000,1) limit 10;// 适合有百万级数据查询 28.命令行修改root密码: mysql> update mysql.user set password='新密码' where user='root'; mysql> flush privileges;
MySQL语法命令(整合篇)
最新推荐文章于 2022-07-23 23:57:27 发布