mysql基本命令

來源:互聯網
上載者:User

標籤: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基本命令

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.