当前位置: 首页 > news >正文

做网站的价格贵吗网站栏目结构图

做网站的价格贵吗,网站栏目结构图,连锁租车网站源码,郑州网站建设专注乐云seo主要内容#xff1a; 源码编译安装、rsync同步操作、inotify实时同步、数据库服务基础 实操前骤#xff1a;#xff08;所需tools.tar.gz与users.sql#xff09; 1.两台主机设置SELinnx和关闭防火墙 setenforce 0 systemctl stop firewalld.service //停止防火墙 sy…主要内容 源码编译安装、rsync同步操作、inotify实时同步、数据库服务基础 实操前骤所需tools.tar.gz与users.sql 1.两台主机设置SELinnx和关闭防火墙 setenforce 0 systemctl stop firewalld.service     //停止防火墙 systemctl disable firewalld.service 2.真机远程复制tools.tar.gz到虚拟机1 [rootlocalhost 桌面]# scp /linux-soft/1/tools.tar.gz root192.168.4.7:/root root192.168.4.7s password: tools.tar.gz                                  100%  766KB   6.1MB/s   00:00     一、源码编译安装介绍 源码编译安装是指从软件的源代码开始通过手动编译和安装过程来部署软件的一种方法。这种方法通常用于需要高度定制化或最新版本的软件或者在特定操作系统或硬件平台上没有预编译二进制包的情况下。 1、源码包编译安装 1源码编译安装的基本步骤如下 获取源代码通常通过下载软件的源代码压缩包如.tar.gz或.zip文件或从版本控制系统如Git中克隆代码库。 解压源代码将下载的源代码压缩包解压到一个目录中。 配置编译选项运行配置脚本通常是./configure该脚本会检查系统环境设置编译选项并生成Makefile文件。配置脚本通常允许用户通过命令行参数指定安装路径、启用或禁用某些功能等。 编译源代码运行make命令该命令会根据Makefile文件中的指令编译源代码。编译过程可能包括编译源文件、链接库文件等步骤。 安装软件运行make install命令该命令会将编译好的二进制文件、库文件、配置文件等安装到系统中指定的目录通常是/usr/local或用户指定的路径。 2源码包相较于RPM软件包的优劣势 RPM包 定义RPM软件包是一种预编译的二进制包通常用于基于Red Hat的Linux发行版如Fedora、CentOS、RHEL等。包含了编译好的可执行文件、库文件、配置文件和安装脚本等。 优势 易于安装和管理RPM包可以通过简单的命令如rpm -i或yum install进行安装且支持依赖关系自动解决。版本控制RPM包管理系统可以跟踪已安装的软件包及其版本方便升级和卸载。一致性RPM包在特定发行版上编译确保与系统库和工具的兼容性。安全性RPM包可以进行数字签名验证确保来源的可靠性。 缺点 定制性有限由于是预编译的二进制包用户无法轻易修改编译选项或功能。版本更新滞后RPM包通常由发行版维护者提供可能不会立即提供最新版本的软件。 源码包 定义包含软件的源代码通常以压缩文件如.tar.gz或.zip的形式分发。用户需要手动编译源代码生成可执行文件和库文件。 优势 定制化用户可以根据需要定制编译选项选择启用或禁用某些功能。最新版本可以获取和安装软件的最新版本而不必等待发行版的更新。平台适应性可以在没有预编译二进制包的平台上安装软件。 缺点 复杂性相比使用预编译的二进制包源码编译安装过程更为复杂需要用户具备一定的技术知识。时间消耗编译过程可能需要较长时间特别是对于大型软件项目。依赖管理可能需要手动解决软件依赖关系确保所有必要的库和工具都已安装。 总结 RPM软件包 适合追求安装简便、系统一致性和安全性的用户特别是在企业环境中。源码包 适合需要高度定制化、追求最新版本或在没有预编译包的平台上安装软件的用户。 2、准备编译环境 开源软件多使用C/C语言开发需要 gcc、gcc-c、make默认安装等编译工具 例如 [rootsvr7 ~]# yum -y install gcc make     //安装软件包 [rootsvr7 ~]# rpm -q gcc gcc-4.8.5-28.el7.x86_64 [rootsvr7 ~]# rpm -q make make-3.82-23.el7.x86_64 [rootsvr7 ~]# gcc --version gcc (GCC) 4.8.5 20150623 (Red Hat 4.8.5-28) Copyright © 2015 Free Software Foundation, Inc. 本程序是自由软件请参看源代码的版权声明。本软件没有任何担保 包括没有适销性和某一专用目的下的适用性担保。 实操了解实现过程 步骤1安装开发工具gcc与make 步骤2tar解包释放源代码至指定目录 步骤3./configure 配置指定安装目录/功能模块等选项 步骤4make 编译生成可执行的二进制程序文件 步骤5make install安装将编译好的文件复制到安装目录 注意./configure、make、make install的步骤必须要在释放源代码指定的目录以相对目录方式(当前目录)下进行脚本运行、编译二进制可执行程序、安装 步骤1安装开gcc、make [rootsvr7 ~]# yum -y install gcc make 步骤2tar解包释放源代码至指定目录企业默认/usr/local目录为源代码存放目录 [rootsvr7 ~]# tar -xf /root/tools.tar.gz -C /      //释放压缩包到根目录 [rootsvr7 ~]# ls / 1.txt  boot  etc   lib    media  mydvd  proc  run   srv  tmp    usr bin    dev   home  lib64  mnt    opt    root  sbin  sys  tools  var [rootsvr7 ~]# ls /tools/ inotify-tools-3.13.tar.gz  other[rootsvr7 ~]# tar -xf /tools/inotify-tools-3.13.tar.gz -C /usr/local/  //释放指定目录 [rootsvr7 ~]# ls /usr/local/ bin  games    inotify-tools-3.13  lib64    sbin   src etc  include  lib                 libexec  share [rootsvr7 ~]# ls /usr/local/inotify-tools-3.13/ aclocal.m4    config.h.in   COPYING     libinotifytools  man      src AUTHORS       config.sub    depcomp     ltmain.sh        missing ChangeLog     configure     INSTALL     Makefile.am      NEWS config.guess  configure.ac  install-sh  Makefile.in      README 步骤3运行./configure 配置脚本指定安装目录 作用1检测当前系统是否安装gcc作用2指定安装位置与功能 [rootsvr7 ~]# cd /usr/local/inotify-tools-3.13/    //必须以当前目录方式运行脚本 [rootsvr7 inotify-tools-3.13]# ./configure --prefix/opt/myrpm //指定安装目录 checking for a BSD-compatible install... /usr/bin/install -c checking whether build environment is sane... yes ... 补充[--prefix指定安装目录]此步骤不产生相应的目录无需提前创建make创建 步骤4进行make 编译生成可执行的二进制程序文件放在内存中 [rootsvr7 inotify-tools-3.13]# make make  all-recursive make[1]: 进入目录“/usr/local/inotify-tools-3.13” Making all in libinotifytools make[2]: 进入目录“/usr/local/inotify-tools-3.13/libinotifytools” ... 补充make编译将高级语言转化成低级语言  步骤5make install 安装将编译好的文件复制到安装目录 [rootsvr7 inotify-tools-3.13]# make install Making install in libinotifytools make[1]: 进入目录“/usr/local/inotify-tools-3.13/libinotifytools” make[2]: 进入目录“/usr/local/inotify-tools-3.13” ... [rootsvr7 inotify-tools-3.13]# ls /opt/ myrpm  rh [rootsvr7 inotify-tools-3.13]# ls /opt/myrpm/ bin  include  lib  share [rootsvr7 inotify-tools-3.13]# ls /opt/myrpm/bin/ inotifywait  inotifywatch 常见报错未安装gcc开发工具 checking for gcc... no checking for cc... no checking for cl.exe... no configure: error: no acceptable C compiler found in $PATH See config.log for more details. 二、分步源码编译解析及示例 1下载及解包inotify-tools软件工具 使用tar解包建议释放到/usr/src/目录/usr/local标准位置/usr/src/软件名-版本号/ [rootsvr7 ~]# yum -y install gcc make [rootsvr7 ~]# tar -xf /root/tools.tar.gz -C /  [rootsvr7 ~]# tar -xf /tools/inotify-tools-3.13.tar.gz -C /usr/local/ 2配置./configure 执行源码目录下的configure脚本通过“./configure --help”可以查看帮助典型参数--prefix指定安装目录    //不生成目录make进行生成作用检测当前系统是否安装gcc、指定安装位置与功能  [rootsvr7 ~]# cd /usr/local/inotify-tools-3.13/ [rootsvr7 inotify-tools-3.13]# ./configure --prefix/opt/myrpm 3编译及安装make、make install 命令make    //编译命令make install    //安装 [rootsvr7 inotify-tools-3.13]# make make install 4结果验证 查看安装目录了解程序的使用方法运行软件包提供的程序/服务 [rootsvr7 inotify-tools-3.13]# ls /opt/myrpm/ bin  include  lib  share 三、Rsync基本使用 rsync 是一种快速、多功能的远程和本地文件复制工具。它可以在不同主机之间同步文件和目录无论是通过本地网络还是通过互联网。rsync 以其高效的数据传输和增量传输特性而闻名它只传输文件中发生变化的部分而不是整个文件从而大大减少了传输时间和带宽消耗。 官网http://rsync.samba.org/ 1、主要特性 增量传输rsync 会检查文件的变化只传输变化的部分而不是整个文件。高效传输通过使用压缩和校验和rsync 可以减少传输的数据量。支持多种传输模式可以通过 SSH、rsync 守护进程等方式进行传输。保留文件属性rsync 可以保留文件的权限、时间戳、软链接等属性。灵活的过滤规则可以使用 include 和 exclude 规则来控制哪些文件和目录需要同步。 复制与同步的差异 ① 复制cp完全拷贝源到目标 ② 同步rsync增量拷贝只传输变化过的数据 2、Rsync基本用法 格式rsync [选项...] 源目录 目标目录 例如要在本地同步两个目录 rsync -av /source/directory/ /destination/directory/要在两台远程主机之间同步文件可以使用 SSH rsync -avz /source/directory/ userremotehost:/destination/directory/常用选项 -a归档模式表示递归传输并保持文件属性相当于 -rlptgoD。-v详细模式显示传输过程中的详细信息。-z压缩文件数据在传输过程中。-P显示传输进度并在传输中断后可以继续传输。--delete删除目标目录中源目录没有的文件。-n测试同步过程不做实际修改 注意使用 [-av] 的前后顺序尽量不能颠倒否则无法进行[Tab]补全命令 本地目录同步目录后[ / ]只同步目录下的数据 格式rsync [选项...] 本地源目录 本地目标目录      //同步整个文件夹格式rsync [选项...] 本地源目录/ 本地目标目录     //只同步目录下的数据 补充rsync同步会对源目录进行检验第一次同步将源目标目录下的所有数据全部拷贝至目标目录第二次同步将源目录的变化数据拷贝到目标目录 注意不加选项 [--delete 只会针对源目录的数据即使目标目录有其它数据也不会操作 例如同步目录本身方式进行同步 [源目录] [rootsvr7 ~]# mkdir /mydir /todir [rootsvr7 ~]# cp /etc/passwd /mydir/ [rootsvr7 ~]# touch /mydir/1.txt [rootsvr7 ~]# mkdir /mydir/ABC [rootsvr7 ~]# ls /mydir/      //准备测试需要的目录、文件 1.txt  ABC  passwd [rootsvr7 ~]# rsync -av /mydir /todir    //不带[/]则同步目录本身 sending incremental file list mydir/ mydir/1.txt mydir/passwd mydir/ABC/ sent 2,552 bytes  received 66 bytes  5,236.00 bytes/sec total size is 2,330  speedup is 0.89[rootsvr7 ~]# ls /todir/ //查看目标目录同步内容 mydir 例如同步目录内容方式进行同步 [源目录/] [rootsvr7 ~]# rsync -av /mydir/ /todir     //带[/]则同步目录内容 sending incremental file list ./ 1.txt passwd ABC/ sent 2,540 bytes  received 65 bytes  5,210.00 bytes/sec total size is 2,330  speedup is 0.89[rootsvr7 ~]# ls /todir/ //查看目标目录同步内容 1.txt  ABC  mydir  passwd 例如增加文件进行同步 [rootsvr7 ~]# touch /mydir/2.txt      //源目录创建新文件 [rootsvr7 ~]# rsync -av /mydir/ /todir/ sending incremental file list ./ 2.txt      //只同步变化数据 sent 188 bytes  received 39 bytes  454.00 bytes/sec total size is 2,330  speedup is 10.26[rootsvr7 ~]# ls /todir/ //查看目标目录同步内容 1.txt  2.txt  ABC  mydir  passwd 例如修改文件内容进行同步 [rootsvr7 ~]# echo 123 /mydir/1.txt    //源目录文件发生数据修改 [rootsvr7 ~]# rsync -av /mydir/ /todir/ sending incremental file list 1.txt      //只同步变化数据 sent 193 bytes  received 36 bytes  458.00 bytes/sec total size is 2,334  speedup is 10.19[rootsvr7 ~]# ls /todir/ //查看目标目录同步内容 1.txt  2.txt  ABC  mydir  passwd 例如源目录与目标目录保持内容一致进行同步 [--delete] [rootsvr7 ~]# ls /mydir/     //源目录内容 1.txt  2.txt  ABC  passwd [rootsvr7 ~]# ls /todir/      //目标目录内容 1.txt  2.txt  ABC  mydir  passwd [rootsvr7 ~]# rsync -av --delete /mydir/ /todir/  //同步并删除目标目录多余的文档 sending incremental file list deleting mydir/ABC/ deleting mydir/passwd deleting mydir/1.txt deleting mydir/ sent 142 bytes  received 68 bytes  420.00 bytes/sec total size is 2,334  speedup is 11.11[rootsvr7 ~]# ls /mydir/ //查看源目录同步内容 1.txt  2.txt  ABC  passwd [rootsvr7 ~]# ls /todir/ //查看目标目录同步内容 1.txt  2.txt  ABC  passwd 例如测试同步过程不做实际修改 [-n] [rootsvr7 ~]# touch /mydir/c.txt [rootsvr7 ~]# rsync -n -av --delete /mydir/ /todir/ sending incremental file list ./ c.txt sent 166 bytes  received 23 bytes  378.00 bytes/sec total size is 2,334  speedup is 12.35 (DRY RUN)[rootsvr7 ~]# ls /todir/ //查看目标目录同步内容 1.txt  2.txt  ABC  passwd 四、RsyncSSH远程同步rsync负责同步ssh负责远程 用法及服务端要求 开启sshd服务并提供授权的用户、密码 列出SSH服务端资源 命令rsync userhost:远程目录/ 1、与远程的SSH目录保持同步 语法下行rsync [...] userhost:远程目录 本地目录语法上行rsync [...] 本地目录 userhost:远程目录 注意该方式远程同步需要密码验证 例如1远程同步上行 主机1 [rootsvr7 ~]# rsync -av --delete /mydir/ root192.168.4.207:/opt root192.168.4.207s password: sending incremental file list deleting rh/ ./ 1.txt 2.txt passwd ABC/sent 2,615 bytes  received 87 bytes  163.76 bytes/sec total size is 2,334  speedup is 0.86 主机2 [rootpc207 ~]# ls /opt/ 1.txt  2.txt  ABC  passwd 例如2远程同步上行增加文件 主机1 [rootsvr7 ~]# touch /mydir/c.txt [rootsvr7 ~]# rsync -av --delete /mydir/ root192.168.4.207:/opt root192.168.4.207s password: sending incremental file list ./ c.txtsent 211 bytes  received 39 bytes  17.24 bytes/sec total size is 2,334  speedup is 9.34 主机2 [rootpc207 ~]# ls /opt/ 1.txt  2.txt  ABC  c.txt  passwd 例如3远程同步下载 主机2 [rootpc207 ~]# echo 123 /mnt/abc.txt 主机1 [rootsvr7 ~]# rsync -av --delete root192.168.4.207:/mnt/ /opt/ root192.168.4.207s password: receiving incremental file list deleting rh/ deleting myrpm/share/man/man1/inotifywatch.1 ... ./ abc.txtsent 46 bytes  received 116 bytes  12.00 bytes/sec total size is 4  speedup is 0.02 [rootsvr7 ~]# ls /opt/ abc.txt [rootsvr7 ~]# cat /opt/abc.txt 123 注意进行远程同步下载时若加 [-delete] 选项会将/opt目录下的内容与/mnt目录内容保持一致所以会对原来在/opt目录下的所有文件全部删除 2、实现SSH无密码验证公钥与私钥 部署公钥与私钥配对具有唯一性且每次生成公私钥不一样RSA加密算法生成 ① 公钥public锁)对应生成文件id_rsa.pub(公钥)② 私钥private钥匙对应生成文件id_rsa(私钥) 生成公私钥命令ssh-keygen传递公钥命令ssh-copy-id userhost    //传递目标主机公私钥存放目录/root/.ssh/目标主机存放公钥文件/root/.ssh/authorized_keys    //每一行记录代表一条公钥 补充公钥和私钥由远程管理的主机生成而被远程管理的主机负责接受公钥 步骤1生成公钥与私钥 [rootsvr7 ~]# ssh-keygen    //生成公钥与私钥回车即可 Generating public/private rsa key pair. Enter file in which to save the key (/root/.ssh/id_rsa): 公私钥保存目录 Enter passphrase (empty for no passphrase):   //公私钥的保险柜密码不输入为空 Enter same passphrase again:     //确认密码为空 Your identification has been saved in /root/.ssh/id_rsa. Your public key has been saved in /root/.ssh/id_rsa.pub. The key fingerprint is: SHA256:fnqPfuarIHeeLqDRE6heKLITGSjd1cXwjZ8iWd/hkI rootsvr7.tedu.cn The keys randomart image is: ---[RSA 2048]---- |                 | |                 | |     . o . .     | |    . . B E      | |.  o . oSB o .   | | * o .. o o o  | |.X o o..o. o   | | o .o.*.oo    | | o . .  .B*.   | ----[SHA256]----- [rootsvr7 ~]# ls /root/.ssh/    //查看公私钥存放目录 id_rsa  id_rsa.pub  known_hosts 解释id_rsa(私钥)、id_rsa.pub(公钥)、known_hosts(记录曾经远程管理过的机器) 补充在已生成公私钥的情况下再次对同一主机进行生成则将原有的公私钥对进行覆盖 补充本机可以把公钥对不同的目标主机进行提供但私钥无法提供给目标主机其次不同的目标主机都可以接收本机的公钥当目标主机接受本机的公钥后本机则可以进行SSH无密码访问目标主机 步骤2将公钥传递给主机2相当于复制 [rootsvr7 ~]# ssh-copy-id root192.168.4.207    //传递公钥给主机2 /usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: /root/.ssh/id_rsa.pub /usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed /usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys root192.168.4.207s password:Number of key(s) added: 1Now try logging into the machine, with:   ssh root192.168.4.207 and check to make sure that only the key(s) you wanted were added. 步骤3验证SSH无密码验证 主机2 [rootpc207 ~]# ls /root/.ssh/     //查看目标主机的存放公钥文件 authorized_keys //传递后的公钥文件改名内容一样 主机1 [rootsvr7 ~]# ssh 192.168.4.207 Last login: Mon Mar 22 08:38:47 2021 from 192.168.4.254   //无需密码认证 [rootpc207 ~]# exit[rootsvr7 ~]# rsync -av --delete /mydir/ root192.168.4.207:/opt  //无需密码验证 sending incremental file listsent 165 bytes  received 13 bytes  15.48 bytes/sec total size is 2,334  speedup is 13.11 补充生产环境下如果发现/root/.ssh/目录下有authorized_keys文件说明本机有无密码验证删除authorized_keys或dd某一行记录 五、部署监控环境 同步的实时性 ① 按照固定周期定期同步 时间间隔不好固定同步不及时或资源浪费实时性较差 ② Linux内核的inotify机制 提供事件响应式的文件系统通知机制安装inotify-tools控制工具可调用此机制实现监控 1安装inotify-tools工具 下载地址http://download.sf.net/inotify-tools/标准的源码、编译安装即可/usr/local/inotify-tools-3.13/bin/目录下 2inotifywait监控基本用法inotifywait报告 格式inotifywait [选项] 目标文件夹 常用命令选项 [-m]   持续监控捕获一个事件后不退出[-r]   递归监控、包括子目录及文件捕获一个事件后退出[-q]   减少屏幕输出信息[-e]   指定监视的modfiy、move、create、delete、attrib等事件类别不加则所有事件都监控 3持续跟踪指定文件夹的变化 要求1目标文件夹/opt要求2当文档出现监视的事件时会立即给出相应提示 例如 [rootsvr7 ~]# mkdir /opt/4.txt [rootsvr7 ~]# /opt/myrpm/bin/inotifywait -rq /opt/ //捕获一个事件则退出 /opt/ CREATE,ISDIR 4.txt 例如 [rootsvr7 ~]# mkdir /opt/4.txt [rootsvr7 ~]# mkdir /opt/5.txt [rootsvr7 ~]# /opt/myrpm/bin/inotifywait -mrq /opt/ /opt/ CREATE,ISDIR 4.txt /opt/ OPEN,ISDIR 4.txt /opt/ CLOSE_NOWRITE,CLOSE,ISDIR 4.txt /opt/ CREATE,ISDIR 5.txt /opt/ OPEN,ISDIR 5.txt /opt/ CLOSE_NOWRITE,CLOSE,ISDIR 5.txt 六、配置实时同步 1inotify与rsync的结合 基本思路利用while循环来反复检查单次监控结果书写shell脚本 脚本可以运行一个文件实现某种功能例如useradd zhangsan 死循环使用while循环条件成立则重复执行 格式 while  条件      do           重复执行的操作      Done 注释只要条件成立则执行do和done之间的“重复执行的操作” 2编写同步脚本 [rootsvr7 ~]# vim /etc/rsync.sh    //编写脚本 while /opt/myrpm/bin/inotifywait -rqq /mydir dorsync -a --delete /mydir/ root192.168.4.207:/opt done [rootsvr7 ~]# ls -l /etc/rsync.sh -rw-r--r--. 1 root root 105 3月  22 16:01 /etc/rsync.sh [rootsvr7 ~]# chmod ax /etc/rsync.sh    //赋予执行权限 [rootsvr7 ~]# ls -l /etc/rsync.sh -rwxr-xr-x. 1 root root 105 3月  22 16:01 /etc/rsync.sh [rootsvr7 ~]# /etc/rsync.sh      //运行脚本程序并放入后台 [1] 2943 [rootsvr7 ~]# jobs -l [1]  2943 运行中               /etc/rsync.sh [rootsvr7 ~]# kill 2943      //停止脚本 3验证实时同步效果 七、数据库服务基础数据库管理系统 DB数据库一批数据的集合主流的数据库多用来存放关系型表格数据 关系型数据以二维表格记录大量实体的属性信息 DBMS数据库管理系统用来操作和管理 Mariadb的基本使用 1.Linux系统的管理指令不能使用 2.所有的数据库系统指令都必须以[ ; ]结尾 3.数据库系统的指令大部分不支持tab补全 1、部署Maridb数据库服务器 RHEL7中的MariDB软件包 - 提供服务端有关的系统程序mariadb-server - 提供客户端及管理工具mariadb 例如 [rootsvr7 ~]# yum -y install mariadb-server mariadb    //安装软件包 [rootsvr7 ~]# systemctl restart mariadb      //重启服务 [rootsvr7 ~]# netstat -anptu | grep :3306 tcp        0      0 0.0.0.0:3306            0.0.0.0:*               LISTEN      5955/mysqld      2、访问Mariadb数据库 使用mysql命令登录交互界面实现数据库管理操作 格式mysql [-u用户名] [-p[密码]] 例如 [rootsvr7 ~]# mysql -uroot     //进入数据库系统默认免密码 MariaDB [(none)] MariaDB [(none)] show databases;    //列出数据库 -------------------- | Database           | -------------------- | information_schema | | mysql              | | performance_schema | | test               | -------------------- 4 rows in set (0.00 sec) MariaDB [(none)] quit Bye 3、数据库的增删查 MariaDB [(none)] 交互命令 - [ show databases; ]   列出数据库 - [ create database 数据库名; ]   创建数据库 - [ drop database 数据库名; ]   删除数据库 - [ use 数据库名; ]   使用/选择数据库 - [ show tables; ]   列出库里有哪些表 - exit 和 quit  都能退出 例如创建数据库数据库名为nsd01 [rootsvr7 ~]# mysql -uroot MariaDB [(none)] create database nsd01;     //创建数据库 Query OK, 1 row affected (0.00 sec) MariaDB [(none)] show databases;     //列出数据库 -------------------- | Database           | -------------------- | information_schema | | mysql              | | nsd01              | | performance_schema | | test               | -------------------- 5 rows in set (0.00 sec) MariaDB [(none)] drop database nsd01;    //删除数据库 Query OK, 0 rows affected (0.00 sec) 例如切换到mysql数据库并查看数据库表格 [rootsvr7 ~]# mysql MariaDB [(none)] use mysql;     //切换到mysql数据库 Reading table information for completion of table and column names You can turn off this feature to get a quicker startup with -ADatabase changed MariaDB [mysql] show tables;     //查看当前库中所有表格 --------------------------- | Tables_in_mysql           | --------------------------- | columns_priv              | | db                        | | event                     | | func                      | | general_log               | | help_category             | | help_keyword              | | help_relation             | | help_topic                | | host                      | | ndb_binlog_index          | | plugin                    | | proc                      | | procs_priv                | | proxies_priv              | | servers                   | | slow_log                  | | tables_priv               | | time_zone                 | | time_zone_leap_second     | | time_zone_name            | | time_zone_transition      | | time_zone_transition_type | | user                      | --------------------------- 24 rows in set (0.00 sec)MariaDB [mysql] use test;     //切换到test数据库 Database changed MariaDB [test] exit     //退出数据库管理系统 Bye 4、为数据库管理系统的管理员设置密码 命令mysqladmin [-u用户名] password 新密码     //[-u]指的用户为数据库管理员 ① Linux系统管理员: 对于Linux系统有最高权限名字为root能够登陆Linux系统的用户信息用/etc/passwd进行储存② 数据库系统管理员对于数据库系统有最高权限名字为root能够登陆数据系统的用户信息用mysql库中user表进行储存 补充由于系统当前为root用户进入数据库管理系统时默认会用数据库管理员身份root登录无需密码验证 例如设置数据库管理系统的管理员密码交互式登录 [rootsvr7 ~]# mysqladmin -uroot password 123456 //设置管理员密码 [rootsvr7 ~]# mysql -u root -p     //交互式登录 Enter password:        //输入密码 Welcome to the MariaDB monitor.  Commands end with ; or \g. Your MariaDB connection id is 5 ... MariaDB [(none)] exit Bye 例如非交互式登录 [rootsvr7 ~]# mysql -uroot -p123456   //非交互式登录 Welcome to the MariaDB monitor.  Commands end with ; or \g. Your MariaDB connection id is 6 ... MariaDB [(none)] exit Bye 5、已知旧密码的情况下修改新密码 命令mysqladmin [-u用户名] [-p[旧密码]] 例如 [rootsvr7 ~]# mysqladmin -uroot -p123456 password 321 //修改密码 [rootsvr7 ~]# mysql -u root -p321 Welcome to the MariaDB monitor.  Commands end with ; or \g. Your MariaDB connection id is 8 ... MariaDB [(none)] exit Bye 常见报错因为数据库管理员设置密码在输入密码错误及没有输入密码情况下会有报错 [rootsvr7 ~]# mysql ERROR 1045 (28000): Access denied for user rootlocalhost (using password: NO) [rootsvr7 ~]# mysql -u root -p65432 ERROR 1045 (28000): Access denied for user rootlocalhost (using password: YES) 6、恢复数据到数据库中    步骤1创建nsd20数据库 [rootsvr7 ~]# mysql -u root -p321 Welcome to the MariaDB monitor.  Commands end with ; or \g. Your MariaDB connection id is 12 ... MariaDB [(none)] create database nsd20; Query OK, 1 row affected (0.00 sec) MariaDB [(none)] show databases; -------------------- | Database           | -------------------- | information_schema | | mysql              | | nsd20              | | performance_schema | | test               | -------------------- 5 rows in set (0.00 sec) 步骤2真机拷贝users.sql文件到主机1的/root目录下 [rootlocalhost 桌面]# scp /root/users.sql root192.168.4.7:/root root192.168.4.7s password: users.sql                                     100% 2634     2.5MB/s   00:00 步骤3将users.sql数据库文件导入nsd20数据库中 [rootsvr7 ~]# mysql -u root -p321 nsd20 /root/users.sql  //将数据导入数据库 [rootsvr7 ~]# mysql -u root -p321 Welcome to the MariaDB monitor.  Commands end with ; or \g. Your MariaDB connection id is 15 ... MariaDB [(none)] use nsd20; Database changed MariaDB [nsd20] show tables; ----------------- | Tables_in_nsd20 | ----------------- | base            | | location        | ----------------- 2 rows in set (0.00 sec) 7、表记录基本操作 基本操作增(insert)、删(delete)、改(update)、查(select) - 表字段、表记录 MariaDB [(none)] 交互指令 - 格式select * from [数据库.]表名; - 格式select 字段1,字段2... from [数据库.]表名; - 格式select ... Where 字段1’值’ and|or 字段2’值’ — 查(select) 格式: select 表字段,表字段... from库名.表名; 例如 [rootsvr7 ~]# mysql -uroot MariaDB [(none)] use nsd20; MariaDB [nsd20] show tables; ----------------- | Tables_in_nsd20 | ----------------- | base            | | location        | ----------------- 2 rows in set (0.00 sec) MariaDB [nsd20] select * from base;     //查看base所有表字段内容 --------------------------- | id   | name    | password   | --------------------------- |    1 | Tom     | 123        | |    2 | Barbara | 456        | |    3 | James   | solicitous | |    4 | Smith   | tarena     | |    5 | Barbara | pwd123     | --------------------------- 5 rows in set (0.00 sec)MariaDB [nsd20] select * from location;    //查看location所有表字段内容 ----------------- | id   | city      | ----------------- |    1 | Beijing   | |    2 | Paris     | |    3 | Sunnyvale | |    4 | Berlin    | |    5 | Sunnyvale | ----------------- 5 rows in set (0.00 sec) 例如在user库中查看nsd20数据库的base表内容 MariaDB [nsd20] use test; MariaDB [test] select * from nsd20.base; --------------------------- | id   | name    | password   | --------------------------- |    1 | Tom     | 123        | |    2 | Barbara | 456        | |    3 | James   | solicitous | |    4 | Smith   | tarena     | |    5 | Barbara | pwd123     | --------------------------- 5 rows in set (0.00 sec) 例如根据字段查找 MariaDB [test] use nsd20; MariaDB [nsd20] select id,name from base; --------------- | id   | name    | --------------- |    1 | Tom     | |    2 | Barbara | |    3 | James   | |    4 | Smith   | |    5 | Barbara | --------------- 5 rows in set (0.00 sec) 例如根据条件查找 MariaDB [nsd20] select * from base where password456; ------------------------- | id   | name    | password | ------------------------- |    2 | Barbara | 456      | ------------------------- 1 row in set (0.00 sec)MariaDB [nsd20] select * from base where id4; ----------------------- | id   | name  | password | ----------------------- |    4 | Smith | tarena   | ----------------------- 1 row in set (0.00 sec)MariaDB [nsd20] select * from base where id4 and password123; Empty set (0.00 sec)MariaDB [nsd20] select * from base where id4 or password123; ----------------------- | id   | name  | password | ----------------------- |    1 | Tom   | 123      | |    4 | Smith | tarena   | ----------------------- — 增(insert) 格式insert 表名 values (‘值’,‘值’,‘值’); 例如增加记录信息 MariaDB [nsd20] insert base values(10,dc,789); Query OK, 1 row affected (0.04 sec)MariaDB [nsd20] insert base values(11,aj,333); Query OK, 1 row affected (0.01 sec)MariaDB [nsd20] select * from base; --------------------------- | id   | name    | password   | --------------------------- |    1 | Tom     | 123        | |    2 | Barbara | 456        | |    3 | James   | solicitous | |    4 | Smith   | tarena     | |    5 | Barbara | pwd123     | |   10 | dc      | 789        | |   11 | aj      | 333        | --------------------------- 7 rows in set (0.00 sec) — 改update 格式update 表名 set 表字段’新值’ where 表字段’值’ 例如修改记录信息 MariaDB [nsd20] update base set password888 where id11; Query OK, 1 row affected (0.02 sec) Rows matched: 1  Changed: 1  Warnings: 0MariaDB [nsd20] update base set password250 where namedc; Query OK, 1 row affected (0.01 sec) Rows matched: 1  Changed: 1  Warnings: 0MariaDB [nsd20] select * from base; --------------------------- | id   | name    | password   | --------------------------- |    1 | Tom     | 123        | |    2 | Barbara | 456        | |    3 | James   | solicitous | |    4 | Smith   | tarena     | |    5 | Barbara | pwd123     | |   10 | dc      | 250        | |   11 | aj      | 888        | --------------------------- 7 rows in set (0.00 sec) — 删delete 例如根据条件进行删除 MariaDB [nsd20] delete from base where id10; Query OK, 1 row affected (0.02 sec)MariaDB [nsd20] use test; MariaDB [test] delete from nsd20.base where id11; Query OK, 1 row affected (0.02 sec)MariaDB [test] select * from nsd20.base; --------------------------- | id   | name    | password   | --------------------------- |    1 | Tom     | 123        | |    2 | Barbara | 456        | |    3 | James   | solicitous | |    4 | Smith   | tarena     | |    5 | Barbara | pwd123     | --------------------------- 5 rows in set (0.00 sec) 扩展rsync常用选项 小结 本篇章节为 【第一阶段】SERVICES-DAY5 的学习笔记可以初步了解到 源码编译安装、rsync同步操作、inotify实时同步、数据库服务基础。 Tip毕竟两个人的智慧大于一个人的智慧如果你不理解本章节的内容或需要相关笔记、视频可私信小安请不要害羞和回避可以向他人请教花点时间直到你真正的理解
http://www.dnsts.com.cn/news/130219.html

