編寫應用程序不方便
數據冗餘不可避免
應用程序依賴性
不支持對文件的併發訪問
數據間聯繫弱
難以按用戶視圖表示數據
無安全控制功能html
相互關聯的數據的集合
較少的數據冗餘
程序與數據相互獨立
保證數據的安全、可靠
最大限度地保證數據的正確性
數據能夠併發使用並能同時保證一致性mysql
數據庫是數據的聚集,它以必定的組織形式存於存儲介質上
DBMS是管理數據庫的系統軟件,它實現數據庫系統的各類功能。是數據庫系統的核心
DBA(團隊):負責數據庫的規劃、設計、協調、維護和管理等工做
應用程序指以數據庫爲基礎的應用程序linux
數據定義
數據處理
數據安全
數據備份c++
單機架構 :好比access,一些財務數據庫
大型主機/終端架構:一個大型主機帶多套鍵鼠顯示屏設備(終端)
主從式架構(C/S):主流的客戶端服務端架構
分佈式架構 :集羣正則表達式
關係 :關係就是二維表,其中:表中的行、列次序並不重要
行row(record):表中的每一行,又稱爲一條記錄
列column(field):表中的每一列,稱爲屬性或字段
主鍵Primary key:用於唯一肯定一個記錄的字段,一張表只能一個主鍵,且主鍵(或者複合主鍵)的字段不能重複
域domain:屬性的取值範圍,如,性別只能是‘男’和‘女’兩個值redis
數據庫規範化,又稱數據庫或資料庫的正規化、標準化,是數據庫設計中的一系列原理和技術,以減小數據庫中數據冗餘,增進數據的一致性。關係模型的發明者埃德加·科德最先提出這一律念,並於1970年代初定義了第一範式、第二
範式和第三範式的概念
RDMBS設計範式基礎概念:設計關係數據庫時,聽從不一樣的規範要求,設計出合理的關係型數據庫,不一樣的規範要求被稱爲不一樣範式,各類範式呈遞次規範,越高的範式數據庫冗餘越小
目前關係數據庫有六種範式:第一範式(1NF)、第二範式(2NF)、第三範式(3NF)、巴德斯科範式(BCNF)、第四範式(4NF)和第五範式(5NF,又稱完美範式)。知足最低要求的範式是第一範式(1NF)。在第一範式的基礎上進一步知足更多規範要求的稱爲第二範式(2NF),其他範式以次類推。通常數據庫只需知足第三範式(3NF)便可sql
附加知識點: /etc/gconf/gconf.xml.gefaults中大部分都是xml文件(圖形界面的xml文件)
其中有個%gconf-tree.xml文件,裏面的文件代碼格式就是xml格式。
在Cenots6中這個文件中的disable_user_list一行,這裏的它下面的type 中的value改成true,則centos6登錄的時候只能手動輸入用戶名而不會顯示用戶名的列表能夠鼠標點選了。shell
插件式存儲引擎:也稱爲「表類型」,存儲管理器有多種實現版本,功能和特性可能均略有差異;用戶可根據須要靈活選擇,Mysql5.5.5開始innoDB引擎是MYSQL默認引擎
MyISAM ==> Aria
InnoDB ==> XtraDB
單進程,多線程
諸多擴展和新特性
提供了較多測試組件
開源數據庫
mysql使用模式:編程
服務器監聽的兩種socket地址:
ip socket: 監聽在tcp的3306端口,支持遠程通訊
unix sock: 監聽在sock文件上,僅支持本機通訊
如:/var/lib/mysql/mysql.sock)
說明:host爲localhost,127.0.0.1時自動使用unix sock
Administration program for the mysqld daemon. Usage: mysqladmin [OPTIONS] command command.... Default options are read from the following files in the given order: /etc/my.cnf /etc/mysql/my.cnf ~/.my.cnf 可看到配置文件順序,這些文件不只包括服務器端還包括客戶端 mysqladmin password centos :修改密碼爲centos(若是沒有舊密碼) mysqladmin -uroot -pOLDPSW passwpord centos :修改舊密碼爲centos mysqladmin -uroot -pPSW ping|status|version :查看各類狀態 mysqladmin -uroot -pPSW shutdown :可關閉數據庫
下面爲一些操做示例:
============================================剛裝以後查看版本和已有用戶,注意加分號: MariaDB [(none)]> select user(); +----------------+ | user() | +----------------+ | root@localhost | +----------------+ 1 row in set (0.000 sec) MariaDB [(none)]> select version(); +-----------------+ | version() | +-----------------+ | 10.3.14-MariaDB | +-----------------+ 1 row in set (0.000 sec) MariaDB [(none)]> =====================================================剛裝以後登錄查看狀態 MariaDB [(none)]> status -------------- mysql Ver 15.1 Distrib 10.3.14-MariaDB, for Linux (x86_64) using readline 5.1 Connection id: 11 Current database: :當前正在使用的數據庫,可見當前爲空 Current user: root@localhost SSL: Not in use Current pager: stdout Using outfile: '' Using delimiter: ; Server: MariaDB Server version: 10.3.14-MariaDB MariaDB Server Protocol version: 10 Connection: Localhost via UNIX socket Server characterset: latin1 Db characterset: latin1 Client characterset: utf8 Conn. characterset: utf8 UNIX socket: /var/lib/mysql/mysql.sock :表示經過本機的socket套接字鏈接的本機的mysql,由於不走網絡,所以不須要端口號。這個套接字文件就顯示在這裏。 Uptime: 26 min 29 sec :線程 Threads: 7 Questions: 10 Slow queries: 0 Opens: 17 Flush tables: 1 Open tables: 11 Queries per second avg: 0.006 -------------- ========================================================剛裝以後查看數據庫,注意加分號: MariaDB [(none)]> show databases ; +--------------------+ | Database | +--------------------+ | information_schema | : 此數據庫是在內存中的,動態數據庫,其餘3個默認自帶數據庫都在/var/lib/mysql下 | mysql | : | performance_schema | : | test | : +--------------------+ 4 rows in set (0.002 sec) MariaDB [(none)]> Ctrl-C -- exit! ===============================================切換數據庫: MariaDB [(none)]> use mysql Reading table information for completion of table and column names You can turn off this feature to get a quicker startup with -A Database changed MariaDB [mysql]> ======================================================/var/lib/mysql/mysql 中文件: 21:49[root@centos7 /var/lib/mysql/mysql]# ls columns_priv.frm general_log.CSM help_topic.MYD proc.frm slow_log.CSM time_zone_name.frm columns_priv.MYD general_log.CSV help_topic.MYI proc.MYD slow_log.CSV time_zone_name.MYD columns_priv.MYI general_log.frm host.frm proc.MYI slow_log.frm time_zone_name.MYI column_stats.frm gtid_slave_pos.frm host.MYD procs_priv.frm tables_priv.frm time_zone_transition.frm column_stats.MYD gtid_slave_pos.ibd host.MYI procs_priv.MYD tables_priv.MYD time_zone_transition.MYD column_stats.MYI help_category.frm index_stats.frm procs_priv.MYI tables_priv.MYI time_zone_transition.MYI db.frm help_category.MYD index_stats.MYD proxies_priv.frm table_stats.frm time_zone_transition_type.frm db.MYD help_category.MYI index_stats.MYI proxies_priv.MYD table_stats.MYD time_zone_transition_type.MYD db.MYI help_keyword.frm innodb_index_stats.frm proxies_priv.MYI table_stats.MYI time_zone_transition_type.MYI event.frm help_keyword.MYD innodb_index_stats.ibd roles_mapping.frm time_zone.frm transaction_registry.frm event.MYD help_keyword.MYI innodb_table_stats.frm roles_mapping.MYD time_zone_leap_second.frm transaction_registry.ibd event.MYI help_relation.frm innodb_table_stats.ibd roles_mapping.MYI time_zone_leap_second.MYD user.frm func.frm help_relation.MYD plugin.frm servers.frm time_zone_leap_second.MYI user.MYD func.MYD help_relation.MYI plugin.MYD servers.MYD time_zone.MYD user.MYI func.MYI help_topic.frm plugin.MYI servers.MYI time_zone.MYI =============================================================進入數據庫中查看數據庫中的表(數據)命令,注意加分號: MariaDB [mysql]> show tables; +---------------------------+ | Tables_in_mysql | +---------------------------+ | column_stats | | columns_priv | | db | | event | | func | | general_log | | gtid_slave_pos | | help_category | | help_keyword | | help_relation | | help_topic | | host | | index_stats | | innodb_index_stats | | innodb_table_stats | | plugin | | proc | | procs_priv | | proxies_priv | | roles_mapping | | servers | | slow_log | | table_stats | | tables_priv | | time_zone | | time_zone_leap_second | | time_zone_name | | time_zone_transition | | time_zone_transition_type | | transaction_registry | | user | +---------------------------+ 31 rows in set (0.001 sec) =========================================================查看user中的字段(field),注意加分號: MariaDB [mysql]> desc user ; +------------------------+-----------------------------------+------+-----+----------+-------+ | Field | Type | Null | Key | Default | Extra | +------------------------+-----------------------------------+------+-----+----------+-------+ | Host | char(60) | NO | PRI | | | | User | char(80) | NO | PRI | | | | Password | char(41) | NO | | | | | Select_priv | enum('N','Y') | NO | | N | | | Insert_priv | enum('N','Y') | NO | | N | | | Update_priv | enum('N','Y') | NO | | N | | | Delete_priv | enum('N','Y') | NO | | N | | | Create_priv | enum('N','Y') | NO | | N | | | Drop_priv | enum('N','Y') | NO | | N | | | Reload_priv | enum('N','Y') | NO | | N | | | Shutdown_priv | enum('N','Y') | NO | | N | | | Process_priv | enum('N','Y') | NO | | N | | | File_priv | enum('N','Y') | NO | | N | | | Grant_priv | enum('N','Y') | NO | | N | | | References_priv | enum('N','Y') | NO | | N | | | Index_priv | enum('N','Y') | NO | | N | | | Alter_priv | enum('N','Y') | NO | | N | | | Show_db_priv | enum('N','Y') | NO | | N | | | Super_priv | enum('N','Y') | NO | | N | | | Create_tmp_table_priv | enum('N','Y') | NO | | N | | | Lock_tables_priv | enum('N','Y') | NO | | N | | | Execute_priv | enum('N','Y') | NO | | N | | | Repl_slave_priv | enum('N','Y') | NO | | N | | | Repl_client_priv | enum('N','Y') | NO | | N | | | Create_view_priv | enum('N','Y') | NO | | N | | | Show_view_priv | enum('N','Y') | NO | | N | | | Create_routine_priv | enum('N','Y') | NO | | N | | | Alter_routine_priv | enum('N','Y') | NO | | N | | | Create_user_priv | enum('N','Y') | NO | | N | | | Event_priv | enum('N','Y') | NO | | N | | | Trigger_priv | enum('N','Y') | NO | | N | | | Create_tablespace_priv | enum('N','Y') | NO | | N | | | Delete_history_priv | enum('N','Y') | NO | | N | | | ssl_type | enum('','ANY','X509','SPECIFIED') | NO | | | | | ssl_cipher | blob | NO | | NULL | | | x509_issuer | blob | NO | | NULL | | | x509_subject | blob | NO | | NULL | | | max_questions | int(11) unsigned | NO | | 0 | | | max_updates | int(11) unsigned | NO | | 0 | | | max_connections | int(11) unsigned | NO | | 0 | | | max_user_connections | int(11) | NO | | 0 | | | plugin | char(64) | NO | | | | | authentication_string | text | NO | | NULL | | | password_expired | enum('N','Y') | NO | | N | | | is_role | enum('N','Y') | NO | | N | | | default_role | char(80) | NO | | | | | max_statement_time | decimal(12,6) | NO | | 0.000000 | | +------------------------+-----------------------------------+------+-----+----------+-------+ 47 rows in set (0.002 sec) ================================================================從這個user表中field(字段)中挑出特定的字段來查看裏面的內容,注意加分號: 由6中結果可見默認安裝後只能在本機(遠程不行)且用root虛擬用戶身份(也能夠匿名任意用戶)鏈接mysql數據庫。 用戶爲空的項表明匿名用戶,它表示任何用戶名(隨便輸入)均可以登陸這個數據庫,好比說 mysql -u abc 命令也能夠登陸(可是空用戶不能登錄 必須得輸入字符才能夠) MariaDB [mysql]> select user,host,password from user; +------+---------------+----------+ | user | host | password | +------+---------------+----------+ | root | localhost | | :指的是本機網段127開頭 | root | centos7.6test | | :指的是本機IP 192.168.36.102(或者其餘網卡上的IP) | root | 127.0.0.1 | | | root | ::1 | | :IPV6上本機IP | | localhost | | :匿名用戶 | | centos7.6test | | :匿名用戶 +------+---------------+----------+ 6 rows in set (0.001 sec) ========================================默認安裝後匿名用戶直接登錄,以及用它查看數據庫信息(權限不如root大,看到的信息不如root多): 22:07[root@centos7 /var/lib/mysql]# mysql -u abc Welcome to the MariaDB monitor. Commands end with ; or \g. Your MariaDB connection id is 17 Server version: 10.3.14-MariaDB MariaDB Server Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. MariaDB [(none)]> select user() ; +---------------+ | user() | +---------------+ | abc@localhost | +---------------+ 1 row in set (0.000 sec) MariaDB [(none)]> show databases ; +--------------------+ | Database | +--------------------+ | information_schema | | test | +--------------------+ 2 rows in set (0.001 sec) ==========================================執行安全加固安裝腳本以後: MariaDB [mysql]> select user,host,password from user -> ; +------+-----------+-------------------------------------------+ | user | host | password | +------+-----------+-------------------------------------------+ | root | localhost | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 | | root | 127.0.0.1 | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 | | root | ::1 | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 | +------+-----------+-------------------------------------------+ 3 rows in set (0.001 sec) ======================================查看寫入配置文件中的設定: 11:38[root@centos7 ~]# mysql --print-defaults mysql would have been started with the following arguments: --prompt=Date:\D Count:\c \n\U[\d] >
服務器監聽的兩種socket地址:
ip socket: 監聽在tcp的3306端口,支持遠程通訊
unix sock: 監聽在sock文件上,僅支持本機通訊
如:/var/lib/mysql/mysql.sock)
說明:host爲localhost,127.0.0.1時自動使用unix sock
服務器端(mysqld):工做特性有多種配置方式
配置文件:
後面覆蓋前面的配置文件,順序以下:
12:28[root@centos7 ~]# ps aux | grep mysql root 403 0.0 0.0 112708 976 pts/2 S+ 12:29 0:00 grep --color=auto mysql mysql 66126 0.0 3.7 1768932 70740 ? Ssl Apr28 0:42 /usr/sbin/mysqld root 125855 0.0 0.1 119868 2552 pts/0 S+ 11:08 0:00 man mysql 12:29[root@centos7 ~]# getent passwd mysql mysql:x:988:982:MySQL server:/var/lib/mysql:/sbin/nologin 12:30[root@centos7 ~]#
建立用戶preinstallscript中的建立mysql系統用戶以及修改數據庫文件的權限命令:
# Create a MySQL user and group. Do not report any problems if it already # exists. groupadd -r mysql 2> /dev/null || true useradd -M -r --home $datadir --shell /sbin/nologin --comment "MySQL server" --gid mysql mysql 2> /dev/null || true # The user may already exist, make sure it has the proper group nevertheless (BUG#12823) usermod --gid mysql mysql 2> /dev/null || true # Change permissions so that the user that will run the MySQL daemon # owns all database files. chown -R mysql:mysql $datadir if [ ! -e $datadir/mysql ]; then # Create data directory mkdir -p $datadir/{mysql,test} # Initiate databases /usr/bin/mysql_install_db --rpm --user=mysql fi # Change permissions again to fix any new files. chown -R mysql:mysql $datadir # Fix permissions for the permission database so that only the user # can read them. chmod -R og-rw $datadir/mysql fi
Mariadb安裝方式:
CentOS 安裝光盤:可安裝可是版本太老
項目官方:https://downloads.mariadb.org/mariadb/repositories/
國內鏡像:https://mirrors.tuna.tsinghua.edu.cn/mariadb/yum/
https://mirrors.tuna.tsinghua.edu.cn/mysql/yum/
提早作好前兩步操做,而後
cd mariadb-10.2.18/ cmake . \ -DCMAKE_INSTALL_PREFIX=/app/mysql \ -DMYSQL_DATADIR=/data/mysql/ \ -DSYSCONFDIR=/etc/mysql \ -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=utf8mb4 \ -DDEFAULT_COLLATION=utf8mb4_general_ci
而後make && make install
提示:若是出錯,執行rm -f CMakeCache.txt
===============================================centos7: [mysqld] datadir=/var/lib/mysql socket=/var/lib/mysql/mysql.sock # Disabling symbolic-links is recommended to prevent assorted security risks symbolic-links=0 # Settings user and group are ignored when systemd is used. # If you need to run mysqld under a different user or group, # customize your systemd unit file for mariadb according to the # instructions in http://fedoraproject.org/wiki/Systemd [mysqld_safe] log-error=/var/log/mariadb/mariadb.log pid-file=/var/run/mariadb/mariadb.pid # # include all files from the config directory # !includedir /etc/my.cnf.d ===============================================centos6: [mysqld] datadir=/var/lib/mysql socket=/var/lib/mysql/mysql.sock user=mysql # Disabling symbolic-links is recommended to prevent assorted security risks symbolic-links=0 [mysqld_safe] log-error=/var/log/mysqld.log pid-file=/var/run/mysqld/mysqld.pid