第一章 MySQL 大綱介紹
1椅棺、官方定義的MySQL? DBA工作內(nèi)容
(1)運維DBA初級:各版本犁罩、各平臺安裝搭建、升級中級:體系結(jié)構(gòu)原理两疚、基礎管理(啟動關(guān)閉床估、初始化配置文件管理、多實例管理诱渤、用戶權(quán)限管理丐巫、基本SQL(增刪改查))、? ? 日志管理、備份與恢復递胧、主從復制(構(gòu)建鸦做、狀態(tài)監(jiān)控) 高級:高可用(MGR、InnoDB Cluster)谓着、高性能(優(yōu)化)(2)開發(fā)DBA懂至少一門開發(fā)語言 :JAVA、Python基本SQL語句深入學習(增刪改查)坛掠、數(shù)據(jù)庫結(jié)構(gòu)設計(建模)高級SQL:存儲過程赊锚、函數(shù)、觸發(fā)器屉栓、視圖舷蒲、事件
2、老男孩MySQL課程-2019-03月-中級DBA要求(80%以上)
(1)MySQL 5.7 安裝部署(二進制)*****? ? 編譯自己擴展(2)MySQL升級步驟擴展 ***(3)MySQL5.7 體系結(jié)構(gòu)原理 *****(4)MySQL基礎管理? *****(5)基礎SQL語句使用 *****(6)SQL高級應用? ***(7)Information_schema獲取元數(shù)據(jù) ***(8)索引友多、執(zhí)行計劃管理(基礎優(yōu)化)*****(9)存儲引擎? *****(10)日志管理 *****(11)備份與恢復 ******(12)主從復制及架構(gòu)演變 ******(13)傳統(tǒng)的高可用及讀寫分離(MHA&Atlas)****(14)傳統(tǒng)分布式架構(gòu)設計與實現(xiàn)-擴展(Mycat--->DBLE,DRDS)**(15)MySQL 5.7 高可用及分布式架構(gòu)-擴展(MGR,InnoDB Cluster)***(16)MySQL優(yōu)化(安全牲平、性能) ****(17)MySQL 監(jiān)控(zabbix、Open-falcon)? ? ****(18)RDS(阿里云課程)*****額外要會的:? ? Redis? ? mongodb了解:PG? ? Oracle
3域滥、DBA職業(yè)素養(yǎng)
3.1纵柿、人品
責任-----權(quán)利
3.2
3.2.1、嚴謹
磁帶庫----->備份軟件-----17樓數(shù)據(jù)庫修改\刪除類的命令時 再三考慮启绰,而且要有理論或者實踐的支撐
3.2.2 請收起你的好奇心0喝濉!N伞Tò稀!
注意規(guī)范:脫庫着倾? 華住網(wǎng)(ip root 密碼)拾酝,“脫敏”!!!!!。學會保護自己!!!
3.3卡者、細心
把最簡單的事情做的最漂亮蒿囤,最專業(yè)。不要怕成功的門很擁擠,因為很多人在半路就已經(jīng)放棄了.? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ----oldguo
3.4崇决、心態(tài)
別惹事蟋软,出事別怕事
3.5、熟悉操作系統(tǒng)(精通)
3.6嗽桩、熟悉公司業(yè)務
業(yè)務岳守?? ? 產(chǎn)品的功能? ? 用戶的行為(熱功能,熱數(shù)據(jù))
3.7、熟悉行業(yè)
熟悉行業(yè)發(fā)展趨勢版本數(shù)據(jù)庫產(chǎn)品類型https://db-engines.com/en/ranking
3.8碌冶、喜歡數(shù)據(jù)庫
體驗很重要
第二章: MySQL 介紹和安裝
1湿痢、什么是數(shù)據(jù)?
數(shù)據(jù):文字、圖片譬重、視頻拒逮。。臀规。人類認知的數(shù)據(jù)表現(xiàn)方式計算機:二進制滩援、16進制的機器語言基于數(shù)據(jù)的重要性和復雜性的不同,我們可能有不同的管理方式塔嬉。哪些數(shù)據(jù)是適合存儲到數(shù)據(jù)庫的呢玩徊?重要性比較高的關(guān)系較復雜的數(shù)據(jù)
2、什么是數(shù)據(jù)庫管理系統(tǒng)(DBMS)谨究?
RDBMS: 關(guān)系型數(shù)據(jù)庫管理系統(tǒng)比較適合于,安全級別要求高的數(shù)據(jù)以及關(guān)系較復雜的數(shù)據(jù)NoSQL:非關(guān)系型數(shù)據(jù)庫管理系統(tǒng)適合于高性能存取數(shù)據(jù),一般是配合RDBMS進行使用的針對大數(shù)據(jù)處理分析,分布式架構(gòu)更加擅長
3恩袱、數(shù)據(jù)庫管理系統(tǒng)種類
RDBMS? :MySQL 、Oracle胶哲、MSSQL(SQLServer)畔塔、PGNoSQL:NotOnlySQL鍵-值(key-value):Redis,memcached文檔(document):Mongodb
4、MySQL簡介及產(chǎn)品線
4.1 MySQL行業(yè)主流版本:
5.6? ? ? 5.7? ? ? ? 8.0(現(xiàn)在開始研究新特性)
4.2 企業(yè)版本選擇(MySQL分支版本),筆試題
Oracle:? ? ? MySQL官方版紅帽? :? ? ? MariaDBPercona:? ? ? PerconaDB
4.3 版本選擇建議要上新環(huán)境
1.一般選擇官方主流版本:5.6,5.7 2.GA(穩(wěn)定發(fā)布版)3.6-12月的產(chǎn)品版本
4.4 課程版本:
5.7.20? 二進制安裝鸯屿,其他安裝方式自己擴展
4.5 如何獲取MySQL軟件
企業(yè)版:Enterprise,互聯(lián)網(wǎng)行業(yè)一般不選擇.社區(qū)版本:選擇源碼包:source code? ? .tar.gz? 通用二進制面試題:你們公司用什么版本數(shù)據(jù)庫? 具體什么小版本號?5.6.20 5.6.34 5.6.36? 5.6.38? 5.6.40? ? 5.7.18? 5.7.20? 5.7.22
5澈吨、MySQL二進制安裝
5.1.創(chuàng)建軟件目錄:
[root@db01~]# mkdir-p/app/上傳軟件到此目錄
5.2. 解壓并改名為mysql
[root@db01app]# mv mysql-5.7.20-linux-glibc2.12-x86_64 mysql[root@db01app]# ls -l /app/mysql/total36drwxr-xr-x2root root4096Mar414:55bin-rw-r--r--171613141517987Sep132017COPYINGdrwxr-xr-x2root root55Mar414:55docsdrwxr-xr-x3root root4096Mar414:55includedrwxr-xr-x5root root229Mar414:55libdrwxr-xr-x4root root30Mar414:55man-rw-r--r--17161314152478Sep132017READMEdrwxr-xr-x28root root4096Mar414:55sharedrwxr-xr-x2root root90Mar414:55support-files
修改環(huán)境變量:
vim /etc/profileexport PATH=/app/mysql/bin:$PATH[root@db01 bin]# source /etc/profile
5.3. 建立mysql用戶和組(如果已有可忽略)
useradd mysql
5.4. 創(chuàng)建相關(guān)目錄并修改權(quán)限
mkdir/data/mysql-p? chown-R mysql.mysql/app/*
chown -R mysql.mysql /data/*
5.5 初始化數(shù)據(jù)(建庫)
方法一:
初始化數(shù)據(jù),初始化管理員的臨時密碼mysqld--initialize--user=mysql--basedir=/app/mysql--datadir=/data/mysql2019-04-18T03:21:53.381108Z0[Warning]TIMESTAMPwithimplicitDEFAULTvalueisdeprecated.Pleaseuse--explicit_defaults_for_timestamp server option(see documentationformore details).2019-04-18T03:21:54.583415Z0[Warning]InnoDB:Newlog files created,LSN=457902019-04-18T03:21:54.697859Z0[Warning]InnoDB:Creatingforeign key constraint system tables.2019-04-18T03:21:54.760821Z0[Warning]NoexistingUUIDhas been found,so we assume thatthisisthe first time thatthisserver has been started.GeneratinganewUUID:1daa0c57-6189-11e9-bc80-000c294234c8.2019-04-18T03:21:54.770856Z0[Warning]Gtidtableisnot ready to be used.Table'mysql.gtid_executed'cannot be opened.2019-04-18T03:21:54.772016Z1[Note]Atemporary passwordisgeneratedforroot@localhost:9LN.fh_Ea#uU
image.png
報錯原因: Linux系統(tǒng)中缺少libaio-devel 軟件包解決:yum install -y libaio-devel
image.png
報錯原因:在/data/mysql 存在文件解決:\rm-rf/data/mysql/*
新特性重要說明:
5.7開始,MySQL加入了全新的 密碼的安全機制:
1.初始化完成后,會生成臨時密碼(顯示到屏幕上,并且會往日志中記一份)
2.密碼復雜度:長度:超過12位? 復雜度:字符混亂組合
3.密碼過期時間180天
方法二:初始化數(shù)據(jù)寄摆,初始化管理員的密碼為空\rm-rf/data/mysql/*[root@db01~]# mysqld --initialize-insecure? --user=mysql --basedir=/app/mysql --datadir=/data/mysql2019-04-18T03:37:43.146018Z0[Warning]TIMESTAMPwith implicitDEFAULTvalue is deprecated.Pleaseuse--explicit_defaults_for_timestamp server option(see documentationformore details).2019-04-18T03:37:43.892132Z0[Warning]InnoDB:Newlog files created,LSN=457902019-04-18T03:37:43.970412Z0[Warning]InnoDB:Creating foreign key constraint system tables.2019-04-18T03:37:44.029490Z0[Warning]No existingUUIDhas been found,so we assume that this is the first time that this server has been started.Generating anewUUID:5378f3b3-618b-11e9-9164-000c294234c8.2019-04-18T03:37:44.041469Z0[Warning]Gtid table is not ready to be used.Table'mysql.gtid_executed'cannot be opened.2019-04-18T03:37:44.042348Z1[Warning]root@localhost is created with anemptypassword!Please consider switching off the--initialize-insecure option.[root@db01~]# [root@db01~]# cd /data/mysql/[root@db01 mysql]# lltotal110628-rw-r-----1mysql mysql56Apr1811:37auto.cnf-rw-r-----1mysql mysql419Apr1811:37ib_buffer_pool-rw-r-----1mysql mysql12582912Apr1811:37ibdata1-rw-r-----1mysql mysql50331648Apr1811:37ib_logfile0-rw-r-----1mysql mysql50331648Apr1811:37ib_logfile1drwxr-x---2mysql mysql4096Apr1811:37mysqldrwxr-x---2mysql mysql8192Apr1811:37performance_schemadrwxr-x---2mysql mysql8192Apr1811:37sys[root@db01 mysql]#
注釋:5.6初始化的區(qū)別
/application/mysql/scripts/mysql_install_db--user=mysql--datadir=/application/mysql/data--basedir=/application/mysql
5.6 書寫默認配置文件
vim/etc/my.cnf[mysqld]user=mysqlbasedir=/app/mysqldatadir=/data/mysqlserver_id=6port=3306socket=/tmp/mysql.sock[mysql]socket=/tmp/mysql.sockprompt=3306[\\d]>
5.7 配置啟動腳本:
[root@db01 mysql]# cd/app/mysql/support-files[root@db01 support-files]#./mysql.server startStartingMySQL.Loggingto'/data/mysql/db01.err'.SUCCESS!cp mysql.server/etc/init.d/mysqld
5.8 使用systemd管理mysql
vim/etc/systemd/system/mysqld.service[Unit]Description=MySQLServerDocumentation=man:mysqld(8)Documentation=http://dev.mysql.com/doc/refman/en/using-systemd.htmlAfter=network.targetAfter=syslog.target[Install]WantedBy=multi-user.target[Service]User=mysqlGroup=mysqlExecStart=/app/mysql/bin/mysqld--defaults-file=/etc/my.cnfLimitNOFILE=5000
注意:將原來模式啟動mysqld先關(guān)閉棚辽,然后再用systemd管理。
systemctl? start/stop/restart/status? mysqld
6. 安裝后的簡單管理
[root@db01~]# mysqladmin -uroot -p password 123Enterpassword:mysqladmin:[Warning] Using a password on the command line interface can be insecure.Warning:Since password will be sent to server in plain text,use ssl connection to ensure password safety.5.6版本:select user,password,host from mysql.user;5.7 中用戶基本信息select user,authentication_string,host from mysql.user;desc? mysql.user;
小結(jié):
1.版本 (主流版本的GA時間了解一下)
5.6 5.7 5.6.38? 5.7.20 20170913(1)初始化方式變了mysql_install_db? mysqld? --initialize-insecure(2)用戶安全12位1804種復雜度(3)密碼字段authentication_strings
2.安裝方法:
二進制源碼yum
3.建庫(初始化數(shù)據(jù)庫)
mysqld--intialize-insecure--user=mysql--basedir=/app/mysql--datadir=/data/mysql
4.簡易的配制文件/etc/my.cnf
user basedirdatadir server_idportsocket
管理員密碼
mysqladmin -uroot -p password xx
作者:MySQL_oldguo
鏈接:http://www.reibang.com/p/dd7137c4efa5
來源:簡書
著作權(quán)歸作者所有包归。商業(yè)轉(zhuǎn)載請聯(lián)系作者獲得授權(quán),非商業(yè)轉(zhuǎn)載請注明出處铅歼。