相关文章:

  • 做网站推广排名向客户介绍网站建设的话术
  • php网站下载文件怎么做网站不备案可以访问吗
  • 网站多大在网站做专题
  • 长沙网站设计建设湖南建设厅特种工查询
  • 余姚网站推广策划案品牌宣传型网站建设方案
  • 做58同城网站需要多少钱如何做网站店铺的模板
  • 广州建站模板搭建建筑网站免费
  • 网站建设 运营字体设计软件 免费
  • 兰州网站运营诊断深圳网站制作公司哪儿济南兴田德润优惠吗
  • 网站会员管理大庆网站开发制作
  • icann 域名注册网站wordpress 简历 插件
  • 网站区域名是什么网站不备案支付宝接口
  • 免费html网页模板网站接单赚钱平台
  • 货物公司网站建设方案网站备案 做网站时就需要吗
  • 宁波建设协会网站我想自己在网站上发文章 怎样做
  • 郑州数码网站建设服务公司郑州一凡网站建设
  • 企业网站找谁做好营销组合策略
  • 网站后台验证码出不来沈阳营销型网站建设
  • 四川省化工建设有限公司网站讯杰网站建设
  • 哈尔滨市住房与城乡建设局网站重庆怎么做网站?
  • 网站 做百度推广有没有效果怎么样设计用的报价网站
  • 新开传奇网站发布网外贸网站建设网站开发
  • 网站建设教程l一站式做网站哪家强
  • 有什么网站做统计图的网站技能培训
  • php网站开发专业是做什么的网站建设仟首先金手指14
  • 网站asp设计作品wordpress调用评论框
  • 参考消息官方网站阅读视频聚合网站怎么做不侵权
  • 温州做网站哪里好手游app平台推广微信xiala5
  • 辽宁住房和城乡建设部网站天涯重庆论坛
  • 高校专业建设网站如何维护企业电子商务网站建设