日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 运维知识 > 数据库 >内容正文

数据库

vpn mysql_MYSQL数据库

發(fā)布時(shí)間:2023/12/3 数据库 26 豆豆
生活随笔 收集整理的這篇文章主要介紹了 vpn mysql_MYSQL数据库 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

1.關(guān)系型數(shù)據(jù)庫相關(guān)概念

關(guān)系Relational :關(guān)系就是二維表,其中:表中的行、列次序并不重要

行row:表中的每一行,又稱為一條記錄record

列column:表中的每一列,稱為屬性,字段,域field

主鍵Primary key:PK ,一個(gè)或多個(gè)字段的組合, 用于惟一確定一個(gè)記錄的字段,一張表只有一個(gè)主 鍵, 主鍵字段不能為空NULL

唯一鍵Unique key: 一個(gè)或多個(gè)字段的組合,用于惟一確定一個(gè)記錄的字段,一張表可以有多個(gè)UK,而 且UK字段可以為NULL

域domain:屬性的取值范圍,如,性別只能是'男'和'女'兩個(gè)值,人類的年齡只能0-150

2.常用關(guān)系數(shù)據(jù)庫

MySQL: MySQL, MariaDB, Percona Server

PostgreSQL: 簡(jiǎn)稱為pgsql,EnterpriseDB

Oracle

MSSQL Server

DB2

3聯(lián)系類型

一對(duì)一聯(lián)系(1:1)

一對(duì)多聯(lián)系(1:n):外鍵

多對(duì)多聯(lián)系(m:n):增加第三張表3聯(lián)系類型

4.數(shù)據(jù)庫規(guī)劃流程

1. 收集數(shù)據(jù),得到字段 收集必要且完整的數(shù)據(jù)項(xiàng) 轉(zhuǎn)換成數(shù)據(jù)表的字段

2. 把字段分類,歸入表,建立表的關(guān)聯(lián) 關(guān)聯(lián):表和表間的關(guān)系 分割數(shù)據(jù)表并建立關(guān)聯(lián)的優(yōu)點(diǎn) 節(jié)省空間 減少輸入錯(cuò)誤 方便數(shù)據(jù)修改

3. 規(guī)范化數(shù)據(jù)庫

5.數(shù)據(jù)庫的正規(guī)化

在第一范式的基礎(chǔ)上進(jìn)一步滿足更多規(guī)范要求的稱為第二范式(2NF),其余范式以次類 推。一般數(shù)據(jù)庫只需滿足第三范式(3NF)即可 規(guī)則是死的,人是活的,所以范式是否必須遵守,要看業(yè)務(wù)需要而定 掌握范式的目的是為了在合適的場(chǎng)景下違反范式

第一范式:1NF

無重復(fù)的列,每一列都是不可分割的基本數(shù)據(jù)項(xiàng),同一列中不能有多個(gè)值,即實(shí)體中的某個(gè)屬性不能有 多個(gè)值或者不能有重復(fù)的屬性,確保每一列的原子性。除去同類型的字段,就是無重復(fù)的列 說明:第一范式(1NF)是對(duì)關(guān)系模式的基本要求,不滿足第一范式(1NF)的數(shù)據(jù)庫就不是關(guān)系數(shù)據(jù) 庫

第二范例:2NF

第二范式必須先滿足第一范式,屬性完全依賴于主鍵,要求表中的每個(gè)行必須可以被唯一地區(qū)分,通常 為表加上每行的唯一標(biāo)識(shí)PK,非PK的字段需要與整個(gè)PK有直接相關(guān)性,即非PK的字段不能依賴于部分主鍵

第三范式:3NF

滿足第三范式必須先滿足第二范式屬性,非主鍵屬性不依賴于其它非主鍵屬性。第三范式要求一個(gè)數(shù)據(jù) 表中不包含已在其它表中已包含的非主關(guān)鍵字信息,非PK的字段間不能有從屬關(guān)系

6.MySQL安裝方式介紹和快速安裝

安裝方式

程序包管理器管理的程序包

源代碼編譯安裝

二進(jìn)制格式的程序包:展開至特定路徑,并經(jīng)過簡(jiǎn)單配置后即可使用

centos8:安裝光盤直接提供

mysql-server:8.0

mariadb-server:10.3.17

centos7:安裝光盤直接提供

mariadb-server:5.5 服務(wù)包

mariadb 客戶端工具包

