Oldguo-標(biāo)桿班級(jí)-MySQL-lesson01-簡介及安裝

如果您對(duì)數(shù)據(jù)庫感興趣,可以添加 DBA解決方案QQ群:895979329

第一章 MySQL 大綱介紹

1、官方定義的MySQL DBA工作內(nèi)容

(1)運(yùn)維DBA
初級(jí):各版本、各平臺(tái)安裝搭建、升級(jí)
中級(jí):體系結(jié)構(gòu)原理、基礎(chǔ)管理(啟動(dòng)關(guān)閉、初始化配置文件管理、多實(shí)例管理、用戶權(quán)限管理、基本SQL(增刪改查))、
     日志管理、備份與恢復(fù)、主從復(fù)制(構(gòu)建、狀態(tài)監(jiān)控) 
高級(jí):高可用(MGR、InnoDB Cluster)、高性能(優(yōu)化)
(2)開發(fā)DBA
懂至少一門開發(fā)語言 :JAVA、Python
基本SQL語句深入學(xué)習(xí)(增刪改查)、數(shù)據(jù)庫結(jié)構(gòu)設(shè)計(jì)(建模)
高級(jí)SQL:存儲(chǔ)過程、函數(shù)、觸發(fā)器、視圖、事件

2、老男孩MySQL課程-2019-03月-中級(jí)DBA要求(80%以上)

(1)MySQL 5.7 安裝部署(二進(jìn)制)*****
    編譯自己擴(kuò)展
(2)MySQL升級(jí)步驟擴(kuò)展 ***
(3)MySQL5.7 體系結(jié)構(gòu)原理 *****
(4)MySQL基礎(chǔ)管理  *****
(5)基礎(chǔ)SQL語句使用 *****
(6)SQL高級(jí)應(yīng)用  ***
(7)Information_schema獲取元數(shù)據(jù) ***
(8)索引、執(zhí)行計(jì)劃管理(基礎(chǔ)優(yōu)化)*****
(9)存儲(chǔ)引擎  *****
(10)日志管理 *****
(11)備份與恢復(fù) ******
(12)主從復(fù)制及架構(gòu)演變 ******
(13)傳統(tǒng)的高可用及讀寫分離(MHA&Atlas)****
(14)傳統(tǒng)分布式架構(gòu)設(shè)計(jì)與實(shí)現(xiàn)-擴(kuò)展(Mycat--->DBLE,DRDS)**
(15)MySQL 5.7 高可用及分布式架構(gòu)-擴(kuò)展(MGR,InnoDB Cluster)***
(16)MySQL優(yōu)化(安全、性能) ****
(17)MySQL 監(jiān)控(zabbix、Open-falcon)    ****
 (18) RDS(阿里云課程)    *****

額外要會(huì)的:
    Redis
    mongodb     
了解: 
    PG
    Oracle  

3、DBA職業(yè)素養(yǎng)


3.1、人品

責(zé)任-----權(quán)利

3.2

3.2.1、嚴(yán)謹(jǐn)

磁帶庫----->備份軟件-----17樓
數(shù)據(jù)庫修改\刪除類的命令時(shí) 再三考慮,而且要有理論或者實(shí)踐的支撐

3.2.2 請(qǐng)收起你的好奇心!?。。?!

注意規(guī)范:
脫庫? 華住網(wǎng)(ip root 密碼),“脫敏”!!!!!。
學(xué)會(huì)保護(hù)自己!!!

3.3、細(xì)心

把最簡單的事情做的最漂亮,最專業(yè)。
不要怕成功的門很擁擠,因?yàn)楹芏嗳嗽诎肼肪鸵呀?jīng)放棄了.
                                           ----oldguo                     

3.4、心態(tài)

別惹事,出事別怕事

3.5、熟悉操作系統(tǒng)(精通)

3.6、熟悉公司業(yè)務(wù)

業(yè)務(wù)?
    產(chǎn)品的功能
    用戶的行為(熱功能,熱數(shù)據(jù))      

3.7、熟悉行業(yè)

熟悉行業(yè)發(fā)展趨勢
版本
數(shù)據(jù)庫產(chǎn)品類型
https://db-engines.com/en/ranking

