mysql database manual(mysql数据库手册)
2024-07-24 12:44:11
供稿:网友
2.1登入到mysql控制台[用户名为root,密码缺省为空]
切换到mysql的bin目录cd d:/wamp/mysql/bin
登入到mysql控制台
语法:mysql -h hostname -u username -p
连接到另一台主机
代码:mysql -h 192.168.1.1 -u root -p
password:直接按回车
连接到本机
代码:mysql -h 127.0.0.1 -u root -p
password:直接按回车
出现mysql>表示登陆到mysql控制台成功
2.2退出mysql控制台
mysql>exit;
/***********************************************************/
3.1检查所有mysql数据库清单;
语法:mysql> show databases;
代码:mysql> show databases;
3.2显示数据库中所有表的清单
查看当前数据库中的表
语法1:mysql> show tables;
代码1:mysql> show tables;
3.3查看其它数据库jxc中的表
语法1:mysql> show tables from databasename;
代码1:mysql> show tables from jxc;
/***********************************************************/
4.创建/删除/选择数据库
创建jxc数据库:
语法:mysql> create database databasename;
代码:mysql> create database jxc;
删除jxc数据库:
语法:mysql> drop database databasename;
代码:mysql> create database abc;
代码:mysql> drop database abc;
选择jxc数据库:
语法:mysql> use database;
代码:mysql> use jxc;
/***********************************************************/
5查看一个表的数据结构
5.1 describte查看表customers结构
语法1:mysql> describe tablename;
代码1:mysql> describe customers;
5.2.show columns查看表customers;结构
语法1:mysql> show columns from tablename;
代码1:mysql> show columns from customers;
5.3.查看一个表的指定列名的数据结构
语法1:mysql> show index from tablename column;
代码1:mysql> show index from customers name;
5.4.查看一个表customers的索引
语法1:mysql> show index from tablename;
代码1:mysql> show index from customers;
6.数据常用操作(select,insert,update,delete)
6.1 select选择:
语法:select * from [表名1,表名1,,,] where [条件范围]
代码:select * from orders where orderid>100;
6.2 insert插入
语法:insert into table1(column1,column,,,) values(value1,value2,,,);
代码:insert into books(isbn,author,title,price) values('iso-902126','jahn.D','mysql6.0',99.0);
6.3 update 更新:
语法:update table1 set [列名]=[新数据] where [条件范围]
代码:update books set title="Thinking in Java" where isbn='iso-902126';
6.4删除:
语法:delete from [表名] where [条件范围]
代码:delete from books where isbn='iso-902126';
6.5其它方法
查找:select * from table1 where field1 like '%value1%' ---like的语法很精妙
排序:select * from table1 order by field1,field2 [desc]
总数:select count as totalcount from table1
求和:select sum(field1) as sumvalue from table1