啟動服務(wù):
1通過控制面板里的服務(wù)選項
2通過命令行
net start mysql??? ->啟動數(shù)據(jù)庫
net stop mysql???? ->關(guān)閉數(shù)據(jù)庫
連接數(shù)據(jù)庫
mysql -u用戶名 -p密碼
查看服務(wù)器上當(dāng)前存在什么數(shù)據(jù)庫
show databases;
創(chuàng)建數(shù)據(jù)庫
create database 數(shù)據(jù)庫名;
如我要創(chuàng)建一個名為gbook的數(shù)據(jù)庫
create database gbook;
刪除數(shù)據(jù)庫
drop database 數(shù)據(jù)庫名;
如:
drop database gbook;
選擇要使用的數(shù)據(jù)庫
use 要使用的數(shù)據(jù)庫名;
如:
use gbook;
查看當(dāng)前使用的數(shù)據(jù)庫中存在的表
show tables;
創(chuàng)建一個數(shù)據(jù)庫表
create table person
{
??? id varchar(32) not null primary key,
??? name varchar(20) not null,
??? password varchar(20) not null
};
顯示數(shù)據(jù)庫中某個表的結(jié)構(gòu)
describe 表名;
導(dǎo)入數(shù)據(jù)庫創(chuàng)建腳本文件命令(如D:\mysql.sql)
先建立一個空數(shù)據(jù)庫->選擇它->導(dǎo)入腳本命令 如:
create database gbook;
source d:/mysql.sql;
刪除表
drop table 表名;
刪除數(shù)據(jù)庫中某表的全部記錄
delete from 表名;
如:
delete from gbook;
向表中插入數(shù)據(jù)(以前面的person表為例)
insert into 表名 values(對應(yīng)的數(shù)據(jù)值);
如:
insert into person values('LXH','李興華','moolee');
更新表中的數(shù)據(jù)
update person set password='zzzzz';
查看當(dāng)前數(shù)據(jù)庫服務(wù)器的版本
select version();
查看數(shù)據(jù)庫服務(wù)器上的所有用戶
select user();
查看當(dāng)前日期時間
select now();
使用load命令向數(shù)據(jù)庫的表中插入數(shù)據(jù)
load data local infile '路徑' into table 表名;
如:
load data local infile 'f:/person.txt' into table person;
person.txt中則單純的列出了許多表中的對應(yīng)數(shù)據(jù),如:
mldn???????? 陳華 1569
god????????? 黃雨 123456
admin??????? 陳天賜 admin888
列出表中所有記錄
select * from 表名;
如:
select * from person;
從表中只選擇特定的行
select * from person where id='lxh';
select * from person where id='lxh' and name='李興華';
選擇表中特定的列(可以是多列哦,記得以,分開)
select name from person;
用distinct檢索出每個唯一的輸出記錄
select distinct name from person;
計算總的記錄數(shù)
select count(*) from person;
count()函數(shù)是查詢數(shù)據(jù)庫中的指定表有多少列