centos6:

mysql-serve:5.1 服務(wù)器包

mysql 客戶端工具包

范例

[14:07:38 root@centos7 yum.repos.d]$vim mysql.repo 創(chuàng)建倉庫

[mysql]

name=mysql5.7baseurl=https://mirrors.tuna.tsinghua.edu.cn/mysql/yum/mysql-5.7-community-el7-x86_64/

gpgcheck=0配置清華大學(xué)倉庫路徑

[14:10:44 root@centos7 yum.repos.d]$yum list |grep 'mysql*'可以看到包

[14:10:44 root@centos7 yum.repos.d]$yum -y install mysql-community-server

[14:19:40 root@centos7 yum.repos.d]$systemctl enable --now mysqld

ss-ntl 發(fā)現(xiàn)端口3306開啟

[14:22:34 root@centos7 yum.repos.d]$mysql 5.7版本會(huì)默認(rèn)創(chuàng)建數(shù)據(jù)庫用戶root'@'localhost

ERROR1045 (28000): Access denied for user 'root'@'localhost'(using password: NO)

[14:27:43 root@centos7 yum.repos.d]$grep password /var/log/mysqld.log 臨時(shí)密碼位置2021-01-28T06:20:26.300014Z 1 [Note] A temporary password is generated for root@localhost: AK:1dY&92qyb2021-01-28T06:21:55.139910Z 2 [Note] Access denied for user 'root'@'localhost'(using password: NO)2021-01-28T06:22:45.441398Z 3 [Note] Access denied for user 'root'@'localhost'(using password: NO)

[14:28:11 root@centos7 yum.repos.d]$mysql -uroot -p'AK:1dY&92qyb'初始密碼登錄后會(huì)要求你修改密碼

mysql: [Warning] Using a password on the command line interface can be insecure.

Welcome to the MySQL monitor. Commands end with ; or \g.

Your MySQL connectionid is 4Server version:5.7.33Copyright (c)2000, 2021, Oracle and/or its affiliates.

Oracle is a registered trademark of Oracle Corporation and/or its

affiliates. Other names may be trademarks of their respective

owners.

Type'help;' or '\h' for help. Type '\c' to clearthe current input statement.

mysql> ALTER USER root@'localhost' identified by 'Yangbo!0'; 注意密碼要設(shè)置的復(fù)雜一些

Query OK,0 rows affected (0.00sec)

mysql>status--------------mysql Ver14.14 Distrib 5.7.33, forLinux (x86_64) using EditLine wrapper

Connectionid: 5Current database:

Current user: root@localhost

SSL: Notinuse

Current pager: stdout

Using outfile:''Using delimiter: ;

Server version:5.7.33Protocol version:10Connection: Localhost via UNIX socket

Server characterset: latin1

Db characterset: latin1

Client characterset: utf8

Conn. characterset: utf8

UNIX socket:/var/lib/mysql/mysql.sock

Uptime:24 min 13sec

Threads:1 Questions: 22 Slow queries: 0 Opens: 107 Flush tables: 1 Open tables: 100 Queries per second avg: 0.015

--------------mysql>exit

修改初始密碼嗎方法二

[14:45:28 root@centos7 yum.repos.d]$mysqladmin -uroot -p'AK:1dY&92qyb' password 'Yangbo!0'

Ubuntu默認(rèn)啟用,空密碼登錄

7初始化腳本提高安全性

運(yùn)行腳本:mysql_secure_installation

設(shè)置數(shù)據(jù)庫管理員root口令

禁止root遠(yuǎn)程登錄

刪除anonymous用戶帳號(hào)

刪除test數(shù)據(jù)庫

范例:針對(duì)5.6版本安全加固

[15:06:20 root@centos7 yum.repos.d]$mysql

Welcome to the MySQL monitor. Commands end with ; or \g.

Your MySQL connectionid is 3Server version:5.6.51MySQL Community Server (GPL)

Copyright (c)2000, 2021, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its

affiliates. Other names may be trademarks of their respective

owners.

Type'help;' or '\h' for help. Type '\c' to clearthe current input statement.

默認(rèn)空密碼登錄

mysql> selectuser,host from mysql.user;+------+-----------+

| user | host |

+------+-----------+

| root | 127.0.0.1 |

| root | ::1 |

| | centos7 |

| root | centos7 |

| | localhost |匿名賬號(hào)| root | localhost |

