搜索词>>GT 1030 耗时0.0060
  • GT 1030显卡测评

    一、GT 1030 显卡怎么样      GT 1030显卡抉择,GT 1030是又一款入门级显卡一、GT 1030 显卡怎么样      GT 1030显卡抉择,GT 1030是又一款入门级显卡。其性能肯定是同辈中垫底的,但是在入门显卡的排行里可算得上性能排行老大了。还记得前几代的GT 710/GT 730 甚至古老的GT 210吗?它们如今还占领了OEM大半江山呢但是这些入门显卡性能统统不是GT 1030的对手。    那么那些人会选择它呢?首先肯定不会是大型单机或大型网游的爱好者,更不会是一些发烧友。首先我们先看看下面的一些测评对比吧​1030二、GT 1030 常见游戏测评2.1 GT 1030 游戏:《古墓丽影10:崛起》1080分辨率测试​《古墓丽影10:崛起》1080分辨率测试2.2 GT 1030 游戏:《战锤 全面战争》1080分辨率测试​《战锤 全面战争》1080分辨率测试2.3 GT 1030 游戏:英雄联盟(LOL)​英雄联盟(LOL)2.4 GT 1030 游戏:守望者先锋​守望者先锋三、3D Mark跑分​3D Mark跑分四、功耗及综合性能4.1 功耗对比​功耗对比4.2 综合性能评估​综合性能评估五、综合评价 1.性能。GT 1030已经完虐GT 730和Intel所有集显,完美取代了上一代入门显卡GT 730的位置。成为低端入门显卡主流选择。2.功耗。GT 1030满载不过100W,自身发热量低,被动散热即可。是HTPC用户的主流选择之一。3.接口。提供HDMI高清输出接口4.价格。购入价格需控制在450左右,否则性价比不高了。综述:入门性能强悍,4K支持,静音(被动散热)功耗低。最后注意:GT 1030有两个版本,切记只能买GDDR5显存版
  • artDialog v7使用说明及API文档

    artDialog v7 使用说明及API文档,artDialog ,artDialog具有bootstrap风格的弹窗组件<h1>artDialog具有bootstrap风格的弹窗组件</h1> <img alt="artdialog1" class="img-thumbnail" src="/assist/images/blog/859e118e483b47189690b6836e9d8416.png" /><br /> <img alt="artdialog2" class="img-thumbnail" src="/assist/images/blog/02fcbce67bc649a2b475ede25c9a3fb6.png" /><br /> <img alt="artdialog3" class="img-thumbnail" src="/assist/images/blog/c31c53851106483f908c0eb7394f4eab.png" /><br /> <img alt="artdialog4" class="img-thumbnail" src="/assist/images/blog/1875d350bcf54980b6206de142705dec.png" /><br /> <img alt="artdialog5" class="img-thumbnail" src="/assist/images/blog/b16cadd97d0448b79ac83ee18ac45630.png" /><br /> <img alt="artdialog6" class="img-thumbnail" src="/assist/images/blog/c267c1d7647340b7851a79c9514ff708.png" /><br />   <p>首页 > 文档与示例</p> <p>artDialog —— 经典、优雅的网页对话框控件。</p> <ol> <li>支持普通与 12 方向气泡状对话框</li> <li>完善的焦点处理,自动焦点附加与回退</li> <li>支持 ARIA 标准</li> <li>面向未来:基于 HTML5 Dialog 的 API</li> <li>支持标准与模态对话框</li> <li>丰富且友好的编程接口</li> <li>能自适应内容尺寸</li> </ol> <h2>引入 artDialog</h2> <h3>1.直接引用</h3> <pre> <code class="language-javascript"><script src="lib/jquery-1.10.2.js"></script> <script src="dist/dialog.js"></script></code></pre> <h3>2.作为 Webpack、RequireJS 或 SeaJS 的模块引入</h3> <p>使用 Npm 安装 <code>art-dialog</code></p> <pre> <code>npm install --save-dev art-dialog </code></pre> <pre> <code>var dialog = require('art-dialog');</code></pre> <p>**注意:**内部依赖全局模块<code>require('jquery')</code>,请注意全局模块配置是否正确</p> <ul> <li>如果需要支持 iframe 内容与拖拽,请引用加强版 dialog-plus.js</li> <li>jquery 最低要求版本为<code>1.7+</code></li> </ul> <h2>快速参考</h2> <h3>普通对话框</h3> <pre> <code class="language-javascript">var d = dialog({ title: '欢迎', content: '欢迎使用 artDialog 对话框组件!' }); d.show(); </code></pre> 运行 <h3>模态对话框</h3> <pre> <code class="language-javascript">var d = dialog({ title: 'message', content: '<input autofocus />' }); d.showModal(); </code></pre> 运行 <h3>气泡浮层</h3> <pre> <code class="language-javascript">var d = dialog({ content: 'Hello World!', quickClose: true// 点击空白处快速关闭 }); d.show(document.getElementById('quickref-bubble')); </code></pre> 运行 <p>12 个方向定位演示</p> <h3>添加按钮</h3> <p>1.确定与取消按钮:</p> <pre> <code class="language-javascript">var d = dialog({ title: '提示', content: '按钮回调函数返回 false 则不许关闭', okValue: '确定', ok: function () { this.title('提交中…'); return false; }, cancelValue: '取消', cancel: function () {} }); d.show(); </code></pre> 运行 <p>2.指定更多按钮:</p> <p>请参考 <code>button</code> 方法或参数。</p> <h3>控制对话框关闭</h3> <pre> <code class="language-javascript">var d = dialog({ content: '对话框将在两秒内关闭' }); d.show(); setTimeout(function () { d.close().remove(); }, 2000); </code></pre> 运行 <h3>给对话框左下角添加复选框</h3> <pre> <code class="language-javascript">var d = dialog({ title: '欢迎', content: '欢迎使用 artDialog 对话框组件!', ok: function () {}, statusbar: '<label><input type="checkbox">不再提醒</label>' }); d.show(); </code></pre> 运行 <h3>点按钮不关闭对话框</h3> <p>按钮事件返回 false 则不会触发关闭。</p> <pre> <code class="language-javascript">var d = dialog({ title: '欢迎', content: '欢迎使用 artDialog 对话框组件!', ok: function () { var that = this; this.title('正在提交..'); setTimeout(function () { that.close().remove(); }, 2000); return false; }, cancel: function () { alert('不许关闭'); return false; } }); d.show(); </code></pre> 运行 <h3>不显示关闭按钮</h3> <pre> <code class="language-javascript">var d = dialog({ title: '欢迎', content: '欢迎使用 artDialog 对话框组件!', cancel: false, ok: function () {} }); d.show(); </code></pre> 运行 <h3>创建 iframe 内容</h3> <p>artDialog 提供了一个增强版用来支持复杂的 iframe 套嵌的页面,可以在顶层页面创建一个可供 iframe 访问的对话框创建方法,例如:</p> <pre> <code class="language-javascript">require(['art-dialog/dist/dialog-plus'], function (dialog) { window.dialog = dialog; });</code></pre> <p>然后子页面就可以通过<code>top.dialog</code>控制对话框了。</p> <p>打开示例页面</p> <p>小提示:增强版的选项比标准版多了<code>url</code>、<code>oniframeload</code>这几个字段。</p> <h2>方法</h2> <p>若无特别说明,方法均支持链式调用。</p> <h3>show([anchor])</h3> <p>显示对话框。</p> <p>默认居中显示,支持传入元素节点或者事件对象。</p> <ul> <li>参数类型为<code>HTMLElement</code>:可吸附到元素上,同时对话框将呈现气泡样式。</li> <li>参数类型为<code>Event Object</code>:根据<code>event.pageX</code>与<code>event.pageY</code>定位。</li> </ul> <h4>示例</h4> <pre> <code class="language-javascript">var d = dialog(); d.content('hello world'); d.show(document.getElementById('api-show')); </code></pre> 运行 <pre> <code class="language-javascript">var d = dialog({ id: 'api-show-dialog', quickClose: true, content: '右键菜单' }); $(document).on('contextmenu', function (event) { d.show(event); return d.destroyed; }); </code></pre> 运行 <h3>showModal([anchor])</h3> <p>显示一个模态对话框。</p> <p>其余特性与参数可参见<code>show([anchor])</code>方法。</p> <h4>示例</h4> <pre> <code class="language-javascript">var d = dialog({ title: 'message', content: '<input autofocus />' }); d.showModal(); </code></pre> 运行 <h3>close([result])</h3> <p>关闭(隐藏)对话框。</p> <p>可接收一个返回值,可以参见 returnValue。</p> <p><strong>注意</strong>:<code>close()</code>方法只隐藏对话框,不会在 DOM 中删除,删除请使用<code>remove()</code>方法。</p> <h3>remove()</h3> <p>销毁对话框。</p> <p><strong>注意</strong>:不同于<code>close([result])</code>方法,<code>remove()</code>方法会从 DOM 中移出对话框相关节点,销毁后的对话框无法再次使用。</p> <p>对话框按钮点击后默认会依次触发 <code>close()</code>、<code>remove()</code> 方法。如果想手动控制对话框关闭可以如下操作:</p> <pre> <code class="language-javascript">var d = dialog(); // [..] d.close().remove(); </code></pre> 运行 <h3>content(html)</h3> <p>写入对话框内容。</p> <p><code>html</code>参数支持<code>String</code>、<code>HTMLElement</code>类型。</p> <h4>示例</h4> <p>传入字符串:</p> <pre> <code class="language-javascript">var d = dialog(); d.content('hello world'); d.show(); </code></pre> 运行 <p>传入元素节点:</p> <pre> <code class="language-javascript">var elem = document.getElementById('test'); dialog({ content: elem, id: 'EF893L' }).show(); </code></pre> <p>v6.0.4 更新:隐藏元素将会自动显示,并且对话框卸载的时候会放回到<code>body</code>中</p> <h3>title(text)</h3> <p> </p> <p>写入对话框标题。</p> <h4>示例</h4> <pre> <code class="language-javascript">var d = dialog(); d.title('hello world'); d.show(); </code></pre> 运行 <h3>width(value)</h3> <p>设置对话框宽度。</p> <h3>示例</h3> <pre> <code class="language-javascript">dialog({ content: 'hello world' }) .width(320) .show(); </code></pre> 运行 <h3>height(value)</h3> <p> </p> <p>设置对话框高度。</p> <h3>示例</h3> <pre> <code class="language-javascript">dialog({ content: 'hello world' }) .height(320) .show(); </code></pre> 运行 <h3>reset()</h3> <p> </p> <p>手动刷新对话框位置。</p> <p>通常动态改变了内容尺寸后需要刷新对话框位置。</p> <h3>button(args)</h3> <p> </p> <p>自定义按钮。</p> <p>参数请参考 选项<code>button</code>;同时支持传入 HTML 字符串填充按钮区域。</p> <h3>focus()</h3> <p> </p> <p>聚焦对话框(置顶)。</p> <h3>blur()</h3> <p> </p> <p>让对话框失去焦点。</p> <h3>addEventListener(type, callback)</h3> <p> </p> <p>添加事件。</p> <p>支持的事件有:<code>show</code>、<code>close</code>、<code>beforeremove</code>、<code>remove</code>、<code>reset</code>、<code>focus</code>、<code>blur</code></p> <h3>removeEventListener(type, callback)</h3> <p> </p> <p>删除事件。</p> <h3>dialog.get(id)</h3> <p> </p> <p>根据获取打开的对话框实例。</p> <p><strong>注意</strong>:这是一个静态方法。</p> <h3>dialog.getCurrent()</h3> <p> </p> <p>获取当前(置顶)对话框实例。</p> <p><strong>注意</strong>:这是一个静态方法。</p> <h2>配置参数</h2> <p> </p> <h3>content</h3> <p> </p> <p>设置消息内容。</p> <h4>类型</h4> <p>String, HTMLElement</p> <h4>示例</h4> <p>传入字符串:</p> <pre> <code class="language-javascript">dialog({ content: 'hello world!' }).show(); </code></pre> 运行 <p>传入元素节点:</p> <pre> <code class="language-javascript">var elem = document.getElementById('test'); dialog({ content: elem, id: 'EF893L' }).show(); </code></pre> <h3>title</h3> <p> </p> <p>标题内容。</p> <h4>类型</h4> <p>String</p> <h4>示例</h4> <pre> <code class="language-javascript">dialog({ title: 'hello world!' }).show(); </code></pre> 运行 <h3>statusbar</h3> <p> </p> <p>状态栏区域 HTML 代码。</p> <p>可以实现类似“不再提示”的复选框。<strong>注意</strong>:必须有按钮才会显示。</p> <h4>类型</h4> <p>String</p> <h4>示例</h4> <pre> <code class="language-javascript">var d = dialog({ title: '欢迎', content: '欢迎使用 artDialog 对话框组件!', ok: function () {}, statusbar: '<label><input type="checkbox">不再提醒</label>' }); d.show(); </code></pre> 运行 <h3>ok</h3> <p> </p> <p>确定按钮。</p> <p>回调函数<code>this</code>指向<code>dialog</code>对象,执行完毕默认关闭对话框,若返回 false 则阻止关闭。</p> <h4>类型</h4> <p>Function</p> <h4>示例</h4> <pre> <code class="language-javascript">dialog({ ok: function () { this .title('消息') .content('hello world!') .width(130); return false; } }).show(); </code></pre> 运行 <h3>okValue</h3> <p> </p> <p>(默认值: <code>"ok"</code>) 确定按钮文本。</p> <h4>类型</h4> <p>String</p> <h4>示例</h4> <pre> <code class="language-javascript">dialog({ okValue: '猛击我', ok: function () { this.content('hello world!'); return false; } }).show(); </code></pre> 运行 <h3>cancel</h3> <p> </p> <p>取消按钮。</p> <p>取消按钮也等同于标题栏的关闭按钮,若值为<code>false</code>则不显示关闭按钮。回调函数<code>this</code>指向<code>dialog</code>对象,执行完毕默认关闭对话框,若返回<code>false</code>则阻止关闭。</p> <h4>类型</h4> <p>Function, Boolean</p> <h4>示例</h4> <pre> <code class="language-javascript">dialog({ title: '消息', ok: function () {}, cancel: function () { alert('取消'); } }).show(); </code></pre> 运行 <pre> <code class="language-javascript">dialog({ title: '消息', content: '不显示关闭按钮', ok: function () {}, cancel: false }).show(); </code></pre> 运行 <h3>cancelValue</h3> <p> </p> <p>(默认值: <code>"cancel"</code>) 取消按钮文本。</p> <h4>类型</h4> <p>String</p> <h4>示例</h4> <pre> <code class="language-javascript">dialog({ cancelValue: '取消我', cancel: function () { alert('关闭'); } }).show(); </code></pre> 运行 <h3>cancelDisplay</h3> <p> </p> <p>(默认值: <code>true</code>) 是否显示取消按钮。</p> <h4>类型</h4> <p>Boolean</p> <h4>示例</h4> <pre> <code class="language-javascript">dialog({ title: '提示', content: '这是一个禁止关闭的对话框,并且没有取消按钮', cancel: function () { alert('禁止关闭'); return false; }, cancelDisplay: false }).show(); </code></pre> 运行 <h3>button</h3> <p> </p> <p>自定义按钮组。</p> <h4>类型</h4> <p>Array</p> <h4>选项</h4> <table class="table table-bordered table-hover"> <thead> <tr> <th>名称</th> <th>类型</th> <th>描述</th> </tr> </thead> <tbody> <tr> <td>value</td> <td>String</td> <td>按钮显示文本</td> </tr> <tr> <td>callback</td> <td>Function</td> <td>(可选) 回调函数<code>this</code>指向<code>dialog</code>对象,执行完毕默认关闭与销毁对话框(依次执行<code>close()</code>与<code>remove()</code>),若返回<code>false</code>则阻止关闭与销毁</td> </tr> <tr> <td>autofocus</td> <td>Boolean</td> <td>(默认值:<code>false</code>) 是否自动聚焦</td> </tr> <tr> <td>disabled</td> <td>Boolean</td> <td>(默认值: <code>false</code>) 是否禁用</td> </tr> </tbody> </table> <h4>示例</h4> <pre> <code class="language-javascript">dialog({ button: [ { value: '同意', callback: function () { this .content('你同意了'); return false; }, autofocus: true }, { value: '不同意', callback: function () { alert('你不同意') } }, { id: 'button-disabled', value: '无效按钮', disabled: true }, { value: '关闭我' } ] }).show(); </code></pre> 运行 <h3>width</h3> <p> </p> <p>设置对话框 <strong>内容</strong> 宽度。</p> <h4>类型</h4> <p>String, Number</p> <h4>示例</h4> <pre> <code class="language-javascript">dialog({ width: 460 }).show(); </code></pre> 运行 <pre> <code class="language-javascript">dialog({ width: '20em' }).show(); </code></pre> 运行 <h3>height</h3> <p> </p> <p>设置对话框 <strong>内容</strong> 高度。</p> <h4>类型</h4> <p>String, Number</p> <h4>示例</h4> <pre> <code class="language-javascript">dialog({ height: 460 }).show(); </code></pre> 运行 <pre> <code class="language-javascript">dialog({ height: '20em' }).show(); </code></pre> 运行 <h3>skin</h3> <p> </p> <p>设置对话框额外的<code>className</code>参数。</p> <p>多个<code>className</code>请使用空格隔开。</p> <h4>类型</h4> <p>String</p> <h4>示例</h4> <pre> <code class="language-javascript">dialog({ skin: 'min-dialog tips' }).show(); </code></pre> <h3>padding</h3> <p> </p> <p>(默认值: <em>继承 css 文件设置</em>) 设置消息内容与消息容器的填充边距,即 style <code>padding</code>属性</p> <h4>类型</h4> <p>String</p> <h4>示例</h4> <pre> <code class="language-javascript">dialog({ content: 'hello world', padding: 0 }).show(); </code></pre> 运行 <h3>fixed</h3> <p> </p> <p>(默认值: <code>false</code>) 开启固定定位。</p> <p>固定定位是 css2.1 <code>position</code>的一个属性,它能固定在浏览器某个地方,也不受滚动条拖动影响。IE6 与部分移动浏览器对其支持不好,内部会转成绝对定位。</p> <h4>类型</h4> <p>Boolean</p> <h4>示例</h4> <pre> <code class="language-javascript">dialog({ fixed: true, title: '消息', content: '请拖动滚动条查看' }).show(); </code></pre> 运行 <h3>align</h3> <p> </p> <p>(默认值: <code>"bottom left"</code>) 设置对话框与其他元素的对齐方式。</p> <p>如果<code>show(elem)</code>与<code>showModal(elem)</code>传入元素,<code>align</code>参数方可生效,支持如下对齐方式:</p> <ul> <li><code>"top left"</code></li> <li><code>"top"</code></li> <li><code>"top right"</code></li> <li><code>"right top"</code></li> <li><code>"right"</code></li> <li><code>"right bottom"</code></li> <li><code>"bottom right"</code></li> <li><code>"bottom"</code></li> <li><code>"bottom left"</code></li> <li><code>"left bottom"</code></li> <li><code>"left"</code></li> <li><code>"left top"</code></li> </ul> <h3>类型</h3> <p>String</p> <h3>示例</h3> <pre> <code class="language-javascript">var d = dialog({ align: 'left', content: 'Hello World!', quickClose: true }); d.show(document.getElementById('option-align')); </code></pre> 运行 <p>12 个方向定位演示</p> <h3>autofocus</h3> <p> </p> <p>(默认值: <code>true</code>) 是否支持自动聚焦。</p> <h4>类型</h4> <p>Boolean</p> <h3>quickClose</h3> <p> </p> <p>(默认值: false) 是否点击空白出快速关闭。</p> <h4>类型</h4> <p>Boolean</p> <h3>示例</h3> <pre> <code class="language-javascript">var d = dialog({ content: '点击空白处快速关闭', quickClose: true }); d.show(document.getElementById('option-quickClose')); </code></pre> 运行 <h3>zIndex</h3> <p> </p> <p>(默认值: <code>1024</code>) 重置全局<code>zIndex</code>初始值,用来改变对话框叠加高度。</p> <p>比如有时候配合外部浮动层 UI 组件,但是它们可能默认<code>zIndex</code>没有对话框高,导致无法浮动到对话框之上,这个时候你就可以给对话框指定一个较小的<code>zIndex</code>值。</p> <p>请注意这是一个会影响到全局的配置,后续出现的对话框叠加高度将重新按此累加。</p> <h4>类型</h4> <p>Number</p> <h4>示例</h4> <pre> <code class="language-javascript">dialog({ zIndex: 87 }).show(); </code></pre> 运行 <h3>onshow</h3> <p> </p> <p>对话框打开的事件。</p> <p>回调函数<code>this</code>指向<code>dialog</code>对象。</p> <h4>类型</h4> <p>Function</p> <h4>示例</h4> <pre> <code class="language-javascript">var d = dialog({ content: 'loading..', onshow: function () { this.content('dialog ready'); } }); d.show(); </code></pre> 运行 <h3>onclose</h3> <p> </p> <p>对话框关闭后执行的事件。</p> <p>回调函数<code>this</code>指向<code>dialog</code>对象。</p> <h4>类型</h4> <p>Function</p> <h4>示例</h4> <pre> <code class="language-javascript">var d = dialog({ onclose: function () { alert('对话框已经关闭'); }, ok: function () {} }); d.show(); </code></pre> 运行 <h3>onbeforeremove</h3> <p> </p> <p>对话框销毁之前事件。</p> <p>回调函数<code>this</code>指向<code>dialog</code>对象。</p> <h4>类型</h4> <p>Function</p> <h3>onremove</h3> <p> </p> <p>对话框销毁事件。</p> <p>回调函数<code>this</code>指向<code>dialog</code>对象。</p> <h4>类型</h4> <p>Function</p> <h4>示例</h4> <pre> <code class="language-javascript">var d = dialog({ onclose: function () { alert('对话框已经关闭'); }, onremove: function () { alert('对话框已经销毁'); }, ok: function () {} }); d.show(); </code></pre> 运行 <h3>onfocus</h3> <p> </p> <p>对话框获取焦点事件。</p> <p>回调函数<code>this</code>指向<code>dialog</code>对象。</p> <h4>类型</h4> <p>Function</p> <h3>onblur</h3> <p> </p> <p>对话框失去焦点事件。</p> <p>回调函数<code>this</code>指向<code>dialog</code>对象。</p> <h4>类型</h4> <p>Function</p> <h3>onreset</h3> <p> </p> <p>对话框位置重置事件。</p> <p>回调函数<code>this</code>指向<code>dialog</code>对象。</p> <h4>类型</h4> <p>Function</p> <h3>id</h3> <p> </p> <p>设定对话框唯一标识。</p> <ol> <li>可防止重复 ID 对话框弹出。</li> <li>支持使用<code>dialog.get(id)</code>获取某个对话框的接口。</li> </ol> <h4>类型</h4> <p>String</p> <h4>示例</h4> <pre> <code class="language-javascript">dialog({ id: 'id-demo', content: '再次点击运行看看' }).show(); dialog.get('id-demo').title('8888888888'); </code></pre> 运行 <h2>属性</h2> <h3>open</h3> <p>判断对话框是否被打开。</p> <h3>returnValue</h3> <p>对话框返回值。</p> <h4>示例</h4> <pre> <code class="language-javascript">var d = dialog({ title: '消息', content: '<input id="property-returnValue-demo" value="1" />', ok: function () { var value = $('#property-returnValue-demo').val(); this.close(value); this.remove(); } }); d.addEventListener('close', function () { alert(this.returnValue); }); d.show(); </code></pre> 运行
  • jquery图片查看插件Viewer.js使用讲解

    jquery插件Viewer.js是一个强大的图片查看工具,Viewer也提供了一个纯js版本的工具,图片查看,Viewer.js,Viewerjquery插件Viewer.js是一个强大的图片查看工具,Viewer也提供了一个纯js版本的工具<br /> GITHUB地址:<a href="https://github.com/fengyuanchen/viewer" rel="nofollow" target="_blank">https://github.com/fengyuanchen/viewer</a><br /> 效果:<br /> <img alt="viewer图片查看器,图片一" class="img-thumbnail" src="/assist/images/blog/9f3b079c3e8c4a61a3d2af0e54dab3de.png" /><br /> <span style="color:#16a085">提示:本站图片查看也是采用该工具</span><br /> 使用:<br /> JavaScript版本 <pre> <code class="language-xml"><link rel="stylesheet" href="css/viewer.min.css"> <script src="js/viewer.min.js"></script></code></pre> <br /> jQuery 版本: <pre> <code class="language-xml"><link rel="stylesheet" href="css/viewer.min.css"> <script src="js/jquery.min.js"></script> <script src="js/viewer.min.js"></script></code></pre> 注意:JS 版本和 jQuery 版本名字虽然一样,但代码不一样,不能通用,请到 github 上下载需要的版本。<br />   <h3>HTML</h3> <pre> <code class="language-xml"><ul id="dowebok"> <li><img src="img/tibet-1.jpg" alt="图片1"></li> <li><img src="img/tibet-2.jpg" alt="图片2"></li> <li><img src="img/tibet-3.jpg" alt="图片3"></li> <li><img src="img/tibet-4.jpg" alt="图片4"></li> <li><img src="img/tibet-5.jpg" alt="图片5"></li> <li><img src="img/tibet-6.jpg" alt="图片6"></li> </ul></code></pre>   <h3>JavaScript:</h3> JavaScript版本: <pre> <code class="language-javascript">var viewer = new Viewer(document.getElementById('dowebok'));</code></pre> jQuery 版本: <pre> <code class="language-javascript">$('#dowebok').viewer();</code></pre> <br /> 参数使用 <pre> <code class="language-javascript">$('#dowebok').viewer({ navbar:false,//关闭缩略导航 toolbar:false//关闭工具栏 });</code></pre> <br /> 其他配置参数: <table class="table table-bordered table-hover"> <thead> <tr> <th>名称</th> <th>类型</th> <th>默认值</th> <th>说明</th> </tr> </thead> <tbody> <tr> <td>inline</td> <td>布尔值</td> <td>false</td> <td>启用 inline 模式</td> </tr> <tr> <td>button</td> <td>布尔值</td> <td>true</td> <td>显示右上角关闭按钮(jQuery 版本无效)</td> </tr> <tr> <td>navbar</td> <td>布尔值/整型</td> <td>true</td> <td>显示缩略图导航</td> </tr> <tr> <td>title</td> <td>布尔值/整型</td> <td>true</td> <td>显示当前图片的标题(现实 alt 属性及图片尺寸)</td> </tr> <tr> <td>toolbar</td> <td>布尔值/整型</td> <td>true</td> <td>显示工具栏</td> </tr> <tr> <td>tooltip</td> <td>布尔值</td> <td>true</td> <td>显示缩放百分比</td> </tr> <tr> <td>movable</td> <td>布尔值</td> <td>true</td> <td>图片是否可移动</td> </tr> <tr> <td>zoomable</td> <td>布尔值</td> <td>true</td> <td>图片是否可缩放</td> </tr> <tr> <td>rotatable</td> <td>布尔值</td> <td>true</td> <td>图片是否可旋转</td> </tr> <tr> <td>scalable</td> <td>布尔值</td> <td>true</td> <td>图片是否可翻转</td> </tr> <tr> <td>transition</td> <td>布尔值</td> <td>true</td> <td>使用 CSS3 过度</td> </tr> <tr> <td>fullscreen</td> <td>布尔值</td> <td>true</td> <td>播放时是否全屏</td> </tr> <tr> <td>keyboard</td> <td>布尔值</td> <td>true</td> <td>是否支持键盘</td> </tr> <tr> <td>interval</td> <td>整型</td> <td>5000</td> <td>播放间隔,单位为毫秒</td> </tr> <tr> <td>zoomRatio</td> <td>浮点型</td> <td>0.1</td> <td>鼠标滚动时的缩放比例</td> </tr> <tr> <td>minZoomRatio</td> <td>浮点型</td> <td>0.01</td> <td>最小缩放比例</td> </tr> <tr> <td>maxZoomRatio</td> <td>数字</td> <td>100</td> <td>最大缩放比例</td> </tr> <tr> <td>zIndex</td> <td>数字</td> <td>2015</td> <td>设置图片查看器 modal 模式时的 z-index</td> </tr> <tr> <td>zIndexInline</td> <td>数字</td> <td>0</td> <td>设置图片查看器 inline 模式时的 z-index</td> </tr> <tr> <td>url</td> <td>字符串/函数</td> <td>src</td> <td>设置大图片的 url</td> </tr> <tr> <td>build</td> <td>函数</td> <td>null</td> <td>回调函数,具体查看演示</td> </tr> <tr> <td>built</td> <td>函数</td> <td>null</td> <td>回调函数,具体查看演示</td> </tr> <tr> <td>show</td> <td>函数</td> <td>null</td> <td>回调函数,具体查看演示</td> </tr> <tr> <td>shown</td> <td>函数</td> <td>null</td> <td>回调函数,具体查看演示</td> </tr> <tr> <td>hide</td> <td>函数</td> <td>null</td> <td>回调函数,具体查看演示</td> </tr> <tr> <td>hidden</td> <td>函数</td> <td>null</td> <td>回调函数,具体查看演示</td> </tr> <tr> <td>view</td> <td>函数</td> <td>null</td> <td>回调函数,具体查看演示</td> </tr> <tr> <td>viewed</td> <td>函数</td> <td>null</td> <td>回调函数,具体查看演示</td> </tr> </tbody> </table>
  • MySQL5.6数据库双机主从热备配置

    MySQL5.6数据库双机主从热备配置<h2><span style="font-family:宋体">一、准备</span></h2> <p><span style="font-family:宋体">首先安装两个</span>MySQL<span style="font-family:宋体">数据库</span></p> <p>Ip<span style="font-family:宋体">地址和端口分别是</span>:</p> <p>192.168.8.202 3306</p> <p>192.168.8.203 3306</p> <p>Root<span style="font-family:宋体">用户及密码</span></p> <p>root root</p> <p><img alt="逻辑图" class="img-thumbnail" src="/assist/images/blog/87f121d199f44b569be494ca6c9226ca.png" /></p> <p><strong><span style="font-family:宋体"><span style="color:red">保证两个数据库服务器中需要同步的库内容一致</span></span></strong></p> <h2><span style="font-family:宋体">二、配置从数据库</span>Master</h2> <h3>2.1<span style="font-family:宋体">停止</span>master<span style="font-family:宋体">数据库服务</span></h3> <p><span style="font-family:宋体">命令</span>:</p> <pre> <code>#service mysqld stop</code></pre> <p>2.2<span style="font-family:宋体">修改</span>/etc/my.cnf<span style="font-family:宋体">配置文件</span></p> <p><span style="font-family:宋体">在</span>[mysqld]<span style="font-family:宋体">节点添加以下内容</span>:</p> <pre> <code>#######主从配置master信息####### #[必须]服务器唯一ID,默认是1,一般取IP最后一段 server_id=202 #[必须]启用二进制日志 log_bin=mysql-bin #需要备份的数据库名  多个库写多行 #binlog-do-db=test #binlog-do-db=test1 #binlog-do-db=test2 #忽略备份数据库名 多个库写多行 binlog-ignore-db=mysql #若涉及及同步函数或者存储过程需要配置,否则主备会产生异常不能同步 log_bin_trust_function_creators=TRUE #######主从配置master信息############</code></pre> <p> </p> <h3>2.3<span style="font-family:宋体">启动</span>MySQL<span style="font-family:宋体">数据库服务</span></h3> <p><span style="font-family:宋体">命令</span>:</p> <pre> <code>#service mysqld start</code></pre> <p>2.4<span style="font-family:宋体">添加从机过来同步数据的用户</span></p> <p><span style="font-family:宋体">首先使用</span>root<span style="font-family:宋体">用户登录</span>master<span style="font-family:宋体">数据库</span>,<span style="font-family:宋体">也就是</span>202</p> <p><span style="font-family:宋体">命令</span>:</p> <pre> <code>#mysql –uroot –proot</code></pre> <p><span style="font-family:宋体">登录数据库后执行命令</span><br />  </p> <pre> <code>mysql> grant replication slave on *.* to 'slaveuser'@'%' identified by '123456'; Query OK, 0 rows affected (0.06 sec) mysql> FLUSH PRIVILEGES; Query OK, 0 rows affected (0.06 sec)</code></pre> <p><strong><span style="font-family:宋体">提示</span></strong><strong>:</strong><em><span style="font-family:宋体">一般不用</span></em><em>root</em><em><span style="font-family:宋体">帐号,“</span></em><em>%</em><em><span style="font-family:宋体">”表示所有客户端都可能连,只要帐号,密码正确,此处可用具体客户端</span></em><em>IP</em><em><span style="font-family:宋体">代替,如</span></em><em>192.168.8.203</em><em><span style="font-family:宋体">,加强安全。</span></em></p> <p> </p> <p><span style="font-family:宋体">查看刚才创建的用户授权结果</span>:</p> <p><span style="font-family:宋体">命令</span>:</p> <p><span style="font-family:宋体">切换至</span>mysql<span style="font-family:宋体">数据库</span></p> <pre> <code>mysql> use mysql mysql>select * from user where host='%' and user='slaveuser' \G;  *************************** 1. row ***************************                   Host: %                   User: slaveuser               Password: *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9            Select_priv: N            Insert_priv: N            Update_priv: N            Delete_priv: N            Create_priv: N              Drop_priv: N            Reload_priv: N          Shutdown_priv: N           Process_priv: N              File_priv: N             Grant_priv: N        References_priv: N             Index_priv: N             Alter_priv: N           Show_db_priv: N             Super_priv: N  Create_tmp_table_priv: N       Lock_tables_priv: N           Execute_priv: N        Repl_slave_priv: Y       Repl_client_priv: N       Create_view_priv: N         Show_view_priv: N    Create_routine_priv: N     Alter_routine_priv: N       Create_user_priv: N             Event_priv: N           Trigger_priv: N Create_tablespace_priv: N               ssl_type:             ssl_cipher:            x509_issuer:           x509_subject:          max_questions: 0            max_updates: 0        max_connections: 0   max_user_connections: 0                 plugin: mysql_native_password  authentication_string:       password_expired: N 1 row in set (0.00 sec) ERROR: No query specified mysql></code></pre> <p> </p> <p><img alt="2" class="img-thumbnail" src="/assist/images/blog/42cf2e46dd9449e2a2ef048dd60c3c24.png" /></p> <p> </p> <p><strong>Repl_slave_priv</strong><strong><span style="font-family:宋体">项为</span>Y</strong><strong><span style="font-family:宋体">,表示授权成功</span></strong></p> <p> </p> <h3>2.5<span style="font-family:宋体">查看</span>master<span style="font-family:宋体">数据库状态</span></h3> <p><strong><span style="font-family:宋体">注意</span>:</strong><strong><span style="font-family:宋体">查看之前做好数据库只读操作</span>,</strong><strong><span style="font-family:宋体">防止在配置过程中出现写入数据日志,导致查询的</span>master</strong><strong><span style="font-family:宋体">日志不可控</span></strong></p> <p> </p> <p><span style="font-family:宋体">查看</span>master<span style="font-family:宋体">数据库状态</span></p> <p><span style="font-family:宋体">命令</span>:</p> <pre> <code>mysql> show master status; +------------------+----------+--------------+------------------+-------------------+ | File             | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set | +------------------+----------+--------------+------------------+-------------------+ | mysql-bin.000002 |     6187 |              | mysql            |                   | +------------------+----------+--------------+------------------+-------------------+ 1 row in set (0.01 sec) mysql></code></pre> <p><img alt="3" class="img-thumbnail" src="/assist/images/blog/487df8f373c743aa85d47462fd11cb76.png" /></p> <p> </p> <p><span style="font-family:宋体">日志文件名</span>:<span style="font-family:宋体">称</span> <strong>mysql-bin.000002</strong></p> <p><span style="font-family:宋体">日志文件位置</span>: 6187</p> <p> </p> <h2><span style="font-family:宋体">三、配置从数据库</span>slave</h2> <p><strong><span style="font-family:宋体"><span style="color:red">如果</span></span><span style="color:red">master</span></strong><strong><span style="font-family:宋体"><span style="color:red">中需要同步的数据库已经存在且有数据</span></span><span style="color:red">,</span></strong><strong><span style="font-family:宋体"><span style="color:red">则需要将</span></span><span style="color:red">master</span></strong><strong><span style="font-family:宋体"><span style="color:red">中的数据库导出到</span></span><span style="color:red">slave</span></strong><strong><span style="font-family:宋体"><span style="color:red">保持</span></span><span style="color:red">master</span></strong><strong><span style="font-family:宋体"><span style="color:red">和</span></span><span style="color:red">slave</span></strong><strong><span style="font-family:宋体"><span style="color:red">需要同步的数据库信息一致。</span></span></strong></p> <h3>3.1<span style="font-family:宋体">停止</span>slave<span style="font-family:宋体">数据库服务</span></h3> <p><span style="font-family:宋体">命令</span>:</p> <pre> <code>#service mysqld stop</code></pre> <p>3.2<span style="font-family:宋体">修改</span>/etc/my.cnf<span style="font-family:宋体">配置文件</span></p> <p><span style="font-family:宋体">在</span>[mysqld]<span style="font-family:宋体">的节点下添加以下配置</span>:</p> <p><img alt="4" class="img-thumbnail" src="/assist/images/blog/d45976833db9461ca6985770eb53cbc0.png" /></p> <p><strong><span style="font-family:宋体">注意</span>ID</strong><strong><span style="font-family:宋体">不能重复</span></strong></p> <p> </p> <h3>3.3<span style="font-family:宋体">启动</span>slave<span style="font-family:宋体">的</span> MySQL<span style="font-family:宋体">数据库服务</span></h3> <p><span style="font-family:宋体">命令</span>:</p> <pre> <code>#service mysqld start</code></pre> <p>3.4root<span style="font-family:宋体">用户登录从库设置信息</span></p> <p><span style="font-family:宋体">登录数据库</span>:</p> <pre> <code>#mysql –uroot -proot</code></pre> <p><span style="font-family:宋体">停止</span>slave</p> <pre> <code>mysql> stop slave;</code></pre> <p><span style="font-family:宋体">配置</span>master<span style="font-family:宋体">信息</span>:</p> <pre> <code>mysql>change master to   master_host='192.168.8.202',  master_user='slaveuser',  master_password='123456',  master_log_file='mysql-bin.000002',  master_log_pos=6187;</code></pre> <p> </p> <p><em><span style="font-family:宋体">配置说明</span>:</em></p> <p><em>master_host:master</em><em><span style="font-family:宋体">的主机地址</span></em></p> <p><em>master_user:master</em><em><span style="font-family:宋体">上创建的同步数据用户</span>,</em><em><span style="font-family:宋体">之前创建的</span>slaveuser</em></p> <p><em>master_password:master</em><em><span style="font-family:宋体">创建的同步数据用户密码</span></em></p> <p><em>master_log_file:master</em><em><span style="font-family:宋体">最后一步查看的日志文件名</span></em></p> <p><em>master_log_pos:master</em><em><span style="font-family:宋体">最后一步查看的日志当前位置</span>,</em><em><span style="font-family:宋体">同步将从这个点开始</span></em></p> <p> </p> <p><span style="font-family:宋体">启动</span>slave</p> <pre> <code>mysql>start slave</code></pre> <p> </p> <h3>3.5<span style="font-family:宋体">查看从库配置状态</span></h3> <p><span style="font-family:宋体">命令</span>:</p> <pre> <code>Mysql> mysql> show slave status \G; *************************** 1. row ***************************                Slave_IO_State: Waiting for master to send event                   Master_Host: 192.168.8.202                   Master_User: slaveuser                   Master_Port: 3306                 Connect_Retry: 60               Master_Log_File: mysql-bin.000002           Read_Master_Log_Pos: 23305                Relay_Log_File: mysqld-relay-bin.000002                 Relay_Log_Pos: 283         Relay_Master_Log_File: mysql-bin.000002              Slave_IO_Running: Yes             Slave_SQL_Running: Yes               Replicate_Do_DB:           Replicate_Ignore_DB:            Replicate_Do_Table:        Replicate_Ignore_Table:       Replicate_Wild_Do_Table:   Replicate_Wild_Ignore_Table:                    Last_Errno: 0                    Last_Error:                  Skip_Counter: 0           Exec_Master_Log_Pos: 23305               Relay_Log_Space: 457               Until_Condition: None                Until_Log_File:                 Until_Log_Pos: 0            Master_SSL_Allowed: No            Master_SSL_CA_File:            Master_SSL_CA_Path:               Master_SSL_Cert:             Master_SSL_Cipher:                Master_SSL_Key:         Seconds_Behind_Master: 0 Master_SSL_Verify_Server_Cert: No                 Last_IO_Errno: 0                 Last_IO_Error:                Last_SQL_Errno: 0                Last_SQL_Error:   Replicate_Ignore_Server_Ids:              Master_Server_Id: 202                   Master_UUID: 4aed5689-6c69-11e7-9b1f-000c290e4f3d              Master_Info_File: /var/lib/mysql/master.info                     SQL_Delay: 0           SQL_Remaining_Delay: NULL       Slave_SQL_Running_State: Slave has read all relay log; waiting for the slave I/O thread to update it            Master_Retry_Count: 86400                   Master_Bind:       Last_IO_Error_Timestamp:      Last_SQL_Error_Timestamp:                Master_SSL_Crl:            Master_SSL_Crlpath:            Retrieved_Gtid_Set:             Executed_Gtid_Set:                 Auto_Position: 0</code></pre> <p>1 row in set (0.00 sec)<img alt="5" class="img-thumbnail" src="/assist/images/blog/9e82bbab3212434b97e01481c2239796.png" /></p> <p><span style="font-family:宋体">注意</span>,<span style="font-family:宋体">上面两个配置</span></p> <p><span style="color:red">Slave_IO_Running: Yes</span></p> <p><span style="color:red">Slave_SQL_Running: Yes</span></p> <p><span style="color:red">Yes</span><span style="font-family:宋体"><span style="color:red">标识已经成功配置</span></span></p> <p> </p> <h2><span style="font-family:宋体">四、测试</span></h2> <h3>4.1<span style="font-family:宋体">表创建同步测试</span></h3> <p><span style="font-family:宋体">测试步骤方法</span>:<span style="font-family:宋体">在</span>master<span style="font-family:宋体">的</span>test<span style="font-family:宋体">数据库中创建一个表</span>,<span style="font-family:宋体">名称为</span>t_book<span style="font-family:宋体">,然后去</span>slave<span style="font-family:宋体">中</span>test<span style="font-family:宋体">数据库查看表是否同步。</span></p> <p> </p> <p><span style="font-family:宋体">首先查看数据库中已经有的表</span>:</p> <p><span style="color:red">Master</span><span style="font-family:宋体"><span style="color:red">中</span></span><span style="color:red">:</span></p> <pre> <code>#mysql –uroot –proot Mysql>use test show tables; +----------------+ | Tables_in_test | +----------------+ | t_user         | +----------------+ 1 row in set (0.00 sec) mysql></code></pre> <p><img alt="6" class="img-thumbnail" src="/assist/images/blog/0bf994d9b7db4ed587e91dc085d0dbe2.png" /></p> <p><span style="font-family:宋体">同样查看</span>slave<span style="font-family:宋体">库中的</span>test<span style="font-family:宋体">库</span></p> <p><img alt="7" class="img-thumbnail" src="/assist/images/blog/034b5e8cf80f47298f9d4801b8cbdeb8.png" /></p> <p> </p> <p><span style="font-family:宋体">在</span>master<span style="font-family:宋体">的</span>test<span style="font-family:宋体">库中创建一个表</span>,<span style="font-family:宋体">名称为</span>t_book</p> <p><span style="font-family:宋体">首先进入</span>MySQL<span style="font-family:宋体">数据库</span></p> <p> </p> <p><span style="font-family:宋体">创建表</span>t_book</p> <pre> <code>mysql> create table t_book(id int,book_name varchar(50)); Query OK, 0 rows affected (0.09 sec) mysql> show tables; +----------------+ | Tables_in_test | +----------------+ | t_book         | | t_user         | +----------------+ 2 rows in set (0.01 sec) mysql></code></pre> <p> </p> <p><img alt="8" class="img-thumbnail" src="/assist/images/blog/eb32f00cfba042d590533733be10f41f.png" /></p> <p> </p> <p><span style="font-family:宋体">查看</span>slave<span style="font-family:宋体">库中的</span>test</p> <p>Master<span style="font-family:宋体">已经在</span>test<span style="font-family:宋体">库中创建了一个</span>t_book<span style="font-family:宋体">的表格,现在查看</span>slave<span style="font-family:宋体">的</span>test<span style="font-family:宋体">数据库中是否已经同步</span></p> <p> </p> <p><span style="font-family:宋体">登录</span>slave</p> <pre> <code>#root –uroot –proot mysql> show tables; +----------------+ | Tables_in_test | +----------------+ | t_book         | | t_user         | +----------------+ 2 rows in set (0.00 sec) mysql></code></pre> <p><img alt="9" class="img-thumbnail" src="/assist/images/blog/4055bd7d4c2c4b87a9db93d542141050.png" /></p> <p><span style="font-family:宋体">可以在</span>slave<span style="font-family:宋体">中看到</span>t_book<span style="font-family:宋体">已经同步过来</span>,</p> <p><img alt="10" class="img-thumbnail" src="/assist/images/blog/98b8f78e613c40f8a12a68007ef00d1e.png" /></p> <p><span style="font-family:宋体">查询数据为空</span></p> <h3>4.2<span style="font-family:宋体">表数据同步测试</span></h3> <p><span style="font-family:宋体">测试方式</span>:</p> <p><span style="font-family:宋体">向</span>Master<span style="font-family:宋体">中的</span>test<span style="font-family:宋体">数据库中的</span>t_book<span style="font-family:宋体">表插入一条测试数据</span>,<span style="font-family:宋体">然后去</span>slave<span style="font-family:宋体">的</span>test<span style="font-family:宋体">数据库查询</span>t_book<span style="font-family:宋体">表中是否存在</span></p> <p> </p> <p>Master<span style="font-family:宋体">操作</span>:</p> <p><img alt="master" class="img-thumbnail" src="/assist/images/blog/2620001766974224ba9cd69408c9cdc6.png" /></p> <p> </p> <p>Slave<span style="font-family:宋体">操作</span>:</p> <p><img alt="slave" class="img-thumbnail" src="/assist/images/blog/b14bda207a9f432aae84d581f7ad8907.png" /></p> <p> </p> <p>Slave<span style="font-family:宋体">中的数据已经同步。</span></p> <p> </p>
  • spring boot thymeleaf使用介绍

    spring boot thymeleaf使用介绍<h2>thymeleaf介绍</h2> <p>简单说, Thymeleaf 是一个跟 Velocity、FreeMarker 类似的模板引擎,它可以完全替代 JSP 。相较与其他的模板引擎,它有如下三个极吸引人的特点:</p> <ul> <li> <p>1.Thymeleaf 在有网络和无网络的环境下皆可运行,即它可以让美工在浏览器查看页面的静态效果,也可以让程序员在服务器查看带数据的动态页面效果。这是由于它支持 html 原型,然后在 html 标签里增加额外的属性来达到模板+数据的展示方式。浏览器解释 html 时会忽略未定义的标签属性,所以 thymeleaf 的模板可以静态地运行;当有数据返回到页面时,Thymeleaf 标签会动态地替换掉静态内容,使页面动态显示。</p> </li> <li> <p>2.Thymeleaf 开箱即用的特性。它提供标准和spring标准两种方言,可以直接套用模板实现JSTL、 OGNL表达式效果,避免每天套模板、该jstl、改标签的困扰。同时开发人员也可以扩展和创建自定义的方言。</p> </li> <li> <p>3.Thymeleaf 提供spring标准方言和一个与 SpringMVC 完美集成的可选模块,可以快速的实现表单绑定、属性编辑器、国际化等功能。</p> </li> </ul> <h2>标准表达式语法</h2> <p>它们分为四类:</p> <ul> <li> <p>1.变量表达式</p> </li> <li> <p>2.选择或星号表达式</p> </li> <li> <p>3.文字国际化表达式</p> </li> <li> <p>4.URL表达式</p> </li> </ul> <h3>变量表达式</h3> <p>变量表达式即OGNL表达式或Spring EL表达式(在Spring术语中也叫model attributes)。如下所示:<br /> <code>${session.user.name}</code>  </p> <p>它们将以HTML标签的一个属性来表示:<br />  </p> <pre> <code class="language-html"><span th:text="${book.author.name}"> <li th:each="book : ${books}"></code></pre> <h3>选择(星号)表达式</h3> <p>选择表达式很像变量表达式,不过它们用一个预先选择的对象来代替上下文变量容器(map)来执行,如下:<br /> <code>*{customer.name}</code></p> <p>被指定的object由th:object属性定义:</p> <pre> <code class="language-html"> <div th:object="${book}"> ... <span th:text="*{title}">...</span> ... </div></code></pre> <p> </p> <h3>文字国际化表达式</h3> <p>文字国际化表达式允许我们从一个外部文件获取区域文字信息(.properties),用Key索引Value,还可以提供一组参数(可选).</p> <pre> <code class="language-html">#{main.title} #{message.entrycreated(${entryId})}</code></pre> <p>可以在模板文件中找到这样的表达式代码:<br />  </p> <pre> <code class="language-html"> <table> ... <th th:text="#{header.address.city}">...</th> <th th:text="#{header.address.country}">...</th> ... </table></code></pre> <h3>URL表达式</h3> <p>URL表达式指的是把一个有用的上下文或回话信息添加到URL,这个过程经常被叫做URL重写。<br /> <code>@{/order/list}</code><br /> URL还可以设置参数:<br /> <code>@{/order/details(id=${orderId})}</code><br /> 相对路径:<br /> <code>@{../documents/report}</code>  </p> <p>让我们看这些表达式:<br />  </p> <pre> <code class="language-html"> <form th:action="@{/createOrder}"> <a href="main.html" th:href="@{/main}"></code></pre> <h3>变量表达式和星号表达有什么区别吗?</h3> <p>如果不考虑上下文的情况下,两者没有区别;星号语法评估在选定对象上表达,而不是整个上下文<br /> 什么是选定对象?就是父标签的值,如下:<br />  </p> <pre> <code class="language-html"> <div th:object="${session.user}"> <p>Name: <span th:text="*{firstName}">Sebastian</span>.</p> <p>Surname: <span th:text="*{lastName}">Pepper</span>.</p> <p>Nationality: <span th:text="*{nationality}">Saturn</span>.</p> </div></code></pre> <p>这是完全等价于:</p> <pre> <code class="language-html"> <div th:object="${session.user}"> <p>Name: <span th:text="${session.user.firstName}">Sebastian</span>.</p> <p>Surname: <span th:text="${session.user.lastName}">Pepper</span>.</p> <p>Nationality: <span th:text="${session.user.nationality}">Saturn</span>.</p> </div></code></pre> <p>当然,美元符号和星号语法可以混合使用:<br />  </p> <pre> <code class="language-html"> <div th:object="${session.user}"> <p>Name: <span th:text="*{firstName}">Sebastian</span>.</p> <p>Surname: <span th:text="${session.user.lastName}">Pepper</span>.</p> <p>Nationality: <span th:text="*{nationality}">Saturn</span>.</p> </div></code></pre> <h3>表达式支持的语法</h3> <h4>字面(Literals)</h4> <ul> <li> <p>文本文字(Text literals): <code>'one text', 'Another one!',…</code></p> </li> <li> <p>数字文本(Number literals): <code>0, 34, 3.0, 12.3,…</code></p> </li> <li> <p>布尔文本(Boolean literals): <code>true, false</code></p> </li> <li> <p>空(Null literal): <code>null</code></p> </li> <li> <p>文字标记(Literal tokens): <code>one, sometext, main,…</code></p> </li> </ul> <h4>文本操作(Text operations)</h4> <ul> <li> <p>字符串连接(String concatenation): <code>+</code></p> </li> <li> <p>文本替换(Literal substitutions): <code>|The name is ${name}|</code></p> </li> </ul> <h4>算术运算(Arithmetic operations)</h4> <ul> <li> <p>二元运算符(Binary operators): <code>+, -, *, /, %</code></p> </li> <li> <p>减号(单目运算符)Minus sign (unary operator): <code>-</code></p> </li> </ul> <h4>布尔操作(Boolean operations)</h4> <ul> <li> <p>二元运算符(Binary operators):<code>and, or</code></p> </li> <li> <p>布尔否定(一元运算符)Boolean negation (unary operator):<code>!, not</code></p> </li> </ul> <h4>比较和等价(Comparisons and equality)</h4> <ul> <li> <p>比较(Comparators): <code>>, <, >=, <= (gt, lt, ge, le)</code></p> </li> <li> <p>等值运算符(Equality operators):<code>==, != (eq, ne)</code></p> </li> </ul> <h4>条件运算符(Conditional operators)</h4> <ul> <li> <p>If-then: <code>(if) ? (then)</code></p> </li> <li> <p>If-then-else: <code>(if) ? (then) : (else)</code></p> </li> <li> <p>Default: (value) ?: <code>(defaultvalue)</code></p> </li> </ul> <p>所有这些特征可以被组合并嵌套:<br />  </p> <pre> <code class="language-html">'User is of type ' + (${user.isAdmin()} ? 'Administrator' : (${user.type} ?: 'Unknown'))</code></pre> <h2>常用th标签都有那些?</h2> <table> <thead> <tr> <th>关键字</th> <th>功能介绍</th> <th>案例</th> </tr> </thead> <tbody> <tr> <td>th:id</td> <td>替换id</td> <td><code><input th:id="'xxx' + ${collect.id}"/></code>  </td> </tr> <tr> <td>th:text</td> <td>文本替换</td> <td><code><p  th:text="${collect.description}">description</p></code></td> </tr> <tr> <td>th:utext</td> <td>支持html的文本替换</td> <td><code><p  th:utext="${htmlcontent}">conten</p></code></td> </tr> <tr> <td>th:object</td> <td>替换对象</td> <td><code><div th:object="${session.user}"></code></td> </tr> <tr> <td>th:value</td> <td>属性赋值</td> <td><code><input th:value="${user.name}" /></code></td> </tr> <tr> <td>th:with</td> <td>变量赋值运算</td> <td><code><div th:with="isEven=${prodStat.count}%2==0"></div></code></td> </tr> <tr> <td>th:style</td> <td>设置样式</td> <td><code>th:style="'display:' + @{(${sitrue} ? 'none' : 'inline-block')} + ''"</code></td> </tr> <tr> <td>th:onclick</td> <td>点击事件</td> <td><code>th:onclick="'getCollect()'"</code></td> </tr> <tr> <td>th:each</td> <td>属性赋值</td> <td><code>tr th:each="user,userStat:${users}"></code></td> </tr> <tr> <td>th:if</td> <td>判断条件</td> <td><code><a th:if="${userId == collect.userId}" ></code></td> </tr> <tr> <td>th:unless</td> <td>和th:if判断相反</td> <td><code><a th:href="@{/login}" th:unless=${session.user != null}>Login</a></code></td> </tr> <tr> <td>th:href</td> <td>链接地址</td> <td><code><a th:href="@{/login}" th:unless=${session.user != null}>Login</a> /></code></td> </tr> <tr> <td>th:switch</td> <td>多路选择 配合th:case 使用</td> <td><code><div th:switch="${user.role}"></code></td> </tr> <tr> <td>th:case</td> <td>th:switch的一个分支</td> <td><code><p th:case="'admin'">User is an administrator</p></code></td> </tr> <tr> <td>th:fragment</td> <td>布局标签,定义一个代码片段,方便其它地方引用</td> <td><code><div th:fragment="alert"></code></td> </tr> <tr> <td>th:include</td> <td>布局标签,替换内容到引入的文件</td> <td><code><head th:include="layout :: htmlhead" th:with="title='xx'"></head> /></code></td> </tr> <tr> <td>th:replace</td> <td>布局标签,替换整个标签到引入的文件</td> <td><code><div th:replace="fragments/header :: title"></div></code></td> </tr> <tr> <td>th:selected</td> <td>selected选择框 选中</td> <td><code>th:selected="(${xxx.id} == ${configObj.dd})"</code></td> </tr> <tr> <td>th:src</td> <td>图片类地址引入</td> <td><code><img class="img-responsive" alt="App Logo" th:src="@{/img/logo.png}"  /></code></td> </tr> <tr> <td>th:inline</td> <td>定义js脚本可以使用变量</td> <td><code><script type="text/javascript" th:inline="javascript"></code></td> </tr> <tr> <td>th:action</td> <td>表单提交的地址</td> <td><code><form action="subscribe.html" th:action="@{/subscribe}"></code></td> </tr> <tr> <td>th:remove</td> <td>删除某个属性</td> <td><code><tr th:remove="all">   1.all:删除包含标签和所有的孩子。2.body:不包含标记删除,但删除其所有的孩子。3.tag:包含标记的删除,但不删除它的孩子。4.all-but-first:删除所有包含标签的孩子,除了第一个。5.none:什么也不做。这个值是有用的动态评估。</code></td> </tr> <tr> <td>th:attr</td> <td>设置标签属性,多个属性可以用逗号分隔</td> <td>比如 <code>th:attr="src=@{/image/aa.jpg},title=#{logo}"</code>,此标签不太优雅,一般用的比较少。</td> </tr> </tbody> </table> <p>还有非常多的标签,这里只列出最常用的几个,由于一个标签内可以包含多个th:x属性,其生效的优先级顺序为:include,each,if/unless/switch/case,with,attr/attrprepend/attrappend,value/href,src ,etc,text/utext,fragment,remove。</p> <h2>几种常用的使用方法</h2> <h3>1、赋值、字符串拼接</h3> <pre> <code class="language-html"> <p th:text="${collect.description}">description</p> <span th:text="'Welcome to our application, ' + ${user.name} + '!'"></code></pre> 字符串拼接还有另外一种简洁的写法 <pre> <code class="language-html"><span th:text="|Welcome to our application, ${user.name}!|"></code></pre> <h3>2、条件判断 If/Unless</h3> Thymeleaf中使用th:if和th:unless属性进行条件判断,下面的例子中,<code><a></code>标签只有在<code>th:if</code>中条件成立时才显示: <pre> <code class="language-html"><a th:if="${myself=='yes'}" > </i> </a> <a th:unless=${session.user != null} th:href="@{/login}" >Login</a></code></pre> <p>th:unless于th:if恰好相反,只有表达式中的条件不成立,才会显示其内容。</p> <p>也可以使用  <code>(if) ? (then) : (else)</code> 这种语法来判断显示的内容</p> <h3>3、for 循环</h3> <pre> <code class="language-html"> <tr th:each="collect,iterStat : ${collects}"> <th scope="row" th:text="${collect.id}">1</th> <td > <img th:src="${collect.webLogo}"/> </td> <td th:text="${collect.url}">Mark</td> <td th:text="${collect.title}">Otto</td> <td th:text="${collect.description}">@mdo</td> <td th:text="${terStat.index}">index</td> </tr></code></pre>   <p>iterStat称作状态变量,属性有:</p> <ul> <li> <p>index:当前迭代对象的index(从0开始计算)</p> </li> <li> <p>count: 当前迭代对象的index(从1开始计算)</p> </li> <li> <p>size:被迭代对象的大小</p> </li> <li> <p>current:当前迭代变量</p> </li> <li> <p>even/odd:布尔值,当前循环是否是偶数/奇数(从0开始计算)</p> </li> <li> <p>first:布尔值,当前循环是否是第一个</p> </li> <li> <p>last:布尔值,当前循环是否是最后一个</p> </li> </ul> <h3>4、URL</h3> <p>URL在Web应用模板中占据着十分重要的地位,需要特别注意的是Thymeleaf对于URL的处理是通过语法@{…}来处理的。<br /> 如果需要Thymeleaf对URL进行渲染,那么务必使用th:href,th:src等属性,下面是一个例子<br />  </p> <pre> <code class="language-html"><!-- Will produce 'http://localhost:8080/standard/unread' (plus rewriting) --> <a th:href="@{/standard/{type}(type=${type})}">view</a> <!-- Will produce '/gtvg/order/3/details' (plus rewriting) --> <a href="details.html" th:href="@{/order/{orderId}/details(orderId=${o.id})}">view</a></code></pre> 设置背景 <pre> <code class="language-html"><div th:style="'background:url(' + @{/<path-to-image>} + ');'"></div></code></pre> 根据属性值改变背景 <pre> <code class="language-html"> <div class="media-object resource-card-image" th:style="'background:url(' + @{(${collect.webLogo}=='' ? 'img/favicon.png' : ${collect.webLogo})} + ')'" ></div></code></pre> <p>几点说明:</p> <ul> <li> <p>上例中URL最后的<code>(orderId=${o.id})</code> 表示将括号内的内容作为URL参数处理,该语法避免使用字符串拼接,大大提高了可读性</p> </li> <li> <p><code>@{...}</code>表达式中可以通过<code>{orderId}</code>访问Context中的orderId变量</p> </li> <li> <p><code>@{/order}</code>是Context相关的相对路径,在渲染时会自动添加上当前Web应用的Context名字,假设context名字为app,那么结果应该是/app/order</p> </li> </ul> <h3>5、内联js</h3> <p>内联文本:[[…]]内联文本的表示方式,使用时,必须先用th:inline=”text/javascript/none”激活,th:inline可以在父级标签内使用,甚至作为body的标签。内联文本尽管比th:text的代码少,不利于原型显示。<br />  </p> <pre> <code class="language-html"><script th:inline="javascript"> /*<![CDATA[*/ ... var username = /*[[${sesion.user.name}]]*/ 'Sebastian'; var size = /*[[${size}]]*/ 0; ... /*]]>*/ </script></code></pre> js附加代码: <pre> <code class="language-html">/*[+ var msg = 'This is a working application'; +]*/</code></pre> js移除代码: <pre> <code class="language-html">/*[- */ var msg = 'This is a non-working template'; /* -]*/</code></pre> <h3>6、内嵌变量</h3> <p>为了模板更加易用,Thymeleaf还提供了一系列Utility对象(内置于Context中),可以通过#直接访问:</p> <ul> <li> <p>dates :  <em>java.util.Date的功能方法类。</em></p> </li> <li> <p>calendars :<em>类似#dates,面向java.util.Calendar</em></p> </li> <li> <p>numbers : <em>格式化数字的功能方法类</em></p> </li> <li> <p>strings :  <em>字符串对象的功能类,contains,startWiths,prepending/appending等等。</em></p> </li> <li> <p>objects:  <em>对objects的功能类操作。</em></p> </li> <li> <p>bools:  <em>对布尔值求值的功能方法。</em></p> </li> <li> <p>arrays:<em>对数组的功能类方法。</em></p> </li> <li> <p>lists:   <em>对lists功能类方法</em></p> </li> <li> <p>sets</p> </li> <li> <p>maps<br /> …</p> </li> </ul> <p>下面用一段代码来举例一些常用的方法:</p> <h4>dates</h4> <pre> <code class="language-html">/* * Format date with the specified pattern * Also works with arrays, lists or sets */ ${#dates.format(date, 'dd/MMM/yyyy HH:mm')} ${#dates.arrayFormat(datesArray, 'dd/MMM/yyyy HH:mm')} ${#dates.listFormat(datesList, 'dd/MMM/yyyy HH:mm')} ${#dates.setFormat(datesSet, 'dd/MMM/yyyy HH:mm')} /* * Create a date (java.util.Date) object for the current date and time */ ${#dates.createNow()} /* * Create a date (java.util.Date) object for the current date (time set to 00:00) */ ${#dates.createToday()}</code></pre> <h4>strings</h4> <pre> <code class="language-html">/* * Check whether a String is empty (or null). Performs a trim() operation before check * Also works with arrays, lists or sets */ ${#strings.isEmpty(name)} ${#strings.arrayIsEmpty(nameArr)} ${#strings.listIsEmpty(nameList)} ${#strings.setIsEmpty(nameSet)} /* * Check whether a String starts or ends with a fragment * Also works with arrays, lists or sets */ ${#strings.startsWith(name,'Don')} // also array*, list* and set* ${#strings.endsWith(name,endingFragment)} // also array*, list* and set* /* * Compute length * Also works with arrays, lists or sets */ ${#strings.length(str)} /* * Null-safe comparison and concatenation */ ${#strings.equals(str)} ${#strings.equalsIgnoreCase(str)} ${#strings.concat(str)} ${#strings.concatReplaceNulls(str)} /* * Random */ ${#strings.randomAlphanumeric(count)}</code></pre> <h2>使用thymeleaf布局</h2> <p>使用thymeleaf布局非常的方便</p> <p>定义代码片段</p> <pre> <code class="language-html"><footer th:fragment="copy"> &copy; 2016 </footer></code></pre> <p>在页面任何地方引入:</p> <pre> <code class="language-html"><body>  <div th:include="footer :: copy"></div>  <div th:replace="footer :: copy"></div> </body></code></pre> <p>th:include 和 th:replace区别,include只是加载,replace是替换</p> <p>返回的HTML如下:</p> <pre> <code class="language-html"><body>   <div> &copy; 2018 </div>  <footer>&copy; 2018 </footer> </body></code></pre> <p>下面是一个常用的后台页面布局,将整个页面分为头部,尾部、菜单栏、隐藏栏,点击菜单只改变content区域的页面</p> <pre> <code class="language-html"><body class="layout-fixed">  <div th:fragment="navbar"  class="wrapper"  role="navigation">    <div th:replace="fragments/header :: header">Header</div>    <div th:replace="fragments/left :: left">left</div>    <div th:replace="fragments/sidebar :: sidebar">sidebar</div>    <div layout:fragment="content" id="content" ></div>    <div th:replace="fragments/footer :: footer">footer</div>  </div> </body></code></pre> <p>任何页面想使用这样的布局值只需要替换中见的 content模块即可</p> <pre> <code class="language-html"> <html xmlns:th="http://www.thymeleaf.org" layout:decorator="layout">   <body>      <section layout:fragment="content">    ...</code></pre> <p>也可以在引用模版的时候传参</p> <pre> <code class="language-html"><head th:include="layout :: htmlhead" th:with="title='Hello'"></head></code></pre> <p>layout 是文件地址,如果有文件夹可以这样写  fileName/layout:htmlhead<br /> htmlhead 是指定义的代码片段 如 <code>th:fragment="copy"</code></p>
  • DbVisualizer pro10.0 激活绿色版下载

    DbVisualizer pro10.0 激活绿色版下载,DbVisualizer 10.0下载,DbVisualizer是一个完全基于JDBC的跨平台数据库管理工具,内置SQL语句编辑器(支持语法高亮),凡是具有JDBC数据库接口的数据库都可以管理,已经在Oracle, Sybase, DB2, Informix, MySQL, InstantDB, Cloudcape, HyperSonic ,Mimer SQL上通过测试.<h2>DbVisualizer pro10.0 激活绿色版下载</h2> <br /> 简介:<br />     DbVisualizer是一个完全基于JDBC的跨平台数据库管理工具,内置SQL语句编辑器(支持语法高亮),凡是具有JDBC数据库接口的数据库都可以管理,已经在Oracle, Sybase, DB2, Informix, MySQL, InstantDB, Cloudcape, HyperSonic ,Mimer SQL上通过测试.<br /> <br /> 绿化说明:<br /> 1.添加jre8运行环境<br /> 2.默认pro版本<br /> 3.快捷键修改<br />     块及注释ctrl+shift+/ <br />     行及注释:ctrl+/<br />     自动补全:alt+/<br /> 4.设置默认字体为宋体<br /> <br /> 使用说明:<br /> 双机绿化安装,等待完成即可<br /> <br /> <span style="color:#16a085"><strong>下载地址:<a href="http://www.leftso.com/resource/1000.html" target="_blank" >点击前往</a></strong></span><br /> 统一解压密码:<strong>leftso.com</strong><br />   <h2>DbVisualizer 10.0.6</h2> <h3>Enhancement</h3> <table cellpadding="2" cellspacing="0" class="table table-bordered table-hover" > <tbody> <tr> <td><strong>DB Support: Oracle</strong></td> <td>Add support for IDENTITY and Virtual columns when generating DDL</td> </tr> </tbody> </table>   <h2>DbVisualizer 10.0.5更新日志</h2> <h3>Enhancement</h3> <table cellpadding="2" cellspacing="0" class="table table-bordered table-hover" > <tbody> <tr> <td><strong>DB Support: Exasol</strong></td> <td>Add database type and driver entry for Exasol</td> </tr> <tr> <td><strong>Export</strong></td> <td>Apply a Style matching the data format specified in DbVisualizer for numeric data</td> </tr> <tr> <td><strong>Grid Component</strong></td> <td>Add quick link to the Data Formats setup in Tool Properties also for BLOB and CLOB in the grids status bar</td> </tr> <tr> <td><strong>SQL Commander</strong></td> <td>Should be possible to disable error markers in the SQL Commander editor</td> </tr> <tr> <td><strong>SQL Editor</strong></td> <td>Add means to add custom keywords for syntax highlighting</td> </tr> <tr> <td><strong>SQL Editor</strong></td> <td>Add key bindings (alt-shift-up, alt-shift-down) to move selected rows up or down <br /> [<a href="http://support.dbvis.com/support/discussions/topics/1000076593" rel="external nofollow" target="_blank" >http://support.dbvis.com/support/discussions/topics/1000076593 </a>]</td> </tr> <tr> <td><strong>SQL Editor</strong></td> <td>Add a Duplicate Current Line editor action with option to set keybinding (is not assigned by default) <br /> [<a href="http://support.dbvis.com/support/discussions/topics/1000076655" rel="external nofollow" target="_blank" >http://support.dbvis.com/support/discussions/topics/1000076655 </a>]</td> </tr> <tr> <td><strong>SQL Log</strong></td> <td>Make it possible set the default column width for Message and SQL/Command multiline columns in the SQL Log</td> </tr> </tbody> </table>   <h2>DbVisualizer 10.0.4更新日志</h2> <h3>Enhancement</h3> <table cellpadding="2" cellspacing="0" class="table table-bordered table-hover" > <tbody> <tr> <td><strong>DB Support: Redshift</strong></td> <td>Add a Vacuum Table action</td> </tr> </tbody> </table> <h2>DbVisualizer 10.0.3更新日志:</h2> <h3>Enhancement</h3> <table cellpadding="2" cellspacing="0" class="table table-bordered table-hover" > <tbody> <tr> <td><strong>DB Support: PostgreSQL</strong></td> <td>XML type not supported in the create table wizard</td> </tr> <tr> <td><strong>Data tab</strong></td> <td>Setting "Max Rows at First Display" or any of the "Max Rows" to 0, should not load any rows</td> </tr> <tr> <td><strong>Export</strong></td> <td>Exporting with "Export Text" disabled should preserve data types not only for numbers but also date, time and timestamp when output is Excel <br /> [<a href="http://support.dbvis.com/support/discussions/topics/1000077122" rel="external nofollow" target="_blank" >http://support.dbvis.com/support/discussions/topics/1000077122 </a>]</td> </tr> <tr> <td><strong>Installation/Update Installation</strong></td> <td>Install4j should remember the last used download folder during updates <br /> [<a href="http://support.dbvis.com/support/discussions/topics/1000076802" rel="external nofollow" target="_blank" >http://support.dbvis.com/support/discussions/topics/1000076802 </a>]</td> </tr> <tr> <td><strong>Installation/Update Installation</strong></td> <td>Installer should request higher privileges when trying to install in a non-writable folder</td> </tr> <tr> <td><strong>Query Builder</strong></td> <td>Make it possible using keyboard to copy grid cells in the query builder</td> </tr> <tr> <td><strong>SQL Commander</strong></td> <td>The @cd command should set the default directory also for @export output files <br /> [<a href="http://support.dbvis.com/support/discussions/topics/1000076777" rel="external nofollow" target="_blank" >http://support.dbvis.com/support/discussions/topics/1000076777 </a>]</td> </tr> <tr> <td><strong>SQL Commander<br /> SQL Log</strong></td> <td>The STARTED log entry should show information about used database connection, database type, database, and schema <br /> [<a href="http://support.dbvis.com/support/discussions/topics/1000076568" rel="external nofollow" target="_blank" >http://support.dbvis.com/support/discussions/topics/1000076568 </a>]</td> </tr> <tr> <td><strong>SQL Formatter</strong></td> <td>Format only selected text and reselect the formatted text</td> </tr> <tr> <td><strong>Table Data Editor</strong></td> <td>The cell editor should allow dropping images, XML, and other file formats we have viewers for</td> </tr> </tbody> </table> <h3>DbVisualizer10.0.2更新日志:</h3> <h3>Enhancement</h3> <table cellpadding="2" cellspacing="0" class="table table-bordered table-hover" > <tbody> <tr> <td><strong>Database Profile: Actions<br /> DB Support: Vertica</strong></td> <td>Add a Purge Table action for a table in Vertica</td> </tr> <tr> <td><strong>Export<br /> Grid Component</strong></td> <td>Add a "Open as Spreadsheet" in grids</td> </tr> <tr> <td><strong>Favorites</strong></td> <td>Add shortcuts for Select Target Object in the Favorites toolbar (Alt+click) and the Favorites tab (Alt+double-click)</td> </tr> <tr> <td><strong>General</strong></td> <td>Allow scaling UI more than 200%</td> </tr> <tr> <td><strong>SQL Commander</strong></td> <td>Add a "Select Target Script File" in the SQL editor status bar filename right-click menu. Used to highlight any corresponding script file in the Scripts tab</td> </tr> </tbody> </table> <h3> </h3> <h2>DbVisualizer10.0.1更新日志:</h2> <h3>Enhancement</h3> <table cellpadding="2" cellspacing="0" class="table table-bordered table-hover" > <tbody> <tr> <td><strong>Database Objects Tree<br /> Filtering/Filter Sets</strong></td> <td>Disabled Filtering state should be restored when restarting DbVisualizer</td> </tr> <tr> <td><strong>Look and Feel: macOS<br /> Performance/Stability</strong></td> <td>DbVisualizer runs Java in discrete graphics mode on macOS potentially draining the battery on laptops</td> </tr> <tr> <td><strong>SQL Log</strong></td> <td>Need to make the summary of success/failed entries for the FINISHED summary log entry in the Message column more readable</td> </tr> </tbody> </table> <h3><br /> <em><strong><span style="color:#ff0000">该软件仅用于提供个人学习和交流使用,切勿商用。本人及本网站不承担任何因此软件发生的纠纷责任</span></strong></em><span style="color:#ff0000"><em><strong>。</strong></em></span></h3>
  • mysql数据库日期类型条件查询传入的参数是字符串

    在MySQL或者各种数据库中,都很大可能使用到日期类型。在Java代码中进行日期转换还是比较容易的。但是大多数时候日期的参数都是字符串。而且在工具中使用字符串的方式来表达时间比较方便。这里记录下MySQL中字符串转换为日期进行比较的方法。<h2>背景</h2>   在MySQL或者各种数据库中,都很大可能使用到日期类型。在Java代码中进行日期转换还是比较容易的。但是大多数时候日期的参数都是字符串。而且在工具中使用字符串的方式来表达时间比较方便。这里记录下MySQL中字符串转换为日期进行比较的方法。 <h2>MySQL日期查询SQL语句</h2> <pre> <code class="language-sql">SELECT * FROM tb_student a WHERE DATE_FORMAT(a.createTime, '%Y-%m-%d') >= DATE_FORMAT('2017-09-17', '%Y-%m-%d');</code></pre> 说明:createTime即为创建时间。数据库类型为datetime类型。MySQL中使用DATE_FORMAT函数进行转换然后比较。<br /> <br /> 表达式中的其他格式参数如下表: <table class="table table-hover"> <tbody> <tr> <th>格式</th> <th>描述</th> </tr> <tr> <td>%a</td> <td>缩写星期名</td> </tr> <tr> <td>%b</td> <td>缩写月名</td> </tr> <tr> <td>%c</td> <td>月,数值</td> </tr> <tr> <td>%D</td> <td>带有英文前缀的月中的天</td> </tr> <tr> <td>%d</td> <td>月的天,数值(00-31)</td> </tr> <tr> <td>%e</td> <td>月的天,数值(0-31)</td> </tr> <tr> <td>%f</td> <td>微秒</td> </tr> <tr> <td>%H</td> <td>小时 (00-23)</td> </tr> <tr> <td>%h</td> <td>小时 (01-12)</td> </tr> <tr> <td>%I</td> <td>小时 (01-12)</td> </tr> <tr> <td>%i</td> <td>分钟,数值(00-59)</td> </tr> <tr> <td>%j</td> <td>年的天 (001-366)</td> </tr> <tr> <td>%k</td> <td>小时 (0-23)</td> </tr> <tr> <td>%l</td> <td>小时 (1-12)</td> </tr> <tr> <td>%M</td> <td>月名</td> </tr> <tr> <td>%m</td> <td>月,数值(00-12)</td> </tr> <tr> <td>%p</td> <td>AM 或 PM</td> </tr> <tr> <td>%r</td> <td>时间,12-小时(hh:mm:ss AM 或 PM)</td> </tr> <tr> <td>%S</td> <td>秒(00-59)</td> </tr> <tr> <td>%s</td> <td>秒(00-59)</td> </tr> <tr> <td>%T</td> <td>时间, 24-小时 (hh:mm:ss)</td> </tr> <tr> <td>%U</td> <td>周 (00-53) 星期日是一周的第一天</td> </tr> <tr> <td>%u</td> <td>周 (00-53) 星期一是一周的第一天</td> </tr> <tr> <td>%V</td> <td>周 (01-53) 星期日是一周的第一天,与 %X 使用</td> </tr> <tr> <td>%v</td> <td>周 (01-53) 星期一是一周的第一天,与 %x 使用</td> </tr> <tr> <td>%W</td> <td>星期名</td> </tr> <tr> <td>%w</td> <td>周的天 (0=星期日, 6=星期六)</td> </tr> <tr> <td>%X</td> <td>年,其中的星期日是周的第一天,4 位,与 %V 使用</td> </tr> <tr> <td>%x</td> <td>年,其中的星期一是周的第一天,4 位,与 %v 使用</td> </tr> <tr> <td>%Y</td> <td>年,4 位</td> </tr> <tr> <td>%y</td> <td>年,2 位</td> </tr> </tbody> </table> <br /> 更多技术博客请浏览<a rel="" target="_blank" href="http://www.leftso.com">左搜技术博客</a>首页查看
  • centos6 redis3.29 安装(yum和源码安装)完整步骤以及常用配置

    centos6 yum安装redis3.29,centos6 源码安装redis以及常用配置<h2>一、 <span style="font-family:宋体">检查</span>yum<span style="font-family:宋体">可以安装的版本</span></h2> <h3>1.1<span style="font-family:宋体">查看当前系统可以安装的</span>redis<span style="font-family:宋体">版本</span></h3> <p><span style="font-family:宋体">命令</span>:</p> <p><strong>[root@localhost ~]# yum list|grep redis</strong></p> <p>[root@localhost ~]#</p> <p> </p> <p><span style="font-family:宋体">发现没有可以安装的</span>,<span style="font-family:宋体">如果有则忽略下面的步骤</span></p> <h3>1.2<span style="font-family:宋体">安装</span>centos<span style="font-family:宋体">提供的</span>epel-release<span style="font-family:宋体">源</span></h3> <p><span style="font-family:宋体">命令</span>:</p> <pre> <code class="language-java">[root@localhost ~]# yum install epel-release</code></pre> <p><img alt="1" class="img-thumbnail" src="/assist/images/blog/a4ba199bfd204d84bbdd4bac341c08aa.png" /></p> <p><span style="font-family:宋体">安装好以后再次查看可以安装的</span>redis<span style="font-family:宋体">版本</span></p> <p><span style="font-family:宋体">命令</span>:</p> <pre> <code class="language-java">[root@localhost ~]# yum list|grep redis php-nrk-Predis.noarch                       0.8.6-1.el6                  epel   php-pecl-redis.x86_64                       2.2.8-1.el6                  epel   php-redis.x86_64                            2.2.2-5.git6f7087f.el6       epel   python-redis.noarch                         2.0.0-1.el6                  epel   redis.x86_64                                2.4.10-1.el6                 epel   uwsgi-logger-redis.x86_64                   2.0.15-1.el6                 epel   uwsgi-router-redis.x86_64                   2.0.15-1.el6                 epel   [root@localhost ~]#</code></pre> <p><span style="font-family:宋体">现在有了可以安装的版本了。但是版本还是太低是</span>2.4<span style="font-family:宋体">的版本。</span></p> <p><span style="font-family:宋体">结论</span>:CentOS6<span style="font-family:宋体">不能直接通过</span>yum<span style="font-family:宋体">安装</span>redis3.X<span style="font-family:宋体">版本。需要源码安装</span>,centos7<span style="font-family:宋体">则可以。具体安装方式可根据使用的系统版本来抉择。</span></p> <p> </p> <h2 style="margin-left:36.0pt">二、 <span style="font-family:宋体">获取</span>redis<span style="font-family:宋体">安装资源以及环境</span></h2> <h3>2.1<span style="font-family:宋体">下载</span>redis<span style="font-family:宋体">的安装文件包</span></h3> <p><span style="font-family:宋体">官网地址</span>: <a href="https://redis.io/download" rel="external nofollow" target="_blank">https://redis.io/download</a></p> <p>Redis 3.2.9<span style="font-family:宋体">下载地址</span>: <a href="http://download.redis.io/releases/redis-3.2.9.tar.gz" rel="external nofollow" target="_blank">http://download.redis.io/releases/redis-3.2.9.tar.gz</a></p> <p> </p> <p><span style="font-family:宋体">直接下载命令</span>:</p> <pre> <code class="language-java">[root@localhost ~]# wget http://download.redis.io/releases/redis-3.2.9.tar.gz</code></pre> <p><span style="font-family:宋体">下载完成后在当前目录会有</span>redis-3.2.9.tar.gz<span style="font-family:宋体">包</span></p> <p><img alt="2" class="img-thumbnail" src="/assist/images/blog/72c50fea69174343b711b862b7c7a1d2.png" /></p> <p> </p> <h3>2.2<span style="font-family:宋体">检查</span>gcc<span style="font-family:宋体">环境</span></h3> <p><span style="font-family:宋体">检查系统中是否有</span>gcc<span style="font-family:宋体">编译器</span>,<span style="font-family:宋体">因为源码安装需要使用</span>gcc<span style="font-family:宋体">编译</span></p> <p><span style="font-family:宋体">命令</span>:</p> <pre> <code class="language-java">[root@localhost ~]# rpm -qa|grep gcc gcc-4.4.7-4.el6.x86_64 libgcc-4.4.7-4.el6.x86_64 [root@localhost ~]#</code></pre> <p><span style="font-family:宋体">上面的命令执行结果标识系统已经安装有</span>gcc<span style="font-family:宋体">编译器</span>,<span style="font-family:宋体">如果没有则执行下面的命令</span>,<span style="font-family:宋体">有则忽略下面步骤</span></p> <p><span style="font-family:宋体">安装</span>GCC<span style="font-family:宋体">命令</span></p> <pre> <code>[root@localhost ~]# yum install –y gcc</code></pre> <p> </p> <h2><span style="font-family:宋体">三、安装</span>redis</h2> <h3>3.1<span style="font-family:宋体">创建</span>redis<span style="font-family:宋体">安装目录</span></h3> <p><span style="font-family:宋体">命令</span>:</p> <pre> <code class="language-java">[root@localhost ~]# mkdir -p /usr/local/redis-3.2.9 [root@localhost ~]#</code></pre> <h3>3.2<span style="font-family:宋体">解压下载的</span>redis<span style="font-family:宋体">安装文件</span></h3> <p><span style="font-family:宋体">命令</span>:</p> <pre> <code class="language-java">[root@localhost ~]# tar -xzvf redis-3.2.9.tar.gz</code></pre> <h3>3.3<span style="font-family:宋体">指定安装目录安装</span>redis</h3> <p><span style="font-family:宋体">首先进入解压后的</span>redis<span style="font-family:宋体">目录</span></p> <p><span style="font-family:宋体">命令</span>:</p> <pre> <code class="language-java">[root@localhost ~]# cd redis-3.2.9 [root@localhost redis-3.2.9]#</code></pre> <p><span style="font-family:宋体">指定目录安装</span>redis</p> <p><span style="font-family:宋体">命令</span>:</p> <pre> <code class="language-java">[root@localhost redis-3.2.9]#make PREFIX=/usr/local/redis-3.2.9 install</code></pre> <p><img alt="3" class="img-thumbnail" src="/assist/images/blog/dc50ab10f63249c8ad7ae52bd5a5137d.png" /></p> <h3>3.4<span style="font-family:宋体">创建一个软连接方便访问寻找</span></h3> <p><span style="font-family:宋体">命令</span>:</p> <pre> <code class="language-java">ln -s /usr/local/redis-3.2.9 /usr/local/redis</code></pre> <p> </p> <h2><span style="font-family:宋体">四、配置</span>redis</h2> <h3>4.1<span style="font-family:宋体">添加配置文件到</span>/etc<span style="font-family:宋体">目录</span></h3> <p><span style="font-family:宋体">默认的</span>redis<span style="font-family:宋体">配置文件还在刚才解压的文件目录中</span>,<span style="font-family:宋体">在</span>Linux<span style="font-family:宋体">系统使用中,通常把配置的文件放在</span>/etc<span style="font-family:宋体">目录下。算一个规范。</span></p> <p> </p> <p><span style="font-family:宋体">将源码目录下的</span>redis<span style="font-family:宋体">配置文件添加一份到</span>/etc<span style="font-family:宋体">目录下</span></p> <p><span style="font-family:宋体">命令</span>:</p> <pre> <code class="language-java">[root@localhost redis-3.2.9]# pwd /root/redis-3.2.9 [root@localhost redis-3.2.9]# ll redis.conf -rw-rw-r--. 1 root root 46695 May 17 08:39 redis.conf [root@localhost redis-3.2.9]# cp redis.conf /etc/redis.conf</code></pre> <h3>4.2.<span style="font-family:宋体">修改</span>redis<span style="font-family:宋体">默认以后台进程方式启动</span></h3> <p><span style="font-family:宋体">编辑</span>/etc/redis.conf<span style="font-family:宋体">配置</span>redis<span style="font-family:宋体">以后台方式启动</span></p> <pre> <code class="language-java">[root@localhost redis-3.2.9]# vi /etc/redis.conf</code></pre> <p><img alt="4" class="img-thumbnail" src="/assist/images/blog/a9e3c8b8406a45f58c4eee2f385a35e4.png" /></p> <p><span style="font-family:宋体">在文件中找到</span>daemonize<span style="font-family:宋体">配置</span>,<span style="font-family:宋体">默认是</span>no,<span style="font-family:宋体">修改成</span>yes</p> <p><img alt="5" class="img-thumbnail" src="/assist/images/blog/f498bccd0e494038a896ce370945ced0.png" /></p> <p><span style="color:#e74c3c"><strong><span style="font-family:宋体">提示</span>:</strong><em><span style="font-family:宋体">配置文件配置项后面不要有空格</span></em></span></p> <p> </p> <h3>4.3<span style="font-family:宋体">配置</span>redis<span style="font-family:宋体">允许远程访问</span></h3> <p><span style="font-family:宋体">编辑</span>/etc/redis.conf<span style="font-family:宋体">配置</span>redis<span style="font-family:宋体">允许远程访问</span></p> <pre> <code class="language-java">[root@localhost redis-3.2.9]# vi /etc/redis.conf</code></pre> <p><img alt="6" class="img-thumbnail" src="/assist/images/blog/5ac5d3d3ca214782b9a76513b1cde8fc.png" /></p> <p><span style="font-family:宋体">将</span>bind 127.0.0.1<span style="font-family:宋体">注释掉即可随意访问,如果不注释则只能通过bind后面的ip进行访问。如:</span><br />  </p> <pre> <code>bind 127.0.0.1 192.168.1.3</code></pre> <p><span style="color:#e74c3c"><strong>上面的配置标识只能本地或者访问自己的ip地址192.168.1.3进行访问</strong></span><br /> <br /> 为了测试方便,注释掉即可。生产请bind自己主机的局域网IP地址<br /> <br /> <img alt="7" class="img-thumbnail" src="/assist/images/blog/3608e0016dc647e08bfa2c0fe5c4ac00.png" /></p> <p><span style="font-family:宋体">但是远程访问还不能读写</span>,<span style="font-family:宋体">所以继续配置</span></p> <p><span style="font-family:宋体">找到</span>protected-mode yes(<span style="color:#8e44ad"><strong>如果使用bind的方式则不需要修改</strong></span>)</p> <p><img alt="8" class="img-thumbnail" src="/assist/images/blog/0d331967cc774469a18bfbc4e41afaf8.png" /></p> <p><span style="font-family:宋体">修改为</span>protected-mode no</p> <p><img alt="9" class="img-thumbnail" src="/assist/images/blog/50f6d50040ee4b29bf59e28ca86992f2.png" /></p> <p> </p> <h3>4.4<span style="font-family:宋体">配置</span>redis<span style="font-family:宋体">访问密码</span></h3> <p><span style="font-family:宋体">编辑</span>/etc/redis.conf<span style="font-family:宋体">配置</span>redis<span style="font-family:宋体">设置访问密码</span></p> <p><span style="font-family:宋体">找到配置文件中的</span><span style="background-color:white"><span style="font-family:Consolas"><span style="color:black">requirepass</span></span></span><span style="background-color:white"><span style="font-family:宋体"><span style="color:black">配置</span></span></span></p> <p><img alt="10" class="img-thumbnail" src="/assist/images/blog/f1c0f305ea6f4d7b8ef3601467340781.png" /></p> <p><span style="font-family:宋体">默认情况是注释的</span>,<span style="font-family:宋体">配置的</span><span style="background-color:white"><span style="font-family:Consolas"><span style="color:black">requirepass </span></span></span><span style="background-color:white"><span style="font-family:宋体"><span style="color:black">后面跟的</span></span></span><span style="background-color:white"><span style="font-family:Consolas"><span style="color:black">foobared</span></span></span><span style="background-color:white"><span style="font-family:宋体"><span style="color:black">就是密码</span></span></span></p> <p><span style="background-color:white"><span style="font-family:宋体"><span style="color:black">例如现在启用密码</span></span></span><span style="background-color:white"><span style="font-family:Consolas"><span style="color:black">,</span></span></span><span style="background-color:white"><span style="font-family:宋体"><span style="color:black">并且将密码设置为</span></span></span><span style="background-color:white"><span style="font-family:Consolas"><span style="color:black">123456</span></span></span><span style="background-color:white"><span style="font-family:宋体"><span style="color:black">,则配置为</span></span></span><span style="background-color:white"><span style="font-family:Consolas"><span style="color:black">:</span></span></span></p> <p><img alt="11" class="img-thumbnail" src="/assist/images/blog/c39435d76b21443f8043f387536d662e.png" /></p> <p><span style="font-family:宋体">去掉</span>#<span style="font-family:宋体">并将后面的密码修改为</span>123456</p> <p><span style="color:#e74c3c"><strong><span style="font-family:宋体">提示</span></strong><em>:</em><em><span style="font-family:宋体">配置前后不要留空格</span></em></span><br />  </p> <span style="font-family:宋体">配置redis最大使用内存以及超出最大内存后的处理策略</span><br />   <p><strong>#maxmemory </strong><strong><bytes></strong></p> <p>redis-cache所能使用的最大内存(bytes),默认为0,表示"无限制",最终由OS物理内存大小决定(如果物理内存不足,有可能会使用swap)。此值尽量不要超过机器的物理内存尺寸,从性能和实施的角度考虑,可以为物理内存3/4。此配置需要和"maxmemory-policy"配合使用,当redis中内存数据达到maxmemory时,触发"清除策略"。在"内存不足"时,任何write操作(比如set,lpush等)都会触发"清除策略"的执行。在实际环境中,建议redis的所有物理机器的硬件配置保持一致(内存一致),同时确保master/slave中"maxmemory""policy"配置一致。</p> <p>当内存满了的时候,如果还接收到set 命令,redis 将先尝试剔除设置过expire 信息的key,而不管该key 的过期时间还没有到达。在删除时,</p> <p>将按照过期时间进行删除,最早将要被过期的key 将最先被删除。如果带有expire 信息的key 都删光了,内存还不够用,那么将返回错误。这样,redis 将不再接收写请求,只接收get 请求。maxmemory 的设置比较适合于把redis 当作于类似memcached的缓存来使用。</p> <p><strong># maxmemory-policy noeviction</strong></p> <p>内存不足"时,数据清除策略,默认为"noeviction。</p> <p><em>volatile-lru</em>  ->对"过期集合"中的数据采取LRU(近期最少使用)算法.如果对key使用"expire"指令指定了过期时间,那么此key将会被添加到"过期集合"中。将已经过期/LRU的数据优先移除.如果"过期集合"中全部移除仍不能满足内存需求,将OOM.<br /> <em>allkeys-lru</em> ->对所有的数据,采用LRU算法<br /> <em>volatile-random</em> ->对"过期集合"中的数据采取"随即选取"算法,并移除选中的K-V,直到"内存足够"为止. 如果如果"过期集合"中全部移除全部移除仍不能满足,将OOM<br /> <em>allkeys-random</em> ->对所有的数据,采取"随机选取"算法,并移除选中的K-V,直到"内存足够"为止<br /> <em>volatile-ttl</em> ->对"过期集合"中的数据采取TTL算法(最小存活时间),移除即将过期的数据.<br /> <em>noeviction</em> ->不做任何干扰操作,直接返回OOM异常<br /> 另外,如果数据的过期不会对"应用系统"带来异常,且系统中write操作比较密集,建议采取"allkeys-lru"<br /> <br /> <strong>举个栗子:</strong><br /> 配置最大使用内存2GB,超出后对不常使用的缓存清理,快过期缓存清理的配置为:</p> <pre> <code>#设置默认内存大小3GB maxmemory 3GB #设置清楚策略allkeys-lru maxmemory-policy allkeys-lru</code></pre> <h3>4.5<span style="font-family:宋体">创建</span>redis<span style="font-family:宋体">用户</span></h3> <p><span style="font-family:宋体">命令</span>:</p> <pre> <code class="language-java"># useradd -r -s /sbin/nologin -M redis</code></pre> <p>4.6<span style="font-family:宋体">创建</span>redis<span style="font-family:宋体">启动弄脚本便于使用</span>service<span style="font-family:宋体">管理</span>redis</p> <p><strong><span style="font-family:宋体">命令</span>:</strong></p> <pre> <code class="language-java">#vi  /etc/init.d/redis</code></pre> <p><span style="font-family:宋体">脚本内容</span>:<br />  </p> <pre> <code class="language-bash">#!/bin/bash #chkconfig: 2345 55 25 #description: Starts,stops and restart the redis-server #Ver:1.1  #Write by ND chengh(200808) #usage: ./script_name -p [port] {start|stop|status|restart} # Source function library. . /etc/rc.d/init.d/functions # Source networking configuration. . /etc/sysconfig/network # Check networking is up. [ "$NETWORKING" = "no" ] && exit 0 RETVAL=0 REDIS_PORT=6379 PID= if [ "$1" = "-p" ]; then     REDIS_PORT=$2     shift 2 fi REDIS_DIR="/usr/local/redis" REDIS_CONF_DIR="/etc" REDIS="${REDIS_DIR}/bin/redis-server" PROG=$(basename $REDIS) CONF="${REDIS_CONF_DIR}/redis-${REDIS_PORT}.conf" if [ ! -f $CONF ]; then    if [ -f "${REDIS_CONF_DIR}/redis.conf" ];then       CONF="${REDIS_CONF_DIR}/redis.conf"    else       echo -n $"$CONF not exist.";warning;echo       exit 1    fi fi PID_FILE=`grep "pidfile" ${CONF}|cut -d ' ' -f2` PID_FILE=${PID_FILE:=/var/run/redis.pid} LOCKFILE="/var/lock/subsys/redis-${REDIS_PORT}" if [ ! -x $REDIS ]; then     echo -n $"$REDIS not exist.";warning;echo     exit 0 fi start() {     echo -n $"Starting $PROG: "     $REDIS $CONF     RETVAL=$?     if [ $RETVAL -eq 0 ]; then         success;echo;touch $LOCKFILE     else         failure;echo     fi     return $RETVAL } stop() {     echo -n $"Stopping $PROG: "     if [ -f $PID_FILE ] ;then        read PID <  "$PID_FILE"     else        failure;echo;        echo -n $"$PID_FILE not found.";failure;echo        return 1;     fi     if checkpid $PID; then      kill -TERM $PID >/dev/null 2>&1         RETVAL=$?         if [ $RETVAL -eq 0 ] ;then                 success;echo                 echo -n "Waiting for Redis to shutdown .."          while checkpid $PID;do                  echo -n "."                  sleep 1;                 done                 success;echo;rm -f $LOCKFILE         else                 failure;echo         fi     else         echo -n $"Redis is dead and $PID_FILE exists.";failure;echo         RETVAL=7     fi        return $RETVAL } restart() {     stop     start } rhstatus() {     status -p ${PID_FILE} $PROG } hid_status() {     rhstatus >/dev/null 2>&1 } case "$1" in     start)         hid_status && exit 0         start         ;;     stop)         rhstatus || exit 0         stop         ;;     restart)         restart         ;;     status)         rhstatus         RETVAL=$?         ;;     *)         echo $"Usage: $0 -p [port] {start|stop|status|restart}"         RETVAL=1 esac exit $RETVAL </code></pre> <p><span style="background-color:#fafafc"><span style="font-family:宋体"><span style="color:#333333">上面脚本中可根据具体</span></span></span><span style="background-color:#fafafc"><span style="font-family:"Tahoma",sans-serif"><span style="color:#333333">redis</span></span></span><span style="background-color:#fafafc"><span style="font-family:宋体"><span style="color:#333333">安装位置配置</span></span></span><span style="background-color:#fafafc"><span style="font-family:"Tahoma",sans-serif"><span style="color:#333333">redis-server</span></span></span><span style="background-color:#fafafc"><span style="font-family:宋体"><span style="color:#333333">的路径和</span></span></span><span style="background-color:#fafafc"><span style="font-family:"Tahoma",sans-serif"><span style="color:#333333">conf</span></span></span><span style="background-color:#fafafc"><span style="font-family:宋体"><span style="color:#333333">的路径</span></span></span></p> <p><span style="background-color:#fafafc"><span style="font-family:"Tahoma",sans-serif"><span style="color:#333333">redis</span></span></span><span style="background-color:#fafafc"><span style="font-family:宋体"><span style="color:#333333">默认安装在</span></span></span></p> <p><span style="background-color:#fafafc"><span style="font-family:"Tahoma",sans-serif"><span style="color:#333333">/usr/local/redis</span></span></span><span style="background-color:#fafafc"><span style="font-family:宋体"><span style="color:#333333">目录下</span></span></span></p> <p><span style="background-color:#fafafc"><span style="font-family:"Tahoma",sans-serif"><span style="color:#333333">Redis</span></span></span><span style="background-color:#fafafc"><span style="font-family:宋体"><span style="color:#333333">配置文件存放在</span></span></span></p> <p><span style="background-color:#fafafc"><span style="font-family:"Tahoma",sans-serif"><span style="color:#333333">/etc/redis.conf</span></span></span></p> <p> </p> <p><span style="background-color:#fafafc"><span style="font-family:宋体"><span style="color:#333333">修改脚本权限</span></span></span></p> <pre> <code class="language-java">#chmod 755 /etc/init.d/redis</code></pre> <p> </p> <p><span style="font-family:宋体">添加进</span>service<span style="font-family:宋体">管理</span></p> <pre> <code class="language-java">#chkconfig --add redis</code></pre> <p> </p> <p><span style="font-family:宋体">设置开机启动</span></p> <pre> <code class="language-java"># chkconfig redis on</code></pre> <p>4.7<span style="font-family:宋体">启动</span>redis</p> <pre> <code class="language-java">[root@localhost redis-3.2.9]# service redis start Starting redis-server:                                     [  OK  ]</code></pre> <p><img alt="12" class="img-thumbnail" src="/assist/images/blog/3c9b6e9d57104e82a82649a844c5b1d8.png" /></p> <p> </p> <h2><span style="font-family:宋体">五、连接到</span>redis<span style="font-family:宋体">测试</span></h2> <p><span style="font-family:宋体">连接命令</span>:</p> <pre> <code class="language-java">#/usr/local/redis/bin/redis-cli -h 127.0.0.1 -p 6379</code></pre> <p> </p> <p><span style="font-family:宋体">设置一个值</span>:</p> <pre> <code>127.0.0.1:6379> set testKey testValue</code></pre> <p><img alt="13" class="img-thumbnail" src="/assist/images/blog/963b924d72964889b49019bfa0695e2d.png" /></p> <p><span style="font-family:宋体">获取上面的设置值</span></p> <p><span style="font-family:宋体">命令</span>:</p> <pre> <code>127.0.0.1:6379> get testKey</code></pre> <p><img alt="14" class="img-thumbnail" src="/assist/images/blog/82deb7d506ea4673970ad757e8f5492c.png" /></p> <p>删除上面的值<br /> 命令</p> <pre> <code>del testKey</code></pre> <p><br />  </p>
  • MySQL5.6配置双机互为主备

    MySQL5.6配置双机互为主备<h2><span style="font-family:宋体">一准备</span></h2> <p><span style="font-family:宋体">首先需要两个</span>MySQL<span style="font-family:宋体">数据库服务器</span></p> <p><span style="font-family:宋体">假如</span>:</p> <p><span style="font-family:宋体">数据库服务器</span>1<span style="font-family:宋体">信息</span></p> <p>192.168.8.202 3306 root root</p> <p><span style="font-family:宋体">数据库服务器</span>2<span style="font-family:宋体">信息</span></p> <p>192.168.8.203 3360 root root</p> <p> </p> <h2><span style="font-family:宋体">二、数据库</span>1<span style="font-family:宋体">配置</span></h2> <h3>2.1<span style="font-family:宋体">修改数据库</span>1<span style="font-family:宋体">配置</span></h3> <p><span style="font-family:宋体">编辑数据库</span>1<span style="font-family:宋体">的配置文件</span>/etc/my.cnf</p> <p><span style="font-family:宋体">在</span>[mysqld]<span style="font-family:宋体">节点下添加</span>:</p> <pre> <code>#######主从配置master信息####### #[必须]服务器唯一ID,默认是1,一般取IP最后一段 server_id=202 #[必须]启用二进制日志 log_bin=mysql-bin #需要备份的数据库名  多个库写多行 binlog-do-db=test #忽略备份数据库名 多个库写多行 #binlog-ignore-db=mysql #若涉及及同步函数或者存储过程需要配置,否则主备会产生异常不能同步 log_bin_trust_function_creators=TRUE #######主从配置master信息############ </code></pre> <p> </p> <p><img alt="1" class="img-thumbnail" src="/assist/images/blog/54fb33900cb949a2aea85ef489156cc6.png" /></p> <p> </p> <p><strong><span style="font-family:宋体"><span style="color:red">配置方式为指定数据库</span></span><span style="color:red">test</span></strong><strong><span style="font-family:宋体"><span style="color:red">同步</span></span></strong></p> <h3>2.2<span style="font-family:宋体">重启</span>MySQL<span style="font-family:宋体">服务</span></h3> <p><span style="font-family:宋体">重启数据库服务器</span>1<span style="font-family:宋体">的</span>MySQL<span style="font-family:宋体">服务</span></p> <p><span style="font-family:宋体">命令</span>:</p> <pre> <code>service mysqld restart</code></pre> <h3>2.3<span style="font-family:宋体">创建</span>slave<span style="font-family:宋体">用户</span></h3> <p><span style="font-family:宋体">创建一个</span>slave<span style="font-family:宋体">用户</span>,<span style="font-family:宋体">用于数据库服务器</span>2<span style="font-family:宋体">上进行同步</span></p> <p> </p> <p>Root<span style="font-family:宋体">登录</span>MySQL<span style="font-family:宋体">数据库</span></p> <pre> <code>[root@localhost ~]# mysql -uroot -proot</code></pre> <p> </p> <p><span style="font-family:宋体">创建</span>slave<span style="font-family:宋体">用户</span></p> <pre> <code>mysql> grant replication slave on *.* to 'slave'@'%' identified by '123456';</code></pre> <p> </p> <p><span style="font-family:宋体">切换至</span>mysql<span style="font-family:宋体">数据库</span>,<span style="font-family:宋体">查看刚才创建的用户信息</span></p> <pre> <code>mysql> 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 mysql> select * from user where User='slave' \G; *************************** 1. row ***************************                   Host: %                   User: slave               Password: *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9            Select_priv: N            Insert_priv: N            Update_priv: N            Delete_priv: N            Create_priv: N              Drop_priv: N            Reload_priv: N          Shutdown_priv: N           Process_priv: N              File_priv: N             Grant_priv: N        References_priv: N             Index_priv: N             Alter_priv: N           Show_db_priv: N             Super_priv: N  Create_tmp_table_priv: N       Lock_tables_priv: N           Execute_priv: N        Repl_slave_priv: Y       Repl_client_priv: N       Create_view_priv: N         Show_view_priv: N    Create_routine_priv: N     Alter_routine_priv: N       Create_user_priv: N             Event_priv: N           Trigger_priv: N Create_tablespace_priv: N               ssl_type:             ssl_cipher:            x509_issuer:           x509_subject:          max_questions: 0            max_updates: 0        max_connections: 0   max_user_connections: 0                 plugin: mysql_native_password  authentication_string:       password_expired: N 1 row in set (0.00 sec) ERROR: No query specified mysql></code></pre> <p><img alt="2" class="img-thumbnail" src="/assist/images/blog/d3716e0e60d7453290b3af342cf6878d.png" /></p> <p><span style="font-family:宋体">注意查看</span>: <strong><span style="color:red">Repl_slave_priv: Y</span></strong></p> <p><span style="font-family:宋体">是</span>Y<span style="font-family:宋体">标识该账户已经有权限操作同步了。</span></p> <h3>2.3<span style="font-family:宋体">备份数据库</span></h3> <p><span style="font-family:宋体">该操作主要是备份<strong>数据库服务器</strong></span><strong>1</strong><span style="font-family:宋体">中需要同步的数据库。(这里的同步数据库为</span>test<span style="font-family:宋体">库)</span></p> <p> </p> <ol start="7" style="list-style-type:lower-alpha"> <li value="176"><span style="font-family:宋体">锁表为只读状态</span></li> </ol> <p style="margin-left:18.0pt"><span style="font-family:宋体">锁表命令</span>:<br />  </p> <pre> <code>mysql> FLUSH TABLES WITH READ LOCK; Query OK, 0 rows affected (0.06 sec) </code></pre> <ol start="7" style="list-style-type:lower-alpha"> <li value="176"><span style="font-family:宋体">备份数据库</span>1<span style="font-family:宋体">数据</span></li> </ol> <p><span style="font-family:宋体">退出数据库或者新打开一个</span>ssh<span style="font-family:宋体">连接</span>,<span style="font-family:宋体">执行以下命令备份</span></p> <pre> <code>[root@localhost ~]# mysqldump -uroot -proot test > /root/test-db.sql</code></pre> <p><img alt="3" class="img-thumbnail" src="/assist/images/blog/22d428f5384146fda237607774502347.png" /></p> <p> </p> <p><span style="font-family:宋体">如图已经将</span>test<span style="font-family:宋体">库备份至</span>/root<span style="font-family:宋体">目录</span>,<span style="font-family:宋体">名称为</span>test-db.sql</p> <ol start="7" style="list-style-type:lower-alpha"> <li value="176"><span style="font-family:宋体">查看数据库服务器</span>1<span style="font-family:宋体">的</span>master<span style="font-family:宋体">信息</span></li> </ol> <p style="margin-left:18.0pt"><span style="font-family:宋体">登录数据库执行命令</span>:</p> <pre> <code>mysql> show master status; +------------------+----------+--------------+------------------+-------------------+ | File             | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set | +------------------+----------+--------------+------------------+-------------------+ | mysql-bin.000003 |      887 | test         |                  |                   | +------------------+----------+--------------+------------------+-------------------+ 1 row in set (0.00 sec) mysql></code></pre> <p><img alt="4" class="img-thumbnail" src="/assist/images/blog/74ce9951b1034a9088bc7daf619e1785.png" /></p> <p><strong><span style="font-family:宋体">记住这里的</span>file</strong><strong><span style="font-family:宋体">名称和</span>Position</strong><strong><span style="font-family:宋体">值</span></strong></p> <ol start="7" style="list-style-type:lower-alpha"> <li value="176"><span style="font-family:宋体">解锁表</span></li> </ol> <pre> <code>mysql> unlock tables;</code></pre> <p> </p> <h2><span style="font-family:宋体">三、数据库</span>2<span style="font-family:宋体">配置</span></h2> <h3>3.1<span style="font-family:宋体">修改数据库</span>2<span style="font-family:宋体">配置</span></h3> <p><span style="font-family:宋体">编辑数据库</span>1<span style="font-family:宋体">的配置文件</span>/etc/my.cnf</p> <p><span style="font-family:宋体">在</span>[mysqld]<span style="font-family:宋体">节点下添加</span>:</p> <pre> <code>#######主从配置master信息####### #[必须]服务器唯一ID,默认是1,一般取IP最后一段 server_id=203 #[必须]启用二进制日志 log_bin=mysql-bin #需要备份的数据库名  多个库以逗号分隔 binlog-do-db=test #忽略备份数据库名 #binlog-ignore-db=mysql #若涉及及同步函数或者存储过程需要配置,否则主备会产生异常不能同步 log_bin_trust_function_creators=TRUE #######主从配置master信息############</code></pre> <h3>3.2<span style="font-family:宋体">重启</span>MySQL<span style="font-family:宋体">服务</span></h3> <p><span style="font-family:宋体">重启数据库服务器</span>2<span style="font-family:宋体">的</span>MySQL<span style="font-family:宋体">服务</span></p> <p><span style="font-family:宋体">命令</span>:</p> <pre> <code>#service mysqld restart</code></pre> <p> </p> <h3>3.3<span style="font-family:宋体">导入数据</span></h3> <p><span style="font-family:宋体">将数据库服务器</span>1<span style="font-family:宋体">中导出的库导入进来</span></p> <p> </p> <ol start="7" style="list-style-type:lower-alpha"> <li value="176"><span style="font-family:宋体">远程复制备份文件</span></li> </ol> <pre> <code>[root@bogon ~]# scp root@192.168.8.202:/root/test-db.sql /root/test-db.sql The authenticity of host '192.168.8.202 (192.168.8.202)' can't be established. RSA key fingerprint is 70:bc:ba:69:58:77:3c:4b:8e:75:75:91:35:fa:40:f6. Are you sure you want to continue connecting (yes/no)? yes Warning: Permanently added '192.168.8.202' (RSA) to the list of known hosts. root@192.168.8.202's password: test-db.sql                                                                                                                                                                                                                                 100% 2575     2.5KB/s   00:00    [root@bogon ~]# ll total 42432 -rw-------. 1 root root     3330 Jul 19 03:54 anaconda-ks.cfg -rw-r--r--. 1 root root 41789864 Jul 25 07:10 axshool25.sql drwxr-xr-x. 2 root root     4096 Jul 19 07:11 Desktop drwxr-xr-x. 2 root root     4096 Jul 19 07:11 Documents drwxr-xr-x. 2 root root     4096 Jul 19 07:11 Downloads drwxr-xr-x. 4 root root     4096 Jul 24 06:08 fastDFS -rw-r--r--. 1 root root    41364 Jul 19 03:54 install.log -rw-r--r--. 1 root root     9154 Jul 19 03:52 install.log.syslog drwxr-xr-x. 2 root root     4096 Jul 19 07:11 Music drwxr-xr-x. 2 root root     4096 Jul 19 07:11 Pictures drwxr-xr-x. 2 root root     4096 Jul 19 07:11 Public drwxrwxr-x. 6 root root     4096 May 17 08:39 redis-3.2.9 -rw-r--r--. 1 root root  1547695 May 17 08:40 redis-3.2.9.tar.gz drwxr-xr-x. 2 root root     4096 Jul 19 07:11 Templates -rw-r--r--. 1 root root     2575 Jul 26 03:00 test-db.sql drwxr-xr-x. 2 root root     4096 Jul 19 07:11 Videos [root@bogon ~]# 导入数据 [root@bogon ~]# mysql -uroot -proot -B test </root/test-db.sql</code></pre> <p> </p> <h3>3.4<span style="font-family:宋体">创建</span>slave<span style="font-family:宋体">用户</span></h3> <p>Root<span style="font-family:宋体">用户登录数据库</span></p> <pre> <code>[root@bogon ~]# mysql -uroot -proot</code></pre> <p> </p> <p><span style="font-family:宋体">创建</span>slave<span style="font-family:宋体">用户</span></p> <pre> <code>mysql> grant replication slave on *.* to 'slave'@'%' identified by '123456';</code></pre> <p> </p> <p><span style="font-family:宋体">切换至</span>mysql<span style="font-family:宋体">数据库</span>,<span style="font-family:宋体">查看刚才创建的用户信息</span></p> <pre> <code>mysql> 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 mysql> select * from user where User='slave' \G; *************************** 1. row ***************************                   Host: %                   User: slave               Password: *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9            Select_priv: N            Insert_priv: N            Update_priv: N            Delete_priv: N            Create_priv: N              Drop_priv: N            Reload_priv: N          Shutdown_priv: N           Process_priv: N              File_priv: N             Grant_priv: N        References_priv: N             Index_priv: N             Alter_priv: N           Show_db_priv: N             Super_priv: N  Create_tmp_table_priv: N       Lock_tables_priv: N           Execute_priv: N        Repl_slave_priv: Y       Repl_client_priv: N       Create_view_priv: N         Show_view_priv: N    Create_routine_priv: N     Alter_routine_priv: N       Create_user_priv: N             Event_priv: N           Trigger_priv: N Create_tablespace_priv: N               ssl_type:             ssl_cipher:            x509_issuer:           x509_subject:          max_questions: 0            max_updates: 0        max_connections: 0   max_user_connections: 0                 plugin: mysql_native_password  authentication_string:       password_expired: N 1 row in set (0.00 sec) ERROR: No query specified mysql></code></pre> <p><img alt="5" class="img-thumbnail" src="/assist/images/blog/dc22d4ee5d40435599149de8f38a43cb.png" /></p> <p> </p> <h3>3.5<span style="font-family:宋体">配置</span>master</h3> <ol start="7" style="list-style-type:lower-alpha"> <li value="176"><span style="font-family:宋体">首先停止</span>slave</li> </ol> <pre> <code>mysql>stop slave</code></pre> <p> </p> <ol start="7" style="list-style-type:lower-alpha"> <li value="176"><span style="font-family:宋体">配置</span>master<span style="font-family:宋体">指向数据库服务器</span>1:</li> </ol> <pre> <code>mysql> change master to       -> master_host='192.168.8.202',      -> master_user='slave',      -> master_password='123456',      -> master_log_file='mysql-bin.000003',      -> master_log_pos=887; Query OK, 0 rows affected, 2 warnings (0.05 sec) mysql></code></pre> <p> </p> <p><em><span style="font-family:宋体">命令说明</span>:</em></p> <p><em>master_host              :master</em><em><span style="font-family:宋体">的主机地址</span></em></p> <p><em>master_user              :master</em><em><span style="font-family:宋体">的备份用户</span></em></p> <p><em>master_password    :master</em><em><span style="font-family:宋体">备份用户密码</span></em></p> <p><em>master_log_file        :</em><em><span style="font-family:宋体">日志文件名</span>,</em><em><span style="font-family:宋体">在第二步骤的</span>2.3</em><em><span style="font-family:宋体">备份的最后一步查看的信息里面</span></em></p> <p><em>master_log_pos       :</em><em><span style="font-family:宋体">日志位置</span>,</em><em><span style="font-family:宋体">同上也在</span>2.3</em><em><span style="font-family:宋体">步骤中</span></em></p> <p> </p> <ol start="7" style="list-style-type:lower-alpha"> <li value="176"><span style="font-family:宋体">启动</span>slave</li> </ol> <pre> <code>mysql> start slave;</code></pre> <p> </p> <h3>3.6<span style="font-family:宋体">查看数据库服务</span>2<span style="font-family:宋体">的</span>master<span style="font-family:宋体">信息</span></h3> <pre> <code>mysql> show master status; +------------------+----------+--------------+------------------+-------------------+ | File             | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set | +------------------+----------+--------------+------------------+-------------------+ | mysql-bin.000001 |      120 | test         |                  |                   | +------------------+----------+--------------+------------------+-------------------+ 1 row in set (0.00 sec) mysql></code></pre> <p><img alt="6" class="img-thumbnail" src="/assist/images/blog/8a1bdb08a23d4e6ab2731f9751ba140b.png" /></p> <p> </p> <h2><span style="font-family:宋体">四、配置数据库</span>1master</h2> <ol start="7" style="list-style-type:lower-alpha"> <li value="176">Root<span style="font-family:宋体">用户登录数据库</span>1</li> </ol> <pre> <code>#mysql –uroot –proot</code></pre> <ol start="7" style="list-style-type:lower-alpha"> <li value="176"><span style="font-family:宋体">停止</span>slave</li> </ol> <pre> <code>mysql> stop slave; Query OK, 0 rows affected, 1 warning (0.02 sec) mysql></code></pre> <ol start="7" style="list-style-type:lower-alpha"> <li value="176"><span style="font-family:宋体">配置</span>master<span style="font-family:宋体">指向数据库服务器</span>2</li> </ol> <pre> <code>mysql> change master to       -> master_host='192.168.8.203',      -> master_user='slave',      -> master_password='123456',      -> master_log_file='mysql-bin.000001',      -> master_log_pos=120; Query OK, 0 rows affected, 2 warnings (0.08 sec) 启动slave mysql> start slave; Query OK, 0 rows affected (0.00 sec) </code></pre> <h2><span style="font-family:宋体">五、测试</span></h2> <p> </p> <h3>5.1<span style="font-family:宋体">测试数据库</span>1<span style="font-family:宋体">为</span>master<span style="font-family:宋体">创建表同步至数据库</span>2</h3> <p><span style="font-family:宋体">测试步骤</span>:</p> <ol start="7" style="list-style-type:lower-alpha"> <li value="176">Root<span style="font-family:宋体">数据库用户登录数据库服务器</span>1,<span style="font-family:宋体">切换至</span>test<span style="font-family:宋体">库</span></li> </ol> <p><img alt="7" class="img-thumbnail" src="/assist/images/blog/707f5370f77e4420b0c3cf1ca2279405.png" /></p> <ol start="7" style="list-style-type:lower-alpha"> <li value="176"><span style="font-family:宋体">创建一张表</span>,<span style="font-family:宋体">名称为</span>t_data</li> </ol> <p><img alt="8" class="img-thumbnail" src="/assist/images/blog/9782fe887f6b42668c646d0f83c9e140.png" /></p> <ol start="7" style="list-style-type:lower-alpha"> <li value="176"><span style="font-family:宋体">登录数据库服务器</span>2<span style="font-family:宋体">,切换至数据库</span>test<span style="font-family:宋体">并查看表请情况</span></li> </ol> <p> </p> <p><span style="font-family:宋体">可以看到数据库</span>2<span style="font-family:宋体">中已经存在</span>t_data<span style="font-family:宋体">表格说明表创建已经同步成功</span></p> <p><img alt="9" class="img-thumbnail" src="/assist/images/blog/ac1062d2c431404c986ccd2f70589649.png" /></p> <h3>5.2<span style="font-family:宋体">测试数据库</span>1<span style="font-family:宋体">为</span>master<span style="font-family:宋体">数据内容同步</span></h3> <p><span style="font-family:宋体">测试步骤</span>:</p> <ol start="7" style="list-style-type:lower-alpha"> <li value="176"><span style="font-family:宋体">登录数据库</span>1<span style="font-family:宋体">并切换至</span>test<span style="font-family:宋体">库,新增一条数据到上面创建的</span>t_data<span style="font-family:宋体">表中</span></li> </ol> <p><img alt="10" class="img-thumbnail" src="/assist/images/blog/632dc5d7655d4baf957eb3c6bb49b891.png" /></p> <ol start="7" style="list-style-type:lower-alpha"> <li value="176"><span style="font-family:宋体">登录数据库</span>2<span style="font-family:宋体">,切换至</span>test<span style="font-family:宋体">库查看</span>t_data<span style="font-family:宋体">表数据是否同步</span></li> </ol> <p><img alt="11" class="img-thumbnail" src="/assist/images/blog/a2bf6397291f4986b911acb359fcf51e.png" /></p> <p><span style="font-family:宋体">可以看到数据库</span>2<span style="font-family:宋体">中的表</span>t_data<span style="font-family:宋体">数据内容已经同步。测试数据同步成功。</span></p> <p> </p> <h3>5.3<span style="font-family:宋体">测试数据库</span>2<span style="font-family:宋体">为</span>master<span style="font-family:宋体">创建表同步</span></h3> <p><span style="font-family:宋体">测试步骤</span>:</p> <ol start="7" style="list-style-type:lower-alpha"> <li value="176">Root<span style="font-family:宋体">数据库用户登录数据库</span>2<span style="font-family:宋体">,并切换至</span>test<span style="font-family:宋体">库,创建一个</span>t_data2<span style="font-family:宋体">的表格</span></li> </ol> <p><img alt="12" class="img-thumbnail" src="/assist/images/blog/c2e37210f12c4d33940a40a63a59a80f.png" /></p> <ol start="7" style="list-style-type:lower-alpha"> <li value="176"><span style="font-family:宋体">登录数据库</span>1<span style="font-family:宋体">切换至</span>test<span style="font-family:宋体">库</span>,<span style="font-family:宋体">查看表</span>t_data2<span style="font-family:宋体">是否创建</span></li> </ol> <p><img alt="13" class="img-thumbnail" src="/assist/images/blog/624225953a5d44fca9ff04d18b5caed0.png" /></p> <p><span style="font-family:宋体">可以看到在数据库</span>1<span style="font-family:宋体">中</span>t_data2<span style="font-family:宋体">表已经同步创建,测试表创建同步成功。</span></p> <p> </p> <h3>5.4<span style="font-family:宋体">测试数据库</span>2<span style="font-family:宋体">为</span>master<span style="font-family:宋体">数据内容的同步</span></h3> <p><span style="font-family:宋体">测试步骤</span>:</p> <ol start="7" style="list-style-type:lower-alpha"> <li value="176"><span style="font-family:宋体">登录数据库</span>2<span style="font-family:宋体">,并切换至</span>test<span style="font-family:宋体">库向</span>t_data2<span style="font-family:宋体">表中插入一条数据</span></li> </ol> <p><img alt="14" class="img-thumbnail" src="/assist/images/blog/36ca6b577a124f76a1638df072436855.png" /></p> <ol start="7" style="list-style-type:lower-alpha"> <li value="176"><span style="font-family:宋体">登录数据库</span>1<span style="font-family:宋体">切换至</span>test<span style="font-family:宋体">库查看表</span>t_data2<span style="font-family:宋体">中数据是否同步</span></li> </ol> <p><img alt="15" class="img-thumbnail" src="/assist/images/blog/ba2fb40560134b99b3bd58a8f27ab1ad.png" /></p> <p><span style="font-family:宋体">可以看到数据已经同步至数据库</span>1<span style="font-family:宋体">中的</span>test<span style="font-family:宋体">库的</span>t_data2<span style="font-family:宋体">表。数据同步测试成功。</span></p>
  • centos6 安装mysql 5.6 数据库及配置

    centos6.5安装MySQL 5.6版本,并配置数据了链接数量数据库默认字符集utf8mb4支持Emoji表情4字节内容<h2><span style="font-family:宋体">一、用户切换</span></h2> <p><span style="font-family:宋体">通过远程工具链接到</span>centos6.5<span style="font-family:宋体">服务器后</span>,<span style="font-family:宋体">切换至</span>root<span style="font-family:宋体">用户。如果已经是</span>root<span style="font-family:宋体">用户则忽略该步骤。</span></p> <p><span style="font-family:宋体">切换</span>root<span style="font-family:宋体">用户步骤</span>:</p> <p><span style="font-family:宋体">执行命令</span>:</p> <pre> <code class="language-html">su –</code></pre> <p><span style="font-family:宋体">回车</span></p> <p><span style="font-family:宋体">输入</span>root<span style="font-family:宋体">密码</span></p> <p> </p> <p><span style="font-family:宋体">密码输入成功则已经切换至</span>root<span style="font-family:宋体">用户,失败则提示鉴定错误。重新执行上面的命令直到密码正确进入</span>root<span style="font-family:宋体">用户</span></p> <p><span style="font-family:宋体">切换成功后可以见到由</span>$<span style="font-family:宋体">变成了</span>#</p> <h2><span style="font-family:宋体">二、检查系统中是否存在</span>MySQL<span style="font-family:宋体">或者</span>MySQL<span style="font-family:宋体">依赖</span></h2> <p><span style="font-family:宋体">检查当前系统是否已经安装</span>MySQL<span style="font-family:宋体">或者</span>MySQL<span style="font-family:宋体">的相关库</span>,<span style="font-family:宋体">如果已经安装</span>MySQL<span style="font-family:宋体">数据库则询问相关人员是否允许卸载重新安装。如果存在</span>MySQL<span style="font-family:宋体">的依赖库则必须先卸载,否则后面可能会因为当前依赖库的版本与后面安装的版本不一致导致安装冲突,最终导致安装失败。</span></p> <p><span style="font-family:宋体">查看系统是否安装</span>MySQL<span style="font-family:宋体">相关</span></p> <p><span style="font-family:宋体">命令</span>:</p> <pre> <code class="language-html">[root@localhost ~]# rpm -qa|grep mysql mysql-libs-5.1.71-1.el6.x86_64 [root@localhost ~]#</code></pre> <p><img alt="删除历史MySQL相关包" class="img-thumbnail" src="/assist/images/blog/331bd33c6c5e4186ae0a1e339f1d9985.png" /></p> <p><span style="font-family:宋体">当前系统没有安装</span>MySQL<span style="font-family:宋体">但是有一个依赖包</span>,<span style="font-family:宋体">将其先卸载</span></p> <p><span style="font-family:宋体">卸载命令</span>:</p> <pre> <code class="language-html">[root@localhost ~]# rpm -e --nodeps  mysql-libs-5.1.71-1.el6.x86_64</code></pre> <p><span style="font-family:宋体">查看是否已经卸载</span>,<span style="font-family:宋体">可执行上面的查看命令</span></p> <h2><span style="font-family:宋体">三、安装</span>MySQL<span style="font-family:宋体">数据库</span></h2> <p><span style="font-family:宋体">通过</span>yum<span style="font-family:宋体">安装</span>MySQL<span style="font-family:宋体">(注意系统必须连接外网)</span></p> <h3>3.1<span style="font-family:宋体">首先安装</span>MySQL<span style="font-family:宋体">的</span>yum<span style="font-family:宋体">源(</span>MySQL yum<span style="font-family:宋体">源官方地址</span>https://dev.mysql.com/downloads/repo/yum/<span style="font-family:宋体">)</span></h3> <p><span style="font-family:宋体">安装命令</span>:</p> <pre> <code class="language-html">[root@bogon ~]# rpm -Uvh http://repo.mysql.com/mysql-community-release-el6-5.noarch.rpm Retrieving http://repo.mysql.com/mysql-community-release-el6-5.noarch.rpm Preparing...                ########################################### [100%]    1:mysql-community-release########################################### [100%] [root@bogon ~]#</code></pre> <p><img alt="安装MySQL yum源" class="img-thumbnail" src="/assist/images/blog/608a9931e82f4cf3982c07e917afc339.png" /></p> <p><span style="font-family:宋体">或者</span></p> <p><span style="font-family:宋体">命令</span>:</p> <pre> <code class="language-html">yum install -y http://repo.mysql.com/mysql-community-release-el6-5.noarch.rpm</code></pre> <p> </p> <h3>3.2<span style="font-family:宋体">首先使用</span>yum<span style="font-family:宋体">查看可以安装的</span>MySQL<span style="font-family:宋体">版本</span></h3> <p><span style="font-family:宋体">命令</span>:</p> <pre> <code class="language-html">[root@localhost ~]# yum list|grep mysql</code></pre> <p><img alt="查看可以选择安装的MySQL版本" class="img-thumbnail" src="/assist/images/blog/40a5fdd47d3b4fbe9265bacdda75cb6d.png" /></p> <p> </p> <h3>3.3<span style="font-family:宋体">通过</span>yum<span style="font-family:宋体">安装</span>mysql5.6.37<span style="font-family:宋体">版本</span></h3> <p><span style="font-family:宋体">安装命令:</span></p> <pre> <code class="language-html">[root@localhost ~]# yum install -y mysql-community-server.x86_64</code></pre> <p><img alt="安装MySQL5.6" class="img-thumbnail" src="/assist/images/blog/fc16ad47bb5a47cbba1f9488b989feb3.png" /></p> <h2><span style="font-family:宋体">四、启动</span>MySQL<span style="font-family:宋体">服务</span></h2> <p><span style="font-family:宋体">启动</span>MySQL<span style="font-family:宋体">服务命令</span></p> <pre> <code class="language-html">[root@localhost ~]# service mysqld start</code></pre> <p><span style="font-family:宋体">重点日志</span>:</p> <pre> <code class="language-html">PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER ! To do so, start the server, then issue the following commands:   /usr/bin/mysqladmin -u root password 'new-password'   /usr/bin/mysqladmin -u root -h bogon password 'new-password' Alternatively you can run:   /usr/bin/mysql_secure_installation </code></pre> <p><span style="font-family:宋体">初次启动</span>MySQL<span style="font-family:宋体">服务</span>,<span style="font-family:宋体">会提示执行相关命令设置</span>root<span style="font-family:宋体">用户密码</span></p> <p><img alt="启动MySQL服务" class="img-thumbnail" src="/assist/images/blog/de4ca6d527cf4002b43fa018a9f54dff.png" /></p> <h2><span style="font-family:宋体">五、配置</span>MySQL</h2> <h3>5.1<span style="font-family:宋体">设置</span>MySQL<span style="font-family:宋体">的默认密码</span></h3> <p><span style="font-family:宋体">根据初次的启动提示,进行设置默认密码</span>,<span style="font-family:宋体">当前版本为</span>5.6.37<span style="font-family:宋体">设置默认密码的方式如下</span>:</p> <p><span style="font-family:宋体">将默认密码设置为</span>root</p> <pre> <code class="language-html">[root@localhost ~]# /usr/bin/mysqladmin -u root password root</code></pre> <p> </p> <h3>5.2<span style="font-family:宋体">登录</span>root<span style="font-family:宋体">用户</span></h3> <p><span style="font-family:宋体">登录</span>root<span style="font-family:宋体">命令</span>:</p> <p>[root@localhost ~]# mysql -uroot –proot</p> <p><img alt="root用户登录" class="img-thumbnail" src="/assist/images/blog/81b466cf8bdc476cb066df6109f816d3.png" /></p> <p><span style="font-family:宋体">退出登录命令</span></p> <pre> <code class="language-html">Mysql>exit</code></pre> <h3>5.3<span style="font-family:宋体">配置</span>MySQL<span style="font-family:宋体">的配置文件</span>my.cnf</h3> <h4 style="margin-left:10.5pt; margin-right:10.5pt">5.3.1<span style="font-family:宋体">配置数据库字符集</span>utf8mb</h4> <p><span style="font-family:宋体">编辑</span>my.cnf<span style="font-family:宋体">文件</span></p> <pre> <code class="language-html">[root@localhost ~]# vi /etc/my.cnf</code></pre> <p><span style="font-family:宋体">默认内容</span></p> <p><img alt="默认配置文件内容" class="img-thumbnail" src="/assist/images/blog/f4a9a176406b4e129597fcf5fa8c31b1.png" /></p> <p> </p> <p><span style="font-family:宋体">配置字符集</span>utf8mb4</p> <p style="margin-left:18.0pt"><span style="font-family:宋体">配置后内容如下</span>:</p> <pre> <code class="language-html">[client] default-character-set = utf8mb4 [mysql] default-character-set = utf8mb4 [mysqld] character-set-client-handshake = FALSE character-set-server = utf8mb4 collation-server = utf8mb4_general_ci init_connect='SET NAMES utf8mb4'</code></pre> <p><span style="font-family:宋体">修改后内容</span>:</p> <p><img alt="设置字符集" class="img-thumbnail" src="/assist/images/blog/3602876605814779bf0bbf9a20246dec.png" /></p> <p><span style="color:#27ae60"><strong><span style="font-family:宋体">注意</span>:MySQL<span style="font-family:宋体">版本</span>5.5<span style="font-family:宋体">以上才支持</span>utf8mb4</strong></span></p> <p><span style="font-family:宋体">重启</span>MySQL<span style="font-family:宋体">服务<br /> 命令</span>:</p> <pre> <code class="language-html">[root@bogon ~]# service  mysqld restart Stopping mysqld:                                           [  OK  ] Starting mysqld:                                           [  OK  ] [root@bogon ~]#</code></pre> <h4 style="margin-left:10.5pt; margin-right:10.5pt">5.3.2<span style="font-family:宋体">配置</span>MySQL<span style="font-family:宋体">最大连接数</span></h4> <p><span style="font-family:宋体">编辑</span>my.cnf<span style="font-family:宋体">文件,</span></p> <pre> <code class="language-html">[root@localhost ~]# vi /etc/my.cnf</code></pre> <p><span style="font-family:宋体">在</span>[mysqld]<span style="font-family:宋体">节点中添加</span></p> <pre> <code class="language-html">max_connections = 1000</code></pre> <p><img alt="设置最大链接数" class="img-thumbnail" src="/assist/images/blog/d9104553fa5d419fbbaf3e7f73490514.png" /></p> <p><span style="font-family:宋体">该配置标识</span>MySQL<span style="font-family:宋体">数据库的最大连接数为</span>1000<span style="font-family:宋体">个<br /> <span style="color:#e74c3c"><strong>注意:配置文件方式修改最大连接数需要重启MySQL服务。某些时候不能重启则可以mysql的root用户登录设置</strong></span></span><br />  </p> <pre> <code class="language-html">mysql> show variables LIKE '%max_connections%'; +-----------------+-------+ | Variable_name | Value | +-----------------+-------+ | max_connections | 151 | +-----------------+-------+ 1 row in set (0.01 sec) mysql> set global max_connections=500; Query OK, 0 rows affected (0.00 sec) mysql> show variables LIKE '%max_connections%'; +-----------------+-------+ | Variable_name | Value | +-----------------+-------+ | max_connections | 500 | +-----------------+-------+ 1 row in set (0.00 sec) mysql> exit </code></pre> <p><span style="font-family:宋体">重启</span>MySQL<span style="font-family:宋体">服务</span></p> <p><span style="font-family:宋体">命令</span>:</p> <pre> <code class="language-html">[root@bogon ~]# service  mysqld restart Stopping mysqld:                                           [  OK  ] Starting mysqld:                                           [  OK  ] [root@bogon ~]# </code></pre> <h4 style="margin-left:10.5pt; margin-right:10.5pt">5.3.3<span style="font-family:宋体">配置数据库连接超时时间</span></h4> <p><span style="font-family:宋体">编辑</span>my.cnf<span style="font-family:宋体">文件,</span></p> <pre> <code class="language-html">[root@localhost ~]# vi /etc/my.cnf</code></pre> <p><span style="font-family:宋体">在</span>[mysqld]<span style="font-family:宋体">节点中添加</span></p> <pre> <code class="language-html">wait_timeout = 15811200</code></pre> <p><img alt="设置超时时间" class="img-thumbnail" src="/assist/images/blog/da1018e90f42441e91f96364bfe561ce.png" /></p> <p><span style="font-family:宋体">该配置标识数据库连接会话超时时间为半年</span>,<span style="font-family:宋体">防止应用中数据库连接池的闲置连接超时。</span></p> <p> </p> <p><span style="font-family:宋体">重启</span>MySQL<span style="font-family:宋体">服务</span></p> <p><span style="font-family:宋体">命令</span>:</p> <pre> <code class="language-html">[root@bogon ~]# service  mysqld restart Stopping mysqld:                                           [  OK  ] Starting mysqld:                                           [  OK  ] [root@bogon ~]# </code></pre> <h3>5.4<span style="font-family:宋体">创建数据库以及用户</span></h3> <h4 style="margin-left:10.5pt; margin-right:10.5pt">5.4.1<span style="font-family:宋体">登录</span>MySQL<span style="font-family:宋体">数据库</span></h4> <p><span style="font-family:宋体">首先通过</span>root<span style="font-family:宋体">用户登录</span>MySQL<span style="font-family:宋体">数据库</span></p> <p><span style="font-family:宋体">命令</span>:</p> <pre> <code class="language-html">[root@bogon ~]# mysql -uroot –proot</code></pre> <p><span style="font-family:宋体">命令说明</span>:</p> <p>-u <span style="font-family:宋体">后面跟</span>MySQL<span style="font-family:宋体">数据库用户名</span></p> <p>-p <span style="font-family:宋体">后面跟</span>MySQL<span style="font-family:宋体">数据库用户密码</span></p> <p> </p> <h4 style="margin-left:10.5pt; margin-right:10.5pt">5.4.2<span style="font-family:宋体">查看</span>MySQL<span style="font-family:宋体">数据库中已有的数据库</span></h4> <p><span style="font-family:宋体">命令</span>:</p> <p>mysql> show databases;</p> <p><img alt="查看默认数据库" class="img-thumbnail" src="/assist/images/blog/86cc4e383e7a4434865d25a1c1436e15.png" /></p> <h4 style="margin-left:10.5pt; margin-right:10.5pt">5.4.3<span style="font-family:宋体">创建数据库</span></h4> <p><span style="font-family:宋体">首先通过创建</span>test<span style="font-family:宋体">数据库来熟悉命令</span></p> <p><span style="font-family:宋体">命令</span>:</p> <pre> <code class="language-html">create database test default character set utf8mb4 collate utf8mb4_unicode_ci;</code></pre> <p><em><span style="font-family:宋体">注意</span>:Linux</em><em><span style="font-family:宋体">系统中</span>MySQL</em><em><span style="font-family:宋体">区分大小写</span></em></p> <p><img alt="创建数据库" class="img-thumbnail" src="/assist/images/blog/db6cfaa1d6aa4b8c8bf17f668745a3d6.png" /></p> <p><span style="font-family:宋体">创建成功后可查看</span></p> <p><img alt="查看数据库" class="img-thumbnail" src="/assist/images/blog/0dc57780514642f781955816419eced8.png" /></p> <p><span style="font-family:宋体">数据库已经成功创建</span></p> <p> </p> <h4 style="margin-left:10.5pt; margin-right:10.5pt">5.4.4<span style="font-family:宋体">创建数据库用户</span></h4> <p><span style="font-family:宋体">为上面创建的</span>test<span style="font-family:宋体">库添加一个数据库用户</span>,<span style="font-family:宋体">并赋予这个用户拥有</span>test<span style="font-family:宋体">库的</span>DBA<span style="font-family:宋体">权限</span></p> <p><span style="font-family:宋体">命令</span>:</p> <pre> <code class="language-html">mysql> grant all privileges on test.*  to testuser@'%' identified by '123456'; mysql> grant all privileges on test.*  to testuser@'localhost' identified by '123456';</code></pre> <pre> <code>grant all privileges on test.* to test@'%' identified by '123456' WITH GRANT OPTION;</code></pre> <p><span style="color:#ff0000"><span style="font-family:宋体">添加 WITH GRANT OPTION;表示该用户可以给其他用户进行grant授权。</span></span><br /> <strong><span style="font-family:宋体">注意</span>:<em><span style="font-family:宋体">某些版本例如</span>5.6.37</em></strong><strong><em><span style="font-family:宋体">中</span>localhost</em></strong><strong><em><span style="font-family:宋体">与</span>%</em></strong><strong><em><span style="font-family:宋体">没有交集需要单独配</span>localhost</em></strong><strong><em><span style="font-family:宋体">否则本地无法登陆</span></em></strong></p> <p><img alt="创建MySQL用户" class="img-thumbnail" src="/assist/images/blog/b86c3e1cdd864361927394f7e87c8b58.png" /></p> <p><span style="font-family:宋体">刷新权限</span></p> <pre> <code class="language-html">mysql> flush privileges; Query OK, 0 rows affected (0.00 sec)</code></pre> <p> </p> <p><span style="font-family:宋体">退出当前</span>root<span style="font-family:宋体">用户,使用新创建的</span>testuser<span style="font-family:宋体">用户登录数据库</span></p> <p><span style="font-family:宋体">命令</span>:</p> <pre> <code class="language-html">[root@bogon ~]# mysql -p192.168.8.167 -utestuser -p123456 Warning: Using a password on the command line interface can be insecure. Welcome to the MySQL monitor.  Commands end with ; or \g. Your MySQL connection id is 35 Server version: 5.6.37 MySQL Community Server (GPL) Copyright (c) 2000, 2017, 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 clear the current input statement. mysql> show databases; +--------------------+ | Database           | +--------------------+ | information_schema | | test               | +--------------------+ 2 rows in set (0.00 sec) mysql></code></pre> <p><img alt="测试用户登录" class="img-thumbnail" src="/assist/images/blog/7462ff3d9482441b84103de62baa2fbe.png" /></p> <p> </p> <h4 style="margin-left:10.5pt; margin-right:10.5pt">5.4.5<span style="font-family:宋体">删除数据库用户</span></h4> <p><span style="font-family:宋体">首先</span>root<span style="font-family:宋体">用户登录数据库</span></p> <p><span style="font-family:宋体">命令</span>:</p> <pre> <code class="language-html">[root@bogon ~]# mysql -uroot –proot</code></pre> <p><span style="font-family:宋体">切换至</span>mysql<span style="font-family:宋体">数据库</span></p> <p><span style="font-family:宋体">命令</span>:</p> <pre> <code class="language-html">mysql> 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 mysql></code></pre> <p><span style="font-family:宋体">删除用户</span></p> <p><span style="font-family:宋体">命令</span>:</p> <pre> <code class="language-html">mysql> delete from user where User='testuser' and Host='localhost'; Query OK, 1 row affected (0.00 sec)</code></pre> <p><span style="font-family:宋体">刷新权限</span>:</p> <p><span style="font-family:宋体">命令</span>:</p> <pre> <code class="language-html">mysql> flush privileges; Query OK, 0 rows affected (0.00 sec)</code></pre> <p><span style="font-family:宋体">退出后再次使用</span>testuser<span style="font-family:宋体">登录将会失败</span>:</p> <pre> <code class="language-html">[root@bogon ~]# mysql -utestuser -p123456 Warning: Using a password on the command line interface can be insecure. ERROR 1045 (28000): Access denied for user 'testuser'@'localhost' (using password: YES) [root@bogon ~]#</code></pre> <p><br /> <br /> <br /> <strong>注意:</strong><br /> 1.5.6默认关闭了通过ln链接方式的存储路径修改。在/etc/my.cnf文件中可以查看到以下配置和说明</p> <pre> <code class="language-html"># Disabling symbolic-links is recommended to prevent assorted security risks symbolic-links=0 </code></pre> <p>如果要使用ln链接方式修改存放路径注意这里配置<strong><span style="color:#ff0000">值为1,并且关闭selinux</span></strong><br /> <br /> 2.<span style="color:#ff0000"><strong>新装</strong></span>的mysql 5.6(yum方式) 修改数据存放路径</p> <ol> <li>需要先启动mysql服务。生成的默认的/var/lib/mysql文件夹</li> <li>停止mysql服务</li> <li>将生成的mysql文件夹移动到新的你需要移动的地方,并配置/etc/my.cnf文件。将路径指定到新的地方</li> <li>启动mysql服务</li> </ol> <p>直接配置/etc/my.cnf文件有较大几率失败<br />  </p>