3.8、喜歡數(shù)據(jù)庫

體驗(yàn)很重要

第二章: MySQL 介紹和安裝

1、什么是數(shù)據(jù)?

數(shù)據(jù):文字、圖片、視頻。。。人類認(rèn)知的數(shù)據(jù)表現(xiàn)方式
計(jì)算機(jī):二進(jìn)制、16進(jìn)制的機(jī)器語言
基于數(shù)據(jù)的重要性和復(fù)雜性的不同,我們可能有不同的管理方式。

哪些數(shù)據(jù)是適合存儲(chǔ)到數(shù)據(jù)庫的呢?
重要性比較高的
關(guān)系較復(fù)雜的數(shù)據(jù)

2、什么是數(shù)據(jù)庫管理系統(tǒng)(DBMS)?

RDBMS: 關(guān)系型數(shù)據(jù)庫管理系統(tǒng)
比較適合于,安全級(jí)別要求高的數(shù)據(jù)以及關(guān)系較復(fù)雜的數(shù)據(jù)

NoSQL:非關(guān)系型數(shù)據(jù)庫管理系統(tǒng)
適合于高性能存取數(shù)據(jù),一般是配合RDBMS進(jìn)行使用的
針對(duì)大數(shù)據(jù)處理分析,分布式架構(gòu)更加擅長

3、數(shù)據(jù)庫管理系統(tǒng)種類

RDBMS  :
MySQL 、Oracle、MSSQL(SQL Server)、PG
 
NoSQL:Not Only SQL
鍵-值(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官方版
紅帽  :
      MariaDB
Percona:
      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  二進(jìn)制安裝,其他安裝方式自己擴(kuò)展

4.5 如何獲取MySQL軟件

企業(yè)版:Enterprise  , 互聯(lián)網(wǎng)行業(yè)一般不選擇.
社區(qū)版本:選擇
源碼包:source code    .tar.gz   
通用二進(jìn)制   
面試題:
你們公司用什么版本數(shù)據(jù)庫? 具體什么小版本號(hào)?
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二進(jìn)制安裝

5.1.創(chuàng)建軟件目錄:

[root@db01 ~]# mkdir -p /app/
上傳軟件到此目錄

5.2. 解壓并改名為mysql

[root@db01 app]# mv mysql-5.7.20-linux-glibc2.12-x86_64 mysql
[root@db01 app]# ls -l /app/mysql/
total 36
drwxr-xr-x  2 root root   4096 Mar  4 14:55 bin
-rw-r--r--  1 7161 31415 17987 Sep 13  2017 COPYING
drwxr-xr-x  2 root root     55 Mar  4 14:55 docs
drwxr-xr-x  3 root root   4096 Mar  4 14:55 include
drwxr-xr-x  5 root root    229 Mar  4 14:55 lib
drwxr-xr-x  4 root root     30 Mar  4 14:55 man
-rw-r--r--  1 7161 31415  2478 Sep 13  2017 README
drwxr-xr-x 28 root root   4096 Mar  4 14:55 share
drwxr-xr-x  2 root root     90 Mar  4 14:55 support-files

修改環(huán)境變量:

vim /etc/profile
export 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ù),初始化管理員的臨時(shí)密碼
mysqld --initialize  --user=mysql --basedir=/app/mysql --datadir=/data/mysql

2019-04-18T03:21:53.381108Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2019-04-18T03:21:54.583415Z 0 [Warning] InnoDB: New log files created, LSN=45790
2019-04-18T03:21:54.697859Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2019-04-18T03:21:54.760821Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: 1daa0c57-6189-11e9-bc80-000c294234c8.
2019-04-18T03:21:54.770856Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2019-04-18T03:21:54.772016Z 1 [Note] A temporary password is generated for root@localhost: 9LN.fh_Ea#uU

