MySQL--簡(jiǎn)介及安裝

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

第一章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ā)語(yǔ)言 :JAVA、Python
基本SQL語(yǔ)句深入學(xué)習(xí)(增刪改查)、數(shù)據(jù)庫(kù)結(jié)構(gòu)設(shè)計(jì)(建模)
高級(jí)SQL:存儲(chǔ)過(guò)程、函數(shù)、觸發(fā)器、視圖、事件

2,老男孩的MySQL課程-2019- 09月 - 中級(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語(yǔ)句使用 *****
(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 嚴(yán)謹(jǐn)

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

官方文檔
源碼
有經(jīng)驗(yàn)的人討論

3.3 請(qǐng)收起你的好奇心!!!!!

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

3.3,細(xì)心

對(duì)每一步操作都要負(fù)責(zé)
把簡(jiǎn)單的事情做到最專業(yè)

3.4,心態(tài)

別惹事,出事別怕事

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

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

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

3.7,熟悉行業(yè)

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

3.8,喜歡數(shù)據(jù)庫(kù)

體驗(yàn)很重要

第二章:MySQL介紹和安裝

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

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

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

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

RDBMS: 關(guān)系型數(shù)據(jù)庫(kù)管理系統(tǒng)
二維表的方式組織和存儲(chǔ)數(shù)據(jù)
安全,強(qiáng)一致性,功能強(qiáng)大
比較適合于,安全級(jí)別要求高的數(shù)據(jù)以及關(guān)系較復(fù)雜的數(shù)據(jù)

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

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

RDBMS  :
MySQL 、Oracle、MSSQL(SQL Server)、PG

NoSQL:Not Only SQL
鍵-值(key-value):Redis, memcached
文檔(document):Mongodb

4,MySQL的簡(jiǎn)介及產(chǎn)品線

4.1 MySQL行業(yè)主流版本:

    5.6  
    5.7    
    8.0(現(xiàn)在開始研究新特性)  從8.0.11開始是正式版本  之前是測(cè)試版本(8.0.1-8.0.10)

4.2企業(yè)版本選擇(MySQL分支版本),筆試題

Oracle:
      MySQL官方版
紅帽  :
      MariaDB 
      5.5版本號(hào)之后就是10.x開始
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.26  二進(jìn)制安裝,其他安裝方式自己擴(kuò)展

4.5如何獲取MySQL軟件

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

5,MySQL的二進(jìn)制安裝

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

[root@db01 ~]# mkdir /application
上傳軟件到此目錄
[root@db01 /application]# ls
mysql-5.7.26-linux-glibc2.12-x86_64.tar.gz

5.2。解壓并改名為MySQL的

[root@db01 application]# mv mysql-5.7.26-linux-glibc2.12-x86_64  mysql
[root@db01 application]# ll /application/mysql/
total 36
drwxr-xr-x  2 root root   4096 Jul 14 19:02 bin
-rw-r--r--  1 7161 31415 17987 Apr 13 21:32 COPYING
drwxr-xr-x  2 root root     55 Jul 14 19:02 docs
drwxr-xr-x  3 root root   4096 Jul 14 19:02 include
drwxr-xr-x  5 root root    230 Jul 14 19:02 lib
drwxr-xr-x  4 root root     30 Jul 14 19:02 man
-rw-r--r--  1 7161 31415  2478 Apr 13 21:32 README
drwxr-xr-x 28 root root   4096 Jul 14 19:02 share
drwxr-xr-x  2 root root     90 Jul 14 19:02 support-files


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

vim /etc/profile
export PATH=/application/mysql/bin:$PATH
[root@db01 ~]# source /etc/profile
[root@db01 ~]# mysql -V
mysql  Ver 14.14 Distrib 5.7.26, for linux-glibc2.12 (x86_64) using  EditLine wrapper

5.3。用戶的創(chuàng)建處理原始環(huán)境

[root@db01 ~]# yum remove mariadb-libs-5.5.60-1.el7_5.x86_64 -y
[root@db01 ~]# rpm -qa |grep mariadb
[root@db01 ~]# useradd -s /sbin/nologin mysql

5.4。創(chuàng)建數(shù)據(jù)路徑并授權(quán)

1. 添加一塊新磁盤模擬數(shù)據(jù)盤
2. 格式化并掛載磁盤
[root@db01 ~]# mkfs.xfs /dev/sdc
[root@db01 ~]# mkdir /data
[root@db01 ~]# blkid
[root@db01 ~]# vim /etc/fstab 
[root@db01 ~]# UUID="b7fde522-aa37-412a-9584-8313a673c5cc" /data xfs defaults 0 0
[root@db01 ~]# mount -a
[root@db01 ~]# df -h

5.5。創(chuàng)建相關(guān)目錄并修改權(quán)限

chown -R mysql.mysql /application/*
mkdir /data/mysql/data -p 
chown -R mysql.mysql /data

5.6。初始化數(shù)據(jù)(建庫(kù))

方法一:

初始化數(shù)據(jù),初始化管理員的臨時(shí)密碼
[root@db01 ~]# mysqld --initialize --user=mysql --basedir=/application/mysql --datadir=/data/mysql/data 

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
報(bào)錯(cuò)原因: Linux系統(tǒng)中缺少libaio-devel 軟件包
解決:
yum install -y libaio-devel

image
報(bào)錯(cuò)原因:
在/data/mysql/data 存在文件
解決:
\rm -rf /data/mysql/data/*

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

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

 \rm -rf /data/mysql/data/*
 mysqld --initialize-insecure --user=mysql --basedir=/application/mysql --datadir=/data/mysql/data

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 data]# cd /data/mysql/data/
[root@db01 data]# ll
total 122924
-rw-r----- 1 mysql mysql       56 Jul 22 15:54 auto.cnf
-rw-r----- 1 mysql mysql     3384 Jul 22 20:55 db01.err
-rw-r----- 1 mysql mysql        5 Aug  1 16:32 db01.pid
-rw-r----- 1 mysql mysql      419 Jul 22 15:54 ib_buffer_pool
-rw-r----- 1 mysql mysql 12582912 Aug  1 16:32 ibdata1
-rw-r----- 1 mysql mysql 50331648 Aug  1 16:32 ib_logfile0
-rw-r----- 1 mysql mysql 50331648 Jul 22 15:54 ib_logfile1
-rw-r----- 1 mysql mysql 12582912 Aug  1 16:32 ibtmp1
drwxr-x--- 2 mysql mysql     4096 Jul 22 15:54 mysql
drwxr-x--- 2 mysql mysql     8192 Jul 22 15:54 performance_schema
drwxr-x--- 2 mysql mysql     8192 Jul 22 15:54 sys


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

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

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

cat >/etc/my.cnf <<EOF
[mysqld]
user=mysql
basedir=/application/mysql
datadir=/data/mysql/data
socket=/tmp/mysql.sock
server_id=6
port=3306
[mysql]
socket=/tmp/mysql.sock
EOF

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

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

5.9使用systemd管理mysql

注意: sysv方式啟動(dòng)過(guò)的話,需要先提前關(guān)閉,才能以下方式登錄
cat >/etc/systemd/system/mysqld.service <<EOF
[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=/application/mysql/bin/mysqld --defaults-file=/etc/my.cnf
LimitNOFILE = 5000
EOF
systemctl  start/stop/restart/status   mysqld

6.安裝后的簡(jiǎn)單管理

管理員密碼的設(shè)定(root@localhost)
[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;

管理員用戶密碼忘記了?

--skip-grant-tables   跳過(guò)授權(quán)表
--skip-networking     跳過(guò)遠(yuǎn)程登錄

1 關(guān)閉數(shù)據(jù)庫(kù)
[root@db01 ~]# /etc/init.d/mysqld stop
Shutting down MySQL.. SUCCESS! 

2 啟動(dòng)數(shù)據(jù)庫(kù)到維護(hù)模式
[root@db01 ~]# mysqld_safe --skip-grant-tables --skip-networking &

3 登錄并修改密碼
SQL --- alter
mysql> alter user root@'localhost' identified by '1';
ERROR 1290 (HY000): The MySQL server is running with the --skip-grant-tables option so it cannot execute this statement
mysql> flush privileges;
mysql> alter user root@'localhost' identified by '1';
Query OK, 0 rows affected (0.01 sec)

SQL --- update
update mysql.user set authentication_string=PASSWORD('123456') where user='root' and hoost='localhost';
flush privileges;

4 關(guān)閉數(shù)據(jù)庫(kù),正常啟動(dòng)驗(yàn)證

小結(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_string

2.安裝方法:

二進(jìn)制
源碼
yum 

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

 mysqld --initialize-insecure --user=mysql --basedir=/application/mysql --datadir=/data/mysql/data

4.簡(jiǎn)易的配制文件的/etc/my.cnf

user 
basedir
datadir 
server_id
port
socket 

  1. 管理員密碼
mysqladmin -uroot -p password xxx

6.管理員密碼忘記

--skip-grant-tables   跳過(guò)授權(quán)表
--skip-networking     跳過(guò)遠(yuǎn)程登錄
最后編輯于
?著作權(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),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

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