+------+-----------+

6 rows in set (0.00sec)

代表6個(gè)用戶

[15:12:11 root@centos7 yum.repos.d]$mysql_secure_installation

NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MySQL

SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY!In order to log into MySQL to secure it, we'll need the current

password for the root user. If you've just installed MySQL, and

you haven't set the root password yet, the password will be blank,

so you should just press enter here.

Enter current passwordfor root (enter fornone): 沒有密碼回車

OK, successfully used password, moving on...

Setting the root password ensures that nobody can log into the MySQL

root user without the proper authorisation.

Set root password? [Y/n] y 是否設(shè)置root口令

New password:

Re-enter new password:

Password updated successfully!Reloading privilege tables..

... Success!By default, a MySQL installation has an anonymous user, allowing anyone

to log into MySQL without having to have a user account createdforthem. This is intended onlyfor testing, and to makethe installation

go a bit smoother. You should remove them before moving into a

production environment.

Remove anonymous users? [Y/n] y 是否移除匿名用戶

... Success!Normally, root should only be allowed to connect from'localhost'. This

ensures that someone cannot guess at the root password from the network.

Disallow rootlogin remotely? [Y/n] y 禁用遠(yuǎn)程登錄

... Success!By default, MySQL comes with a database named'test'that anyone can

access. This is also intended onlyfortesting, and should be removed

before moving into a production environment.

Remove test database and access to it? [Y/n] y-Dropping test database...

ERROR1008 (HY000) at line 1: Can't drop database'test'; database doesn't exist

... Failed!Not critical, keep moving...-Removing privileges on test database...

... Success!Reloading the privilege tables will ensure that all changes made so far

will take effect immediately.

Reload privilege tables now? [Y/n] y 是否生效

... Success!Alldone! If you've completed all of the above steps, your MySQL

installation should now be secure.

Thanksfor using MySQL!Cleaning up...

[15:18:19 root@centos7 yum.repos.d]$mysql

ERROR1045 (28000): Access denied for user 'root'@'localhost'(using password: NO)

再次空口令登錄失敗

[15:17:56 root@centos7 yum.repos.d]$mysql -uroot -p'123456'登錄成功

mysql> selectuser,host from mysql.user;+------+-----------+

| user | host |

+------+-----------+

| root | 127.0.0.1 |

| root | ::1 |

| root | localhost |

+------+-----------+

3 rows in set (0.00sec)

刪除了之前的不安全登錄

8.MYSQL組成

客戶端程序

mysql: 交互式或非交互式的CLI工具

mysqldump:備份工具,基于mysql協(xié)議向mysqld發(fā)起查詢請(qǐng)求,并將查得的所有數(shù)據(jù)轉(zhuǎn)換成

insert等寫操作語句保存文本文件中

mysqladmin:基于mysql協(xié)議管理mysqld

[15:35:39 root@centos7 yum.repos.d]$mysqladmin -uroot -p'Yangbo!0'用法幫助ping[15:29:05 root@centos7 yum.repos.d]$mysqladmin -uroot -p'Yangbo!0' pingmysqladmin: [Warning] Using a password on the command line interface can be insecure.

mysqld is alive

驗(yàn)證數(shù)據(jù)庫是否正常運(yùn)行

shutdown

[15:29:05 root@centos7 yum.repos.d]$mysqladmin -uroot -p'Yangbo!0'shutdown

安全的關(guān)閉數(shù)據(jù)庫,要耐心等待

mysqlimport:數(shù)據(jù)導(dǎo)入工具

服務(wù)器端程序

mysqld_safe

mysqld

mysqld_multi 多實(shí)例 ,示例:mysqld_multi --example

用戶賬戶

mysql用戶賬號(hào)由兩部分組成:

'USERNAME'@'HOST'

說明: HOST限制此用戶可通過哪些遠(yuǎn)程主機(jī)連接mysql服務(wù)器 支持使用通配符:

% 匹配任意長(zhǎng)度的任意字符,相當(dāng)于shell中*, 示例: 172.16.0.0/255.255.0.0 或 172.16.%.%_ 匹配任意單個(gè)字符

9.mysql 客戶端命令

客戶端命令:本地執(zhí)行,每個(gè)命令都完整形式和簡(jiǎn)寫格式

mysql>\h, help

mysql>\u,use

mysql>\s,status

mysql> \!,system

