2.1登入到mysql控制臺(tái)[用戶名為root,密碼缺省為空]
切換到mysql的bin目錄cd d:/wamp/mysql/bin
登入到mysql控制臺(tái)
語法:mysql -h hostname -u username -p
連接到另一臺(tái)主機(jī)
代碼:mysql -h 192.168.1.1 -u root -p
password:直接按回車
連接到本機(jī)
代碼:mysql -h 127.0.0.1 -u root -p
password:直接按回車
出現(xiàn)mysql>表示登陸到mysql控制臺(tái)成功
2.2退出mysql控制臺(tái)
mysql>exit;
/***********************************************************/
3.1檢查所有mysql數(shù)據(jù)庫清單;
語法:mysql> show databases;
代碼:mysql> show databases;
3.2顯示數(shù)據(jù)庫中所有表的清單
查看當(dāng)前數(shù)據(jù)庫中的表
語法1:mysql> show tables;
代碼1:mysql> show tables;
3.3查看其它數(shù)據(jù)庫jxc中的表
語法1:mysql> show tables from databasename;
代碼1:mysql> show tables from jxc;
/***********************************************************/
4.創(chuàng)建/刪除/選擇數(shù)據(jù)庫
創(chuàng)建jxc數(shù)據(jù)庫:
語法:mysql> create database databasename;
代碼:mysql> create database jxc;
刪除jxc數(shù)據(jù)庫:
語法:mysql> drop database databasename;
代碼:mysql> create database abc;
代碼:mysql> drop database abc;
選擇jxc數(shù)據(jù)庫:
語法:mysql> use database;
代碼:mysql> use jxc;
/***********************************************************/
5查看一個(gè)表的數(shù)據(jù)結(jié)構(gòu)
5.1 describte查看表customers結(jié)構(gòu)
語法1:mysql> describe tablename;
代碼1:mysql> describe customers;
5.2.show columns查看表customers;結(jié)構(gòu)
語法1:mysql> show columns from tablename;
代碼1:mysql> show columns from customers;
5.3.查看一個(gè)表的指定列名的數(shù)據(jù)結(jié)構(gòu)
語法1:mysql> show index from tablename column;
代碼1:mysql> show index from customers name;
5.4.查看一個(gè)表customers的索引
語法1:mysql> show index from tablename;
代碼1:mysql> show index from customers;
6.數(shù)據(jù)常用操作(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 [列名]=[新數(shù)據(jù)] 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]
總數(shù):select count as totalcount from table1
求和:select sum(field1) as sumvalue from table1