mysql第一篇

來源:互聯網
上載者:User

標籤:support   刪除   ant   host   select   min   dex   oca   val   

charset modify charset  engine字元集  修改  字元集    引擎#1 操作檔案夾(庫)    代碼如下:    SHOW CREATE DATABASE db_name;增create database db1 charset utf8;查show databases;show create database db1;改alter database db1 charset gbk;刪drop database db1;#2 操作檔案(表)    查看錶編碼:    SHOW CREATE TABLE tbl_name;切換到檔案夾下:use db1增(相當於建立)create table t1(id int,name char(10))engine=innodb;create table t2(id int,name char(10))engine(引擎)=innodb default(預設) charset(字元集) utf8;指定這個表的id,name是什麼類型,指定引擎,以及字元集查show tables;show create table t1; 查看錶的基本資料desc t1;#查看錶結構改 (相當於添加)alter table t1 add age int;    添加AGE欄位為整形alter table t1 modify name char(12);刪drop table t1;#3 操作檔案的一行行內容(記錄)    查看欄位編碼:    代碼如下:    SHOW FULL COLUMNS FROM tbl_name增 插入資料insert into db1.t1 values(1,‘egon1‘),(2,‘egon2‘),(3,‘egon3‘);insert into db1.t1(name) values(‘egon1‘),(‘egon2‘),(‘egon3‘);查select * from t1;select name from t1;select name,id from t1;改(更新)update t1 set name=‘SB‘ where id=4;update t1 set name=‘SB‘ where name=‘alex‘;刪delete from t1 where id=4;#對於清空表記錄有兩種方式,但是推薦後者delete from t1;truncate t1; #當資料量比較大的情況下,使用這種方式,刪除速度快#自增idcreate table t5(id int primary(主鍵) key auto_increment,name char(10));create table t4(id int not null unique,name char(10));insert into t5(name) values(‘egon5‘),(‘egon6‘),(‘egon7‘),(‘egon8‘),(‘egon9‘),(‘egon10‘),(‘egon11‘),(‘egon12‘),(‘egon13‘);#拷貝表結構create table t7 select * from t5 where 1=2;alter table t7 modify id int primary key auto_increment;   有問題insert into t7(name) values(‘egon1‘),(‘egon2‘),(‘egon3‘),(‘egon4‘),(‘egon5‘),(‘egon6‘),(‘egon7‘),(‘egon8‘),(‘egon9‘),(‘egon10‘),(‘egon11‘),(‘egon12‘),(‘egon13‘);delete from t7 where  id=1; #刪記錄update t7 set name=‘‘; #修改欄位對應的值  (這是修改name這個欄位的所有列)#建立使用者create user ‘lin‘@‘localhost‘ identified by ‘123‘;#insert,delele,update,select#層級1:對所有庫,下的所有表,下的所有欄位grant select on *.* to ‘lin1‘@‘localhost‘ identified by ‘123‘;(第一個*代表所有庫,第二個*代表所有表)#層級2:對db1庫,下的所有表,下的所有欄位(@前是帳號,@後是密碼)grant select on db1.* to ‘lin2‘@‘localhost‘ identified by ‘123‘;#層級3:對錶db1.t1,下的所有欄位grant select on db1.t1 to ‘lin3‘@‘localhost‘ identified by ‘123‘;#層級4:對錶db1.t1,下的id,name欄位grant select (id,name) on db1.t1 to ‘lin4‘@‘localhost‘ identified by ‘123‘;grant select (id,name),update (name) on db1.t1 to ‘lin5‘@‘localhost‘ identified by ‘123‘;#修改完許可權後,要記得重新整理許可權flush privileges;

  

mysql現在已提供什麼儲存引擎:
mysql> show engines;
看你的mysql當前預設的儲存引擎:
mysql> show variables like ‘%storage_engine%‘;
1.Myisam是Mysql的預設儲存引擎,當create建立新表時,未指定新表的儲存引擎時,預設使用Myisam。每個MyISAM在磁碟上儲存成三個檔案。檔案名稱都和表名相同,副檔名分別是.frm(儲存表定義)、.MYD(MYData,儲存資料)、.MYI(MYIndex,儲存索引)。資料檔案和索引檔案可以放置在不同的目錄,平均分布io,獲得更快的速度。
2.InnoDB儲存引擎提供了具有提交、復原和崩潰恢複能力的事務安全。但是對比Myisam的儲存引擎,InnoDB寫的處理效率差一些並且會佔用更多的磁碟空間以保留資料和索引。
修改mysql的預設儲存引擎

1、查看mysql儲存引擎命令,
在mysql>提示符下搞入show engines;
欄位 Support為:Default表示預設儲存引擎
www.2cto.com
2、設定InnoDB為預設引擎:
在設定檔my.cnf中的 [mysqld] 下面加入
default-storage-engine=INNODB 一句

3、重啟mysql伺服器:
mysqladmin -u root -p shutdown
或者service mysqld restart 登入mysql資料庫


MySQL查看和修改表的儲存引擎
1 查看系統支援的儲存引擎
show engines;
2 查看錶使用的儲存引擎
兩種方法:
a、show table status from db_name where name=‘table_name‘;
b、show create table table_name;
如果顯示的格式不好看,可以用\g代替行尾分號
有人說用第二種方法不準確,我試了下,關閉掉原先預設的Innodb引擎後根本無法執行show create table table_name指令,因為之前建的是Innodb表,關掉後預設用MyISAM引擎,導致Innodb表資料無法被正確讀取。
3 修改表引擎方法
alter table table_name engine=innodb;
4 關閉Innodb引擎方法
關閉mysql服務: net stop mysql
找到mysql安裝目錄下的my.ini檔案:
找到default-storage-engine=INNODB 改為default-storage-engine=MYISAM
找到#skip-innodb 改為skip-innodb
啟動mysql服務:net start mysql


查看資料庫編碼:
代碼如下:
SHOW CREATE DATABASE db_name;

查看錶編碼:
SHOW CREATE TABLE tbl_name;

查看欄位編碼:
代碼如下:
SHOW FULL COLUMNS FROM tbl_name

charset字元集

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.