服務(wù)端命令:通過mysql協(xié)議發(fā)往服務(wù)器執(zhí)行并取回結(jié)果,命令末尾都必須使用命令結(jié)束符號(hào),默 認(rèn)為分號(hào)

-A, --no-auto-rehash 禁止補(bǔ)全-u, --user=用戶名,默認(rèn)為root-h, --host=服務(wù)器主機(jī),默認(rèn)為localhost-p, --passowrd= 用戶密碼,建議使用-p,默認(rèn)為空密碼-P, --port=服務(wù)器端口-S, --socket=指定連接socket文件路徑-D, --database=指定默認(rèn)數(shù)據(jù)庫-C, --compress 啟用壓縮-e “SQL“ 執(zhí)行SQL命令-V, --version 顯示版本-v --verbose 顯示詳細(xì)信息--print-defaults 獲取程序默認(rèn)使用的配置

范例:mysql的配置文件,修改提示符

[16:15:51 root@centos7 yum.repos.d]$mysql -uroot -p'Yangbo!0' --prompt="(\\u@\\h) [\\d]>\\_"臨時(shí)修改mysql提示符

[16:17:49 root@centos7 ~]$vim /etc/my.cnf

[mysql]

prompt="\\r:\\m:\\s(\\u@\\h) [\\d]>\\_"寫入配置文件永久保存

范例:配置所有MySQL客戶端的自動(dòng)登錄

[16:17:49 root@centos7 ~]$vim /etc/my.cnf

[mysql]

user=root

password='Yangbo!0'

服務(wù)器端配置

服務(wù)器端配置文件:

/etc/my.cnf #Global選項(xiàng)

/etc/mysql/my.cnf #Global選項(xiàng)

~/.my.cnf #User-specific 選項(xiàng)

配置文件格式:

[mysqld]

[mysqld_safe]

[mysqld_multi]

[mysql]

[mysqldump]

[server]

[client]

格式:

parameter = value

socket地址

ip socket: 監(jiān)聽在tcp的3306端口,支持遠(yuǎn)程通信 ,偵聽3306/tcp端口可以在綁定有一個(gè)或全部接 口IP上 unix sock: 監(jiān)聽在sock文件上,僅支持本機(jī)通信, 如:/var/lib/mysql/mysql.sock

范例:關(guān)閉遠(yuǎn)程連接,通過socket文件連接

vim /etc/my.cnf

[mysqld]

skip-networking=1

10.通用二進(jìn)制格式安裝MySQL 5.7

安裝相關(guān)包

[16:45:03 root@centos7 ~]$yum -y install libaio numactl-libs

用戶和組

[16:45:03 root@centos7 ~]$groupadd mysql

[16:45:43 root@centos7 ~]$useradd -r -g mysql -s /bin/false mysql

準(zhǔn)備程序文件

[16:54:22 root@centos7 ~]$wget http://mirrors.163.com/mysql/Downloads/MySQL-5.7/mysql-5.7.31-linux-glibc2.12

[16:58:44 root@centos7 ~]$tar xf mysql-5.7.31-linux-glibc2.12-x86_64.tar.gz -C /usr/local/[16:59:46 root@centos7 ~]$cd /usr/local/[16:59:56 root@centos7 local]$ln -s mysql-5.7.31-linux-glibc2.12-x86_64/mysql

[17:03:30 root@centos7 local]$chown -R root:root /usr/local/mysql/

準(zhǔn)備環(huán)境變量

[17:05:43 root@centos7 local]$echo 'PATH=/usr/local/mysql/bin:$PATH' > /etc/profile.d/mysql.sh[17:09:09 root@centos7 local]$. /etc/profile.d/mysql.sh

準(zhǔn)備配置文件

[17:13:41 root@centos7 local]$cp /etc/my.cnf{,.bak} 備份原文件

[17:14:31 root@centos7 local]$vim /etc/my.cnf

[mysqld]

datadir=/data/mysql

skip_name_resolve=1socket=/data/mysql/mysql.sock

log-error=/data/mysql/mysql.log

pid-file=/data/mysql/mysql.pid

[client]

socket=/data/mysql/mysql.sock

生成數(shù)據(jù)庫文件,并提取root密碼

[17:46:49 root@centos7 /]$mkdirdata