image.png
報(bào)錯(cuò)原因: Linux系統(tǒng)中缺少libaio-devel 軟件包
解決:
yum install -y libaio-devel
image.png
報(bào)錯(cuò)原因:
在/data/mysql 存在文件
解決:
\rm -rf /data/mysql/*

新特性重要說明:
5.7開始,MySQL加入了全新的 密碼的安全機(jī)制:
1.初始化完成后,會(huì)生成臨時(shí)密碼(顯示到屏幕上,并且會(huì)往日志中記一份)
2.密碼復(fù)雜度:長度:超過12位? 復(fù)雜度:字符混亂組合
3.密碼過期時(shí)間180天

方法二 :
初始化數(shù)據(jù),初始化管理員的密碼為空

\rm -rf  /data/mysql/*
[root@db01 ~]# mysqld --initialize-insecure  --user=mysql --basedir=/app/mysql --datadir=/data/mysql

2019-04-18T03:37:43.146018Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2019-04-18T03:37:43.892132Z 0 [Warning] InnoDB: New log files created, LSN=45790
2019-04-18T03:37:43.970412Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2019-04-18T03:37:44.029490Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: 5378f3b3-618b-11e9-9164-000c294234c8.
2019-04-18T03:37:44.041469Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2019-04-18T03:37:44.042348Z 1 [Warning] root@localhost is created with an empty password ! Please consider switching off the --initialize-insecure option.
[root@db01 ~]# 

[root@db01 ~]# cd /data/mysql/
[root@db01 mysql]# ll
total 110628
-rw-r----- 1 mysql mysql       56 Apr 18 11:37 auto.cnf
-rw-r----- 1 mysql mysql      419 Apr 18 11:37 ib_buffer_pool
-rw-r----- 1 mysql mysql 12582912 Apr 18 11:37 ibdata1
-rw-r----- 1 mysql mysql 50331648 Apr 18 11:37 ib_logfile0
-rw-r----- 1 mysql mysql 50331648 Apr 18 11:37 ib_logfile1
drwxr-x--- 2 mysql mysql     4096 Apr 18 11:37 mysql
drwxr-x--- 2 mysql mysql     8192 Apr 18 11:37 performance_schema
drwxr-x--- 2 mysql mysql     8192 Apr 18 11:37 sys
[root@db01 mysql]# 

注釋:5.6初始化的區(qū)別

/application/mysql/scripts/mysql_install_db  --user=mysql --datadir=/application/mysql/data --basedir=/application/mysql

5.6 書寫默認(rèn)配置文件

vim /etc/my.cnf
[mysqld]
user=mysql
basedir=/app/mysql
datadir=/data/mysql
server_id=6
port=3306
socket=/tmp/mysql.sock
[mysql]
socket=/tmp/mysql.sock
prompt=3306 [\\d]>

5.7 配置啟動(dòng)腳本:

[root@db01 mysql]# cd /app/mysql/support-files
[root@db01 support-files]# ./mysql.server start
Starting MySQL.Logging to '/data/mysql/db01.err'.
 SUCCESS! 
cp mysql.server    /etc/init.d/mysqld

5.8 使用systemd管理mysql

vim /etc/systemd/system/mysqld.service 
[Unit]
Description=MySQL Server
Documentation=man:mysqld(8)
Documentation=http://dev.mysql.com/doc/refman/en/using-systemd.html
After=network.target
After=syslog.target
[Install]
WantedBy=multi-user.target
[Service]
User=mysql
Group=mysql
ExecStart=/app/mysql/bin/mysqld --defaults-file=/etc/my.cnf
LimitNOFILE = 5000

注意:將原來模式啟動(dòng)mysqld先關(guān)閉,然后再用systemd管理。

systemctl  start/stop/restart/status   mysqld

6. 安裝后的簡單管理

[root@db01 ~]# mysqladmin -uroot -p password 123
Enter password: 
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時(shí)間了解一下)

5.6 5.7 
5.6.38   5.7.20 
20170913 
(1) 初始化方式變了
mysql_install_db   
mysqld  --initialize-insecure
(2) 用戶安全
12位
180
4種復(fù)雜度

(3)密碼字段
authentication_strings

2.安裝方法:

二進(jìn)制
源碼
yum 

3.建庫(初始化數(shù)據(jù)庫)

mysqld --intialize-insecure --user=mysql --basedir=/app/mysql --datadir=/data/mysql 

4.簡易的配制文件/etc/my.cnf

user 
basedir
datadir 
server_id
port
socket 
  1. 管理員密碼
mysqladmin -uroot -p password xx
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

友情鏈接更多精彩內(nèi)容