終端命令行
登錄MYSQL -- >mysql -uroot -p -->密碼
quit、exit 退出數(shù)據(jù)庫(kù)
CLS的清除屏幕命令行
mysql -hlocalhost -uroot - p123456 訪問(wèn)本機(jī)mysql服務(wù)器,登錄名和密碼
create database liubo;創(chuàng)建數(shù)據(jù)庫(kù)
drop database liubo;刪除數(shù)據(jù)庫(kù)
use liubo;選中數(shù)據(jù)庫(kù)
show databases;查詢(xún)數(shù)據(jù)庫(kù)
show tables;查看數(shù)據(jù)庫(kù)里面的表格
create table liubo(id int,name char(30),age int) 30是給name分配的最大空間(分配的多少個(gè)字節(jié)颊亮,最大是255個(gè)字節(jié)) default charset=utf8,engine=innodb
show create table liubo;查看創(chuàng)建的表
desc liubo;查看表里有哪些字段以及字段類(lèi)型
alter table liubo modify name char(50)修改字段
alter table liubo add weight int;增加字段
alter table liubo drop weight;刪除字段
alter table liubo change name waihao char(30);修改字段名字
alter table liubo add weight int first;排在第一位
alter table liubo add weight int after age;weight排在age 后面
alter table liubo rename lb;修改表名字
create table liubo(id int,name varchar(30),age int,nowtime timestamp default current_timestamp),default charset=utf8,engine=innodb;創(chuàng)建表格,并顯示時(shí)間
insert into liubo(id,name,age) values(2,'liubo',19);插入數(shù)據(jù)
select *from liubo;查詢(xún)字段對(duì)應(yīng)的數(shù)據(jù)
enum (‘男’洛二,‘女’)單選
insert into liubo(sex) values(1) 或者values(男)插入單條數(shù)據(jù)
set('美女'蜀踏,‘帥哥’摩渺,‘啦啦’)
insert into liubo(love) values(1|2|4|8) 或者 values(15);插入多條數(shù)據(jù)
\c清除本條指令
導(dǎo)出數(shù)據(jù)庫(kù)
1.首先要退出mysql數(shù)據(jù)庫(kù)
mysqldump -uroot -p liubo>c:/liubo.sql后面不需要加分號(hào)
2.導(dǎo)入數(shù)據(jù)庫(kù):退出數(shù)據(jù)庫(kù),首先創(chuàng)建一個(gè)空的數(shù)據(jù)庫(kù)膘壶。創(chuàng)建一個(gè)空的數(shù)據(jù)庫(kù)后退出quit在導(dǎo)入文件.
mysql -uroot -p bb<c:/liubo.sql后面不需要加分號(hào)
UNSIGNED
無(wú)符號(hào)類(lèi)型 只能修飾正數(shù)错蝴,整型或者是浮點(diǎn)型。就是把前面的負(fù)號(hào)去掉颓芭。
zerofill(0填充)
alter table liubo add height int(5) zerofill;前面不夠5位時(shí)候0填充顷锰。
insert into bb(height) values(123); --->會(huì)顯示00123
自動(dòng)增長(zhǎng)auto_increment
create table liubo(id int auto_increment primary key,name varchar(30));
insert into liubo(name) values('xiaoming') -->id=1,name = xiaoming
default默認(rèn)值
alter table liubo add age int default 100;
insert into liubo(name) values('sdffs'); 其他默認(rèn)都是age = 100
not null 不能為空
alter table liubo add shouji int not null;
insert into liubo(name,shouji) values('xiaoming',11);必須得插入手機(jī),因?yàn)閟houji不能為空
show engines;查看搜索引擎
show create table liubo;查看創(chuàng)建表的語(yǔ)句亡问;
///在mysql數(shù)據(jù)庫(kù)里面設(shè)置字符集
設(shè)置默認(rèn)的數(shù)據(jù)庫(kù)字符集
character_set_server=utf8
引擎
default-storage-engine=INNODB;
create table liubo(id int auto_increment primary key,name varchar(30),age int) engine=innodb,default charset=utf8;主鍵官紫、自動(dòng)增長(zhǎng)
wampServer中修改mysql默認(rèn)空密碼(root密碼)
root password 修改路徑:
C:\wamp\apps\phpmyadmin3.4.10.1\config.inc.php
重新啟動(dòng)mysql,不行的話重新啟動(dòng)電腦就可以了玛界。