[17:47:00 root@centos7 /]$mysqld --initialize --user=mysql --datadir=/data/mysql5.6版本生成數(shù)據(jù)庫/usr/local/mysql/scripts/mysql_install_db --user=mysql -- datadir=/data/mysql --basedir=/usr/local/mysql/[17:48:51 root@centos7 /]$grep password /data/mysql/mysql.log2021-01-28T09:47:16.362119Z 1 [Note] A temporary password is generated for root@localhost: R&d0iVsQ,564初始密碼

[17:53:37 root@centos7 /]$awk '/temporary password/{print $11}' /data/mysql/mysql.log

R&d0iVsQ,564

準(zhǔn)備服務(wù)腳本和啟動(dòng)

[17:53:54 root@centos7 /]$cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld

[18:01:31 root@centos7 /]$chkconfig --add mysqld

[18:01:40 root@centos7 /]$service mysqld start

修改口令

[18:01:51 root@centos7 /]$mysqladmin -uroot -p'R&d0iVsQ,564'password yangbo

[18:05:06 root@centos7 /]$mysql -uroot -p'yangbo'登錄成功

11.源碼編譯安裝mysql-5.6.51

安裝相關(guān)依賴包

yum -y install gcc gcc-c++ cmake bison bison-devel zlib-devel libcurl-devel libarchive-devel boost-devel ncurses-devel gnutls-devel libxml2-devel openssl-devel libevent-devel libaio-devel perl-Data-Dumper

準(zhǔn)備用戶和數(shù)據(jù)目錄

useradd -r -s /sbin/nologin -d /data/mysql mysql

準(zhǔn)備用戶和數(shù)據(jù)目錄

[18:25:56 root@centos7 ~]$mkdir -p /data/mysql

[18:26:24 root@centos7 data]$chown mysql:mysql /data/mysql

下載源碼包并解壓縮源碼包

[18:21:06 root@centos7 ~]$tar -xf mysql-5.6.51.tar.gz -C /usr/local/src

[18:27:03 root@centos7 data]$cd /usr/local/src/mysql-5.6.51/[18:52:44 root@centos7 mysql-5.6.51]$cmake . \-DCMAKE_INSTALL_PREFIX=/apps/mysql \-DMYSQL_DATADIR=/data/mysql/\-DSYSCONFDIR=/etc/\-DMYSQL_USER=mysql \-DWITH_INNOBASE_STORAGE_ENGINE=1\-DWITH_ARCHIVE_STORAGE_ENGINE=1\-DWITH_BLACKHOLE_STORAGE_ENGINE=1\-DWITH_PARTITION_STORAGE_ENGINE=1\-DWITHOUT_MROONGA_STORAGE_ENGINE=1\-DWITH_DEBUG=0\-DWITH_READLINE=1\-DWITH_SSL=system \-DWITH_ZLIB=system \-DWITH_LIBWRAP=0\-DENABLED_LOCAL_INFILE=1\-DMYSQL_UNIX_ADDR=/data/mysql/mysql.sock \-DDEFAULT_CHARSET=utf8 \-DDEFAULT_COLLATION=utf8_general_ci

[18:52:44 root@centos7 mysql-5.6.51]$make && make install如果出錯(cuò)rm-rf CMakeCache.txt

準(zhǔn)備環(huán)境變量

[18:52:44 root@centos7 mysql-5.6.51]$echo 'PATH=/apps/mysql/bin:$PATH' > /etc/profile.d/mysql.sh[18:59:11 root@centos7 mysql-5.6.51]$. /etc/profile.d/mysql.sh

生成數(shù)據(jù)庫文件

[18:59:33 root@centos7 mysql-5.6.51]$cd /apps/mysql/[19:01:20 root@centos7 mysql]$scripts/mysql_install_db --datadir=/data/mysql/ --user=mysql

準(zhǔn)備配置文件

[19:01:20 root@centos7 mysql]$cp -b /apps/mysql/support-files/my-default.cnf /etc/my.cnfcp: overwrite ‘/etc/my.cnf’? y

準(zhǔn)備啟動(dòng)腳本,并啟動(dòng)服務(wù)

[19:03:28 root@centos7 mysql]$cp /apps/mysql/support-files/mysql.server /etc/init.d/mysqld

[19:09:23 root@centos7 mysql]$chkconfig --add mysqld

[19:09:32 root@centos7 mysql]$service mysqld start

安全初始化

mysql_secure_installation

總結(jié)

以上是生活随笔為你收集整理的vpn mysql_MYSQL数据库的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。