標籤:資料庫索引 password 資料庫檔案 管理工具 支援人員
一、版本介紹
社區版:免費,個人使用,不能商業用,出了問題自己解決,沒有支援人員
企業版:收費,商業用,偏重於基本服務,cpu個數在1-4之間,費用4萬/年;超過4個,7萬/年
叢集版:收費,商業用,偏重於叢集設定,cpu個數在1-4之間,費用7萬/年;超過4個,14萬/年
二、yum安裝
mysql:主要提供管理工具
mysql-server:提供基本模組和功能
三、啟動資料庫
載入的內容以及資料庫下的檔案
說明:ibdata1、ib_logfile0、ib_logfile1都是資料庫索引檔案,用來快速定位元據;mysql.sock通訊端檔案,綁定了資料庫的IP、連接埠等,想要使用者串連訪問,就必須要有這個檔案
資料庫檔案解釋:
.frm檔案:存放資料用的資料表結構
.MYD檔案:存放資料表的具體資料
.MYI檔案:當前資料表的索引檔案
四、登入資料庫
mysql -u 使用者
-p 密碼
-h 登入哪台伺服器
-P 指定連接埠
a. mysqladmin:添加密碼的工具
格式:mysqladmin -uroot password‘123456‘
b. 修改root密碼:root登入之後
set password=password("654321")
c. 修改普通使用者密碼,root登入之後
set password for ‘user1‘@‘localhost‘ =password("654321")
d. 忘記root使用者密碼之後,重設密碼步驟:
1. 停止資料庫 service mysqld stop
2. 修改設定檔my.cnf,加入skip-grant-tables
3. 啟動資料庫 service mysqld stat,不用密碼直接root登入
4. 重設密碼 update mysql.user set password=password(‘123‘) where user=‘root‘
5. 修改設定檔,刪除skip-grant-tables
6. 重啟資料庫service mysqld restart
7. 新密碼登入
五、建立資料庫使用者
格式:create user [email protected]‘192.168.1.0/24‘ by identified ‘123456‘
六、資料庫操作(備份 還原 多機 叢集)
【增】
1. create databases db1
2. create tables tb1(欄位1 類型1,欄位2 類型2......)
建立資料庫和表,用到create命令,類型即域約束
3. insert into tb1(id,name,info) values (1,‘zhangshan‘,‘student‘)
字串值用單引號括起來,標紅可以不用寫,即插入所有欄位值,注意對應順序,用到insert into命令
4. insert into tb1 (name) values (‘lisi‘)
插入部分欄位資料
5. insert into tb1 values (1,‘zhangshan‘,‘student‘),(2,‘wangwu‘,‘student‘)...
同時插入多行資料
6. insert into tb1 (id) select id from tb2
將tb2中的id值複製給tb1的id欄位,兩條命令合并,id類型需相同
【刪】
1. drop database db1
2. drop table tb1
刪除庫和表,用到drop命令
3. delete from tb1 where id=2
刪除id=2的這一行資料,最好用主鍵來標識行,避免刪錯其他行,用到delete命令
【改】
說明:update更改資料,alter更改表
1. update tb1 set info=‘student‘ where id=5
更改一條資料,用到where來定位
2. update tb1 set info=‘student‘ where id between 4 and 10
用範圍匹配between and,更改多條資料
3. alter table tb1 rename tb10
更改表名,用到rename命令
4. alter table tb1 modify name char(60) not null default ‘ ‘
更改欄位類型,比如name的char長度,其他屬性也跟著改,如Default,用到modify命令
5. alter table tb1 change info information char(40) null
更改欄位名稱,用到change命令,其他屬性也跟著修改
6. alter table tb1 drop name
刪除某個欄位,用drop命令
7. alter table tb1 add time date first
添加一個欄位,用到add命令,date表示類型,first表示放在第一行呈現,沒有second選項,不加則預設最後一行;
8. alter table tb1 add nian year after time
after命令表示插入在某行的後面
【查】
1. show databases
2. show tables
3. show engines\G
4. desc tb1
5. select 欄位名/* from tb1
Field:欄位屬性
Null:是否允許數值為空白
Key:主鍵(約束),具有唯一性數值的欄位名,能快速定位到某一行,如id
Default:當沒有填入值時,預設填一個NULL
Extra:額外參數
6. show global variables like ‘%log%‘
查看跟日誌相關的變數
bin開頭:二進位日誌資訊,主從配置mysql,從伺服器的日誌也會產生在主的錯誤記錄檔裡
general開頭:一般查詢日誌資訊
innodb開頭:交易記錄資訊
relay開頭:中繼日誌資訊
【許可權】
1. grant all on db1.* to ‘user1‘@‘localhost‘ identified by ‘123456‘
授權use1r以本地身份登入,並擁有db1庫的所有許可權
2. show grants for ‘user1‘@‘localhost‘
查看user1在本地登入,擁有哪些許可權
3. revoke select on *.* to ‘user1‘@‘localhost‘
移除user1本地登入後的查詢許可權
六、MySQL資料庫用戶端圖形介面管理工具
1. MyDB Studio
2. phpMyAdmin
3. sqlyog
4. Navicat for MySQL
mysql-資料庫概述2