標籤:mysql
鍵盤esc清除命令 \c取消命令
登入mysql -uCountName -p 斷行符號 cmd命令無效在作業系統環境變數註冊MySql
顯示所有資料庫show databases
顯示表use dbName;show tables;
顯示表結構desc tName;
註冊mysql帳號grant all on dbName.* to "CountName"@"localhost" identified by "pwd";
建立資料庫create database dbName;
刪除資料庫drop database dbName;
備份資料庫 mysqldump -uroot -p dbName>d:/123.sql;
匯入mysql -uroot -p dbName>d:/123.sql;
use dbName; source d:/123.sql;
mysql狀態資訊 status;
create table student
( Id int unsigned primary key Auto_increment, 主鍵自增
No int(3) zerofill 插入3 輸人003
sex,tinyint default 0)
select if(sex,"男生","女生") from student
select concat("姓名":sName,"性別",sex) from student
select * from studnet limit 2 取前兩條
select sname from student order by birthday litmi 1,1; 尋找年齡第二大的學生
alter table student modify name character set utf8;
show character set;字元集
show collation;字元集校正規則
show create table student
mysql中變數不用事前申明,在用的時候直接用“@變數名”使用就可以了。
第一種用法:set @num=1; 或set @num:=1; //這裡要使用變數來儲存資料,直接使用@num變數
第二種用法:select @num:=1; 或 select @num:=欄位名 from 表名 where ……
注意上面兩種賦值符號,使用set時可以用“=”或“:=”,但是使用select時必須用“:=賦值”
要設定一個全域變數,有如下兩種方式:
set global var_name = value; //注意:此處的global不能省略。根據手冊,set命令設定變數時若不指定GLOBAL、SESSION或者LOCAL,預設使用SESSION
set @@global.var_name = value; //同上
要想查看一個全域變數,有如下兩種方式:
select @@global.var_name;ame = value; //同上
mysql基本命令