1. 程式人生 > 其它 ><2>mysql:常用命令

<2>mysql:常用命令

連線mysql伺服器

1.mysql -u 使用者名稱 -p : 連線本地mysql伺服器

2.mysql -h ip地址 -u 使用者名稱 -p : 連線目的ip的mysql伺服器

3.mysqld --skip-grant-tables; : 跳過輸入密碼直接連線

資料庫

1.show databases; :檢視所有資料庫

2.create database 資料庫名; : 建立資料庫

3.create database 資料庫名 default charset = 'utf8'; :建立資料庫,資料庫字符集是utf8(適用於table)

4.drop database 資料庫名; : 刪除資料庫

5.use 資料庫名; :開啟資料庫

6.show create database 資料庫名; : 檢視資料庫字符集(適用於table)

1.show tables;:檢視當前資料庫中所有的表

2.create table 表名(列名1 資料型別,列名2 資料型別,...); :建立表

3.create table 表名 as 表; :複製表

常用資料型別

  int 整型

  float 浮點型

  numeric(n,s) decimal(n,s) 浮點型,n表示總長度,s表示小數長度

  char(n) 定長字元型,n表示長度

  varchar(n) 可變長字元型

4.truncate table 表名; :刪除表內所有的資料

5.drop table 表名; :刪除表

6.describe 表名(也可簡寫成desc 表名):查看錶結構

基礎增刪改查

1.insert into 表名(列名1,列名2,...不寫表示全部)value(列1值,列2值,...) ;

2.delete 表名 where 條件

3.update 表名 set 列名1=值,列名2 = 值,...where 條件;

4.select 列名1,列名2,..*表示全部 from 表名 where 條件;