博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
PHP 数据库命令行的使用
阅读量:7035 次
发布时间:2019-06-28

本文共 1641 字,大约阅读时间需要 5 分钟。

hot3.png

在命令行在操作数据库:(注意   加了 ; 是SQL语句结束标识 )

(1)连接数据库:  mysql -h localhost(主机地址) -u root(用户名) -p 回车  在输入数据库密码

(2)修改密码:mysqladmin -u root(用户名) -p 123456(旧密码) password 12345(新密码);

(3)显示数据库列表: show databases;

(4)显示某个数据库中的数据表: use test(数据库名称);    show tables;

(5)显示数据表的结构: describe  user(表名);

(6)创建数据库: create database thinkphp(数据库名);

(7)删除数据库: drop database thinkphp(数据库名);

(8)创建表:use thinkphp(数据库名);     create table user(表名)

                                                                 ( id int(3) auto_increment(自动增长) not null primary key(设置为主键),

                                                                      name  varchar(10) not null,

                                                                      age int(3) not null  )  engine = myisam  partition by  key(id) partition 5 ;

                                                                       注意分区:key hash 是去余操作   list  rang  是条件分区  list条件是可列举的                                                                           rang条件是可以范围的。

(9) 删除表:drop table user(表名);

(10) 向表中插入数据: insert into user(表名) values ( 1 , `php`, 1);

(11) 删除表中的数据: delete from user(表名) where age =3;

(12) 显示表中的数据:  select * from user(表名);

(13) 清空表中的数据: delete from user(表名) ;

(14) 更新表中的数据: update user(表名) set name = 'linux'  where id =2;

(15) 查询表中结果排序: select  * from  user  order by id desc(倒序排列  ase顺序排列);

(16)查询表中某个数据的总数: select count(id) from user where name = 'linux';//id、name 字段名

(17)查询表中的最大值: select max(id) from user;   //sum 求和  avg 平均数  min 最小数  max 最大数

(18)组合查询: select goods.id goods.name user.age  from goods, user where goods.id = user.id;

(19)建立索引: create  index user_index(索引表名字任意取) on user(id); 

(20)连接查询: select goods.id goods.name user.age from goods inner join user on goods.id = user.id order by                                 goods.name;   //inner join 是查找两个人相等的数据   left join  查找左表中所有的数据右表中相等的数据

                                                      right join 查找右表中的所有数据左表中想等的数据

(21)向表中添加字段: alter table user(表名) add  sex bool(要添加的字段名和类型);  

(22)向数据库中导入sql文件:先定位到数据库中在使用 source d:thinkphp.sql

(23) 退出数据库: exit;

 

转载于:https://my.oschina.net/u/2546235/blog/666934

你可能感兴趣的文章
Maven学习总结(四)——Maven核心概念
查看>>
安装xtables-addons时报错
查看>>
.NET开发规范教程
查看>>
网络公开课《最后的升级-Oracle RAC数据库升级》
查看>>
配置FTP服务
查看>>
我的友情链接
查看>>
人类认识的层次模型
查看>>
WDS使用捕获映像制作企业自定义映像
查看>>
C++数组、指针与vector、iterator
查看>>
SSL及其开源实现OpenSSL+创建私有CA
查看>>
jquery实现表单form异步提交
查看>>
Citrix xendesktop中未注册(Not registered)的检查流程
查看>>
一张图让你看懂JAVA线程间的状态转换
查看>>
Performance comparison Raw device VS Ext2 VS Ext3 VS OCFS
查看>>
ISBN号码(CCF考题)
查看>>
PendingIntent中Flags的参数设置
查看>>
企业级镜像仓库harbor搭建(http/https)及使用
查看>>
从MySQL到MongoDB简易对照表 (转)
查看>>
python爬取某个网页的图片-如百度贴吧
查看>>
使用httpwatch抓包
查看>>