<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>MariaDB &#8211; Eternal Center</title>
	<atom:link href="https://eternalcenter-sep-2022.github.io/category/database/relational-database-sql/mariadb/feed/" rel="self" type="application/rss+xml" />
	<link>https://eternalcenter-sep-2022.github.io/</link>
	<description></description>
	<lastBuildDate>Tue, 13 Sep 2022 12:51:17 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	
	<item>
		<title>[内容] MariaDB &#038; MySQL 规划表结构的思路</title>
		<link>https://eternalcenter-sep-2022.github.io/mariadb-mysql-table-structure/</link>
		
		<dc:creator><![CDATA[Mingyu Zhu]]></dc:creator>
		<pubDate>Thu, 22 Jul 2021 08:08:31 +0000</pubDate>
				<category><![CDATA[Chinese (中文)]]></category>
		<category><![CDATA[Database (数据库)]]></category>
		<category><![CDATA[MariaDB]]></category>
		<category><![CDATA[MySQL]]></category>
		<guid isPermaLink="false">https://eternalcenter-sep-2022.github.io/?p=16925</guid>

					<description><![CDATA[1) 确保表里的字段都缺一不可（也就是具有原子性）2) 确保表里的字段都和主键直接相关]]></description>
										<content:encoded><![CDATA[
<p>1) 确保表里的字段都缺一不可（也就是具有原子性）<br>2) 确保表里的字段都和主键直接相关</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>[内容] MariaDB &#038; MySQL 事务</title>
		<link>https://eternalcenter-sep-2022.github.io/mariadb-mysql-transaction/</link>
		
		<dc:creator><![CDATA[Mingyu Zhu]]></dc:creator>
		<pubDate>Tue, 20 Jul 2021 07:55:17 +0000</pubDate>
				<category><![CDATA[Chinese (中文)]]></category>
		<category><![CDATA[Database (数据库)]]></category>
		<category><![CDATA[MariaDB]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[Relational Database (SQL) (关系型数据库 )]]></category>
		<guid isPermaLink="false">https://eternalcenter-sep-2022.github.io/?p=16863</guid>

					<description><![CDATA[内容一：事务的作用 事务的作用是保护数据的安全性 内容二：MariaDB &#38; MySQL 事务的 4 大特性 2.1 原子性（Atomicity） 一系列操作被看作一个事务，这个事务里面的所有操作要么全部失败，要么全部成功，如果在操作的过程中出现中断，则立刻进行 rollback 2.2 一致性（Consistency） 一系列操作被看作一个事务，在事务开始前和结束后，整个库的完整逻辑约束不能被打破，例如：一个人向另一个人转账，不能出现一个人转账成功另一个人没有收到转账，或者一个人转账失败另一个人收到转账的情况 2.3 隔离性（Isolation） 主要解决并发的情况，避免不同的人，在相同的时间，查看到的数据的不一致性，避免以下情况的发生：1) 脏读：一个事务读取了另一个事务更新、提交并撤销的数据，导致此事务看到的数据是错误的2) 不可重复读：一个事务多次读取了另一个事务多次更新并提交的数据，导致此事务看到的数据是来回变化的3) 幻读：一个事务在批量修改所有数据，但是在修改的过程中另一个事务又往里面插入了数据，导致此事务在修改完成之后，意外发现还有一条数据没有修改 2.4 持久性（Durability） 事务结束后，所有更新都将被保存，不能回滚 内容三：MariaDB &#38; MySQL 事务隔离级别 3.1 MariaDB &#38; MySQL 事务隔离级别的特点 事务隔离级别 脏读 不可重复读 幻读 读未提交（read-uncommitted） 是 是 是 不可重复读（read-committed） 否 是 是 可重复读（repeatable-read） 否 否 是 串行化（serializable） 否 否 否 3.2 MariaDB &#8230; <p class="link-more"><a href="https://eternalcenter-sep-2022.github.io/mariadb-mysql-transaction/" class="more-link">Continue reading<span class="screen-reader-text"> "[内容] MariaDB &#038; MySQL 事务"</span></a></p>]]></description>
										<content:encoded><![CDATA[
<h3 id="内容一-事务的作用">内容一：事务的作用</h3>



<p>事务的作用是保护数据的安全性</p>



<h3 id="内容二-mariadb-mysql-事务的-4-大特性2-1-原子性-atomicity">内容二：MariaDB &amp; MySQL 事务的 4 大特性</h3>



<h4 id="内容二-mariadb-mysql-事务的-4-大特性2-1-原子性-atomicity">2.1 原子性（Atomicity）</h4>



<p>一系列操作被看作一个事务，这个事务里面的所有操作要么全部失败，要么全部成功，如果在操作的过程中出现中断，则立刻进行 rollback</p>



<h4 id="2-2-一致性-consistency">2.2 一致性（Consistency）</h4>



<p>一系列操作被看作一个事务，在事务开始前和结束后，整个库的完整逻辑约束不能被打破，例如：一个人向另一个人转账，不能出现一个人转账成功另一个人没有收到转账，或者一个人转账失败另一个人收到转账的情况</p>



<h4 id="2-3-隔离性-isolation">2.3 隔离性（Isolation）</h4>



<p>主要解决并发的情况，避免不同的人，在相同的时间，查看到的数据的不一致性，避免以下情况的发生：<br>1) 脏读：一个事务读取了另一个事务更新、提交并撤销的数据，导致此事务看到的数据是错误的<br>2) 不可重复读：一个事务多次读取了另一个事务多次更新并提交的数据，导致此事务看到的数据是来回变化的<br>3) 幻读：一个事务在批量修改所有数据，但是在修改的过程中另一个事务又往里面插入了数据，导致此事务在修改完成之后，意外发现还有一条数据没有修改</p>



<h4 id="2-4-持久性-durability">2.4 持久性（Durability）</h4>



<p>事务结束后，所有更新都将被保存，不能回滚</p>



<h3 id="内容三-mariadb-mysql-事务隔离级别3-1-mariadb-mysql-事务隔离级别的特点">内容三：MariaDB &amp; MySQL 事务隔离级别</h3>



<h4 id="内容三-mariadb-mysql-事务隔离级别3-1-mariadb-mysql-事务隔离级别的特点">3.1 MariaDB &amp; MySQL 事务隔离级别的特点</h4>



<figure class="wp-block-table"><table><tbody><tr><td>事务隔离级别</td><td>脏读</td><td>不可重复读</td><td>幻读</td></tr><tr><td>读未提交（read-uncommitted）</td><td>是</td><td>是</td><td>是</td></tr><tr><td>不可重复读（read-committed）</td><td>否</td><td>是</td><td>是</td></tr><tr><td>可重复读（repeatable-read）</td><td>否</td><td>否</td><td>是</td></tr><tr><td>串行化（serializable）</td><td>否</td><td>否</td><td>否</td></tr></tbody></table></figure>



<h4 id="3-2-mariadb-mysql-默认的事务隔离级别">3.2 MariaDB &amp; MySQL 默认的事务隔离级别</h4>



<p>可重复读 repeatable-read</p>



<h4 id="3-3-查看目前所使用的事务隔离的方法">3.3 查看目前所使用的事务隔离的方法</h4>



<pre class="wp-block-code"><code>MariaDB &#91;(none)]&gt; select @@tx_isolation;
+-----------------+
| @@tx_isolation  |
+-----------------+
| REPEATABLE-READ |
+-----------------+
1 row in set (0.001 sec)</code></pre>



<p>（补充：这里以查看 MariaDB 目前所使用的事务隔离为例）</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>[内容] MariaDB &#038; MySQL 多表关系</title>
		<link>https://eternalcenter-sep-2022.github.io/mariadb-mysql-multi-table-relation/</link>
		
		<dc:creator><![CDATA[Mingyu Zhu]]></dc:creator>
		<pubDate>Wed, 30 Jun 2021 09:03:27 +0000</pubDate>
				<category><![CDATA[Chinese (中文)]]></category>
		<category><![CDATA[Database (数据库)]]></category>
		<category><![CDATA[Django]]></category>
		<category><![CDATA[Django Foundation (基础)]]></category>
		<category><![CDATA[Django Model Layer (模型层)]]></category>
		<category><![CDATA[Language (语言)]]></category>
		<category><![CDATA[MariaDB]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[Relational Database (SQL) (关系型数据库 )]]></category>
		<guid isPermaLink="false">https://eternalcenter-sep-2022.github.io/?p=16308</guid>

					<description><![CDATA[内容一：一对一关系 1.1 通常实现方法 唯一外键 1.2 典型案例 学生表和学生证表 内容二：一对多关系 2.1 通常实现方法 主外键 2.2 典型案例 学生表和班级表 内容三：多对多关系 3.1 通常实现方法 中间表加联合主键 （补充：联合主键是指一张表中有两个主键，这两个主键叫联合主键，每一条数据里的联合主键可以相互之间拼凑成一个新的主键，联合主键可以重复，只要保证这个新的主键唯一即可） 3.2 典型案例 学生和课程]]></description>
										<content:encoded><![CDATA[
<h3>内容一：一对一关系</h3>



<h4>1.1 通常实现方法</h4>



<p>唯一外键</p>



<h4>1.2 典型案例</h4>



<p>学生表和学生证表</p>



<h3>内容二：一对多关系</h3>



<h4>2.1 通常实现方法</h4>



<p>主外键</p>



<h4>2.2 典型案例</h4>



<p>学生表和班级表</p>



<h3>内容三：多对多关系</h3>



<h4>3.1 通常实现方法</h4>



<p>中间表加联合主键</p>



<p>（补充：联合主键是指一张表中有两个主键，这两个主键叫联合主键，每一条数据里的联合主键可以相互之间拼凑成一个新的主键，联合主键可以重复，只要保证这个新的主键唯一即可）</p>



<h4>3.2 典型案例</h4>



<p>学生和课程</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>[工具] Shell 自动化部署 LNMP + SSL 平台 （openSUSE Leap 15 版）</title>
		<link>https://eternalcenter-sep-2022.github.io/shell-lnmp-install-opensuse-leap-15/</link>
		
		<dc:creator><![CDATA[Mingyu Zhu]]></dc:creator>
		<pubDate>Mon, 24 May 2021 05:53:21 +0000</pubDate>
				<category><![CDATA[Chinese (中文)]]></category>
		<category><![CDATA[Database (数据库)]]></category>
		<category><![CDATA[Language (语言)]]></category>
		<category><![CDATA[MariaDB]]></category>
		<category><![CDATA[Nginx]]></category>
		<category><![CDATA[Nginx Installation (安装)]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Relational Database (SQL) (关系型数据库 )]]></category>
		<category><![CDATA[Service (服务)]]></category>
		<category><![CDATA[Shell]]></category>
		<category><![CDATA[Shell Deployment (部署)]]></category>
		<category><![CDATA[Shell Tools (工具)]]></category>
		<category><![CDATA[Shell Website (网站)]]></category>
		<category><![CDATA[Website Service (网站服务)]]></category>
		<guid isPermaLink="false">https://eternalcenter-sep-2022.github.io/?p=14333</guid>

					<description><![CDATA[介绍 基本信息 作者：朱明宇名称：自动化部署 LNMP + SSL 平台作用：自动化安装 LNMP + SSL，即通过 Linux、Nginx、MariaDB、PHP、php-fpm、SSL，实现 HTTPS 使用方法 1. 将网站的网页数据备份、网站的 SSL 公钥、网站的 SSL 私钥、网站的数据库备份和本脚本，5 个文件放在同一目录下2. 如果没有网站的数据库备份则将网页数据备份、网站的 SSL 公钥、网站的 SSL 私钥和本脚本，4 个文件放在同一目录下3. 在此脚本的分割线内写入相应的内容4. 开启系统的 selinux5. 给此脚本添加执行权限6. 执行此脚本：./&#60;执行本脚本&#62; 脚本分割线里的变量 1. webdomain=&#8221;eternalcenter.com&#8221; #网站的域名，注意不要在前面加任何前缀2. webtar=&#8221;eternalcenter-backup-*.tar.gz&#8221; #网站的网页数据备份，如果没有这个备份，可以下载一个开源的 WordPress 网页程序3. webcrt=&#8221;eternalcenter.com.crt&#8221; #网站 SSL 的公钥，可以自己创建也可以在 FreeSSl 上申请4. webkey=&#8221;eternalcenter.com.key&#8221; #网站 SSL 的私钥，可以自己创建也可以在 FreeSSL 上申请5. sqlbackup=&#8221;eternalcenter-backup-*.sql&#8221; #网站数据库数据备份，如果没有这个备份（数据库是全量备份），则这里可以为空6. db=&#8221;ec&#8221; #网站在数据库中库7. &#8230; <p class="link-more"><a href="https://eternalcenter-sep-2022.github.io/shell-lnmp-install-opensuse-leap-15/" class="more-link">Continue reading<span class="screen-reader-text"> "[工具] Shell 自动化部署 LNMP + SSL 平台 （openSUSE Leap 15 版）"</span></a></p>]]></description>
										<content:encoded><![CDATA[
<h2>介绍</h2>



<h3>基本信息</h3>



<p>作者：朱明宇<br>名称：自动化部署 LNMP + SSL 平台<br>作用：自动化安装 LNMP + SSL，即通过 Linux、Nginx、MariaDB、PHP、php-fpm、SSL，实现 HTTPS</p>



<h3>使用方法</h3>



<p>1. 将网站的网页数据备份、网站的 SSL 公钥、网站的 SSL 私钥、网站的数据库备份和本脚本，5 个文件放在同一目录下<br>2. 如果没有网站的数据库备份则将网页数据备份、网站的 SSL 公钥、网站的 SSL 私钥和本脚本，4 个文件放在同一目录下<br>3. 在此脚本的分割线内写入相应的内容<br>4. 开启系统的 selinux<br>5. 给此脚本添加执行权限<br>6. 执行此脚本：./&lt;执行本脚本&gt;</p>



<h3>脚本分割线里的变量</h3>



<p>1. webdomain=&#8221;eternalcenter.com&#8221; #网站的域名，注意不要在前面加任何前缀<br>2. webtar=&#8221;eternalcenter-backup-*.tar.gz&#8221; #网站的网页数据备份，如果没有这个备份，可以下载一个开源的 WordPress 网页程序<br>3. webcrt=&#8221;eternalcenter.com.crt&#8221; #网站 SSL 的公钥，可以自己创建也可以在 FreeSSl 上申请<br>4. webkey=&#8221;eternalcenter.com.key&#8221; #网站 SSL 的私钥，可以自己创建也可以在 FreeSSL 上申请<br>5. sqlbackup=&#8221;eternalcenter-backup-*.sql&#8221; #网站数据库数据备份，如果没有这个备份（数据库是全量备份），则这里可以为空<br>6. db=&#8221;ec&#8221; #网站在数据库中库<br>7. dbuser=&#8221;ec&#8221; #网站在数据库中的用户<br>8. dbuserpw=&#8221;eternalcenter&#8221; #网站在数据库中的用户密码<br>9. dbrootpw=&#8221;eternalcenter&#8221; #数据库的 root 密码</p>



<h3>注意</h3>



<p>1. 服务器的系统需要是 openSUSE 15 版本<br>2. 服务器系统要配置好可用的软件源（最好是软件数量最多的官方版本）<br>3. 服务器要能够连接外网</p>



<h2>脚本</h2>



<pre class="wp-block-code"><code>#!/bin/bash

####################### Separator ########################
webdomain="eternalcenter.com"
webtar="eternalcenter-backup-*.tar.gz"
webcrt="eternalcenter.com.crt"
webkey="eternalcenter.com.key"
sqlbackup="eternalcenter-backup-*.sql"
db="ec"
dbuser="ec"
dbuserpw="eternalcenter"
dbrootpw="eternalcenter"
####################### Separator ########################

#判断所需文件是否存在
ls $webtar
if &#91; $? -ne 0 ];then
	echo "没有网页数据备份，无法继续"
	exit 2
fi

ls $webcrt
if &#91; $? -ne 0 ];then
	echo "没有网站公钥，无法继续"
	exit 2
fi

ls $webkey
if &#91; $? -ne 0 ];then
	echo "没有网站私钥，无法继续"
	exit 2
fi

#更新系统
zypper ref
zypper -n update

#确保必需软件已经安装
zypper -n in tar
zypper -n in firewalld


#部署 Nginx
zypper -n in nginx

echo 'worker_processes  1;

events {
    worker_connections  1024;
}

http {
    limit_req_zone $binary_remote_addr zone=one:10m rate=1r/s;
    include       mime.types;
    default_type  application/octet-stream;

    sendfile        on;

    keepalive_timeout  60;
    client_body_timeout 20s;
    client_header_timeout 10s;
    send_timeout 30s;

    server {
        listen       80;
        limit_req zone=one burst=5;
        server_name www.eternalcenter.com eternalcenter.com;

        rewrite ^/(.*)$ https://eternalcenter-sep-2022.github.io/$1 permanent;
      
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }

        }

    server {
        listen 443 ssl;
        server_name www.eternalcenter.com eternalcenter.com;

        if ($request_method !~ ^(GET|POST)$){
        return 444;
        }

        ssl_certificate      /etc/nginx/ssl/eternalcenter.com.crt;
        ssl_certificate_key  /etc/nginx/ssl/eternalcenter.com.key;

        ssl_session_cache    shared:SSL:1m;
        ssl_session_timeout  5m;

        ssl_ciphers  HIGH:!aNULL:!MD5;
        ssl_prefer_server_ciphers  on;

        root /srv/www/htdocs;

        location / {
            index index.php;
            try_files $uri $uri/ /index.php$is_args$args;
            if (-f $request_filename/index.html){rewrite (.) $1/index.html break;}
            if (-f $request_filename/index.php){rewrite (.) $1/index.php;}
            if (!-f $request_filename){rewrite (.) /index.php;}
        }

        location ~ \.php$ {
            include fastcgi_params;
	    include fastcgi.conf;
            fastcgi_pass 127.0.0.1:9000;
            fastcgi_index index.php;
            fastcgi_param SCRIPT_FILENAME /srv/www/htdocs/$fastcgi_script_name;

        }
	
	location ~ ^/\.user\.ini {
            deny all;
        }

        location ~*\.(jpd|jpeg|gif|png|css|js|ico|xml)$ {
            expires 30d;
        }

        error_page  404              /404.html;
    }

        gzip on;
	gzip_min_length 1000;
	gzip_comp_level 4;
	gzip_types text/plain test/css application/json application/x-javascript text/xml application/xml
	application/xml+rss text/javascripts;

	client_header_buffer_size 1k;

	open_file_cache_valid  60s;
	open_file_cache_min_uses 5;
	open_file_cache_errors off;

}' > /etc/nginx/nginx.conf

sed -i "s/server_name www.eternalcenter.com eternalcenter.com;/server_name www.$webdomain $webdomain;/" /etc/nginx/nginx.conf
sed -i "s@rewrite ^/(.*)$ https://eternalcenter-sep-2022.github.io/\$1 permanent@rewrite ^/(.*)$ https://$webdomain/\$1 permanent@" /etc/nginx/nginx.conf;
sed -i "s/eternalcenter.com.crt/$webcrt/" /etc/nginx/nginx.conf
sed -i "s/eternalcenter.com.key/$webkey/" /etc/nginx/nginx.conf

mkdir /etc/nginx/ssl
mv $webcrt /etc/nginx/ssl
mv $webkey /etc/nginx/ssl

rm -rf /srv/www/htdocs/*
tar -xvf $webtar -C /srv/www/htdocs/ &amp;&amp; rm -rf $webtar

zypper -n in policycoreutils

systemctl start nginx
systemctl enable nginx

#部署 MariaDB
zypper -n in mariadb mariadb-server

grep "^log_bin=" /etc/my.cnf
if &#91; $? -ne 0 ];then
	sed -i '/^datadir/a log_bin=ec' /etc/my.cnf
fi

grep "^binlog_format=" /etc/my.cnf
if &#91; $? -ne 0 ];then
	sed -i '/^datadir/a binlog_format=\"mixed\"' /etc/my.cnf
fi

grep "^server_id=" /etc/my.cnf
if &#91; $? -ne 0 ];then
	sed -i '/^datadir/a server_id=51' /etc/my.cnf
fi

sed -i 's/^plugin-load-add=auth_gssapi.so/#plugin-load-add=auth_gssapi.so/' /etc/my.cnf

sed -i '/^user=.*/d' /etc/my.cnf
sed -i "/\&#91;mysqld\]/a user=mysql" /etc/my.cnf

sed -i '/^bind-address=.*/d' /etc/my.cnf
sed -i "/\&#91;mysqld\]/a bind-address=127.0.0.1" /etc/my.cnf

systemctl start mariadb
systemctl enable mariadb

chown -R mysql:mysql /var/lib/mysql

ls $sqlbackup
if &#91; $? -ne 0 ];then
        mysql -uroot -e "create database $db;"
        mysql -uroot -e "create user \"$dbuser\"@\"localhost\" identified by \"$dbuserpw\";"
        mysql -uroot -e "grant all privileges on $db.* to \"$dbuser\"@\"localhost\" identified by \"$dbuserpw\";"
        mysql -uroot -e "set password for 'root'@'localhost'=password(\"$dbrootpw\")"
else
        mysql -uroot -e "create database $db;"
        mysql -uroot $db &lt; $sqlbackup
        mysql -uroot -e "create user \"$dbuser\"@\"localhost\" identified by \"$dbuserpw\";"
        mysql -uroot -e "grant all privileges on $db.* to \"$dbuser\"@\"localhost\" identified by \"$dbuserpw\";"
        mysql -uroot -e "set password for 'root'@'localhost'=password(\"$dbrootpw\")"
        rm -rf $sqlbackup
fi
	
systemctl restart mariadb

#部署 PHP
zypper -n in php7 php7-fpm php7-mysql php7-gd php7-mbstring php7-opcache php7-json php7-xmlrpc php7-zlib
useradd php-fpm -s /sbin/nologin
groupadd php-fpm
chown -R php-fpm:php-fpm /srv/www/htdocs
cp /etc/php7/fpm/php-fpm.conf.default /etc/php7/fpm/php-fpm.conf

sed -i /"^user =.*"/d /etc/php7/fpm/php-fpm.conf
sed -i /"^group =.*"/d /etc/php7/fpm/php-fpm.conf
sed -i /"^listen =.*"/d /etc/php7/fpm/php-fpm.conf
sed -i /"^&#91;www]"/d /etc/php7/fpm/php-fpm.conf
sed -i /"^pm = .*"/d /etc/php7/fpm/php-fpm.conf
sed -i /"^pm.start_servers = .*"/d /etc/php7/fpm/php-fpm.conf
sed -i /"^pm.min_spare_servers = .*"/d /etc/php7/fpm/php-fpm.conf
sed -i /"^pm.max_spare_servers = .*"/d /etc/php7/fpm/php-fpm.conf
sed -i /"^pm.max_children = .*"/d /etc/php7/fpm/php-fpm.conf
sed -i /"^pm.max_requests = .*"/d /etc/php7/fpm/php-fpm.conf
sed -i /"^request_terminate_timeout = .*"/d /etc/php7/fpm/php-fpm.conf

echo '&#91;www]' >> /etc/php7/fpm/php-fpm.conf
echo 'user = php-fpm' >> /etc/php7/fpm/php-fpm.conf
echo 'group = php-fpm' >> /etc/php7/fpm/php-fpm.conf
echo 'listen = 127.0.0.1:9000' >> /etc/php7/fpm/php-fpm.conf
echo 'pm = dynamic' >> /etc/php7/fpm/php-fpm.conf
echo 'pm.start_servers = 2' >> /etc/php7/fpm/php-fpm.conf
echo 'pm.min_spare_servers = 2' >> /etc/php7/fpm/php-fpm.conf
echo 'pm.max_spare_servers = 4' >> /etc/php7/fpm/php-fpm.conf
echo 'pm.max_children = 4' >> /etc/php7/fpm/php-fpm.conf
echo 'pm.max_requests = 1024' >> /etc/php7/fpm/php-fpm.conf
echo 'request_terminate_timeout = 300' >> /etc/php7/fpm/php-fpm.conf

systemctl start php-fpm
systemctl enable php-fpm

#提高系统性能
grep "^* soft nofile" /etc/security/limits.conf
if &#91; $? -ne 0 ];then
	echo '* soft nofile 1024' >> /etc/security/limits.conf
fi

grep "^* hard nofile" /etc/security/limits.conf
if &#91; $? -ne 0 ];then
	echo '* hard nofile 1024' >> /etc/security/limits.conf
fi

#打开防火墙
systemctl start firewalld
systemctl enable firewalld
firewall-cmd --add-port=80/tcp --permanent
firewall-cmd --add-port=443/tcp --permanent
firewall-cmd --reload

#限制日志占用空间
echo "/var/log/mariadb/mariadb.log {
        create 600 mysql mysql
        notifempty
	daily
        rotate 3
        missingok
        compress
    postrotate
	# just if mysqld is really running
        if &#91; -e /run/mariadb/mariadb.pid ]
        then
           kill -1 $(&lt;/run/mariadb/mariadb.pid)
        fi
    endscript
}" > /etc/logrotate.d/mariadb

echo "/var/log/nginx/*log {
    create 0664 nginx root
    size 1024M
    rotate 1
    missingok
    notifempty
    compress
    sharedscripts
    postrotate
        /bin/kill -USR1 `cat /run/nginx.pid 2>/dev/null` 2>/dev/null || true
    endscript
}" > /etc/logrotate.d/nginx

echo "/var/log/php-fpm/*log {
    size 100M
    rotate 1
    missingok
    notifempty
    sharedscripts
    delaycompress
    postrotate
        /bin/kill -SIGUSR1 `cat /run/php-fpm/php-fpm.pid 2>/dev/null` 2>/dev/null || true
    endscript
}" > /etc/logrotate.d/php-fpm

echo "/var/log/cron
/var/log/maillog
/var/log/messages
/var/log/secure
/var/log/spooler
{
    size 100M
    rotate 1
    missingok
    sharedscripts
    postrotate
        /usr/bin/systemctl kill -s HUP rsyslog.service >/dev/null 2>&amp;1 || true
    endscript
}" > /etc/logrotate.d/syslog

#删除此脚本
scriptwhere=`readlink -f "$0"`
rm -rf $scriptwhere

#重启系统
reboot</code></pre>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>[步骤] MariaDB 的安装</title>
		<link>https://eternalcenter-sep-2022.github.io/mariadb-install/</link>
		
		<dc:creator><![CDATA[Mingyu Zhu]]></dc:creator>
		<pubDate>Mon, 05 Oct 2020 07:04:59 +0000</pubDate>
				<category><![CDATA[Chinese (中文)]]></category>
		<category><![CDATA[Database (数据库)]]></category>
		<category><![CDATA[MariaDB]]></category>
		<category><![CDATA[Relational Database (SQL) (关系型数据库 )]]></category>
		<guid isPermaLink="false">https://eternalcenter-sep-2022.github.io/?p=11192</guid>

					<description><![CDATA[步骤一：系统环境要求 服务器系统要配置好可用的软件源 2.1 CentOS&#38;RHEL 安装 MariaDB 2.2 openSUSE&#38;SUSE 安装 MariaDB]]></description>
										<content:encoded><![CDATA[
<h3>步骤一：系统环境要求</h3>



<p>服务器系统要配置好可用的软件源</p>



<h4>2.1 CentOS&amp;RHEL 安装 MariaDB</h4>



<pre class="wp-block-code"><code># yum -y install mariadb mariadb-devel mariadb-server</code></pre>



<h4>2.2 openSUSE&amp;SUSE 安装 MariaDB</h4>



<pre class="wp-block-code"><code># zypper -n mariadb mariadb-devel mariadb-server</code></pre>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>[工具] Shell 在 MariaDB &#038; MySQL 的配置文件里设置部分安全策略</title>
		<link>https://eternalcenter-sep-2022.github.io/shell-mariadb-mysql-securtiy/</link>
		
		<dc:creator><![CDATA[Mingyu Zhu]]></dc:creator>
		<pubDate>Sun, 12 Apr 2020 08:22:54 +0000</pubDate>
				<category><![CDATA[Chinese (中文)]]></category>
		<category><![CDATA[Database (数据库)]]></category>
		<category><![CDATA[Language (语言)]]></category>
		<category><![CDATA[MariaDB]]></category>
		<category><![CDATA[Relational Database (SQL) (关系型数据库 )]]></category>
		<category><![CDATA[Shell]]></category>
		<category><![CDATA[Shell Database (数据库)]]></category>
		<category><![CDATA[Shell Tools (工具)]]></category>
		<guid isPermaLink="false">https://eternalcenter-sep-2022.github.io/?p=8736</guid>

					<description><![CDATA[介绍： 作者:朱明宇名称:在 MariaDB &#38; MySQL 的配置文件里设置部分安全策略作用:在 MariaDB &#38; MySQL 的配置文件里设置部分安全策略 使用方法:1. 确认 MariaDB &#38; MySQL 已提前装好2. 在此脚本的分割线内写入相应的内容3. 给此脚本增加执行权限4. 执行此脚本 脚本：]]></description>
										<content:encoded><![CDATA[
<h2>介绍：</h2>



<p>作者:朱明宇<br>名称:在 MariaDB &amp; MySQL 的配置文件里设置部分安全策略<br>作用:在 MariaDB &amp; MySQL 的配置文件里设置部分安全策略</p>



<p>使用方法:<br>1. 确认 MariaDB &amp; MySQL 已提前装好<br>2. 在此脚本的分割线内写入相应的内容<br>3. 给此脚本增加执行权限<br>4. 执行此脚本</p>



<h2>脚本：</h2>



<pre class="wp-block-code"><code>#!/bin/bash

#At the system level, start the database as a MySQL user
chown -R mysql /var/lib/mysql
sed -i '/^user=/d' /etc/my.cnf.d/mariadb-server.cnf
sed -i '/^datadir/a user=mysql' /etc/my.cnf.d/mariadb-server.cnf

#Disable client local data reading at the system level
sed -i '/^local-infile=/d' /etc/my.cnf.d/mariadb-server.cnf
sed -i '/^datadir/a local-infile=0' /etc/my.cnf.d/mariadb-server.cnf

#At the system level, remote login of database is prohibited
sed -i '/^bind-address=/d' /etc/my.cnf.d/mariadb-server.cnf
sed -i '/^datadir/a bind-address=127.0.0.1' /etc/my.cnf.d/mariadb-server.cnf

#Restart database
systemctl restart mariadb ; systemctl restart mysql</code></pre>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>[工具] Shell 自动化部署 LNMP + SSL 平台 （CentOS Linux 8 版）</title>
		<link>https://eternalcenter-sep-2022.github.io/shell-lnmp-install-centos-linux-8/</link>
		
		<dc:creator><![CDATA[Mingyu Zhu]]></dc:creator>
		<pubDate>Sat, 11 Apr 2020 15:29:16 +0000</pubDate>
				<category><![CDATA[Chinese (中文)]]></category>
		<category><![CDATA[Database (数据库)]]></category>
		<category><![CDATA[Language (语言)]]></category>
		<category><![CDATA[MariaDB]]></category>
		<category><![CDATA[Nginx]]></category>
		<category><![CDATA[Nginx Installation (安装)]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Relational Database (SQL) (关系型数据库 )]]></category>
		<category><![CDATA[Service (服务)]]></category>
		<category><![CDATA[Shell]]></category>
		<category><![CDATA[Shell Deployment (部署)]]></category>
		<category><![CDATA[Shell Tools (工具)]]></category>
		<category><![CDATA[Shell Website (网站)]]></category>
		<category><![CDATA[Website Service (网站服务)]]></category>
		<guid isPermaLink="false">https://eternalcenter-sep-2022.github.io/?p=8720</guid>

					<description><![CDATA[介绍 基本信息 作者：朱明宇名称：自动化部署 LNMP + SSL 平台作用：自动化安装 LNMP + SSL，即通过 Linux、Nginx、MariaDB、PHP、php-fpm、SSL，实现 HTTPS 使用方法 1. 将网站的网页数据备份、网站的 SSL 公钥、网站的 SSL 私钥、网站的数据库备份和本脚本，5 个文件放在同一目录下2. 如果没有网站的数据库备份则将网页数据备份、网站的 SSL 公钥、网站的 SSL 私钥和本脚本，4 个文件放在同一目录下3. 在此脚本的分割线内写入相应的内容4. 服务器都要开启 SELinux5. 给此脚本添加执行权限6. 执行此脚本：./&#60;此脚本&#62; 脚本分割线里的变量 1. webdomain=&#8221;eternalcenter.com&#8221; #网站的域名，注意不要在前面加任何前缀2. webtar=&#8221;eternalcenter-backup-*.tar.gz&#8221;网站的网页数据备份，如果没有这个备份，可以下载一个开源的 WordPress 网页程序3. webcrt=&#8221;eternalcenter.com.crt&#8221; #网站 SSL 的公钥，可以自己创建也可以在 FreeSSL 上申请4. webkey=&#8221;eternalcenter.com.key&#8221; #网站 SSL 的私钥，可以自己创建也可以在 FreeSSL 上申请5. sqlbackup=&#8221;eternalcenter-backup-*.sql&#8221; #网站数据库数据备份，如果没有这个备份（数据库是全量备份），则这里可以为空6. db=&#8221;ec&#8221; #网站在数据库中库7. dbuser=&#8221;ec&#8221; &#8230; <p class="link-more"><a href="https://eternalcenter-sep-2022.github.io/shell-lnmp-install-centos-linux-8/" class="more-link">Continue reading<span class="screen-reader-text"> "[工具] Shell 自动化部署 LNMP + SSL 平台 （CentOS Linux 8 版）"</span></a></p>]]></description>
										<content:encoded><![CDATA[
<h2>介绍</h2>



<h3>基本信息</h3>



<p>作者：朱明宇<br>名称：自动化部署 LNMP + SSL 平台<br>作用：自动化安装 LNMP + SSL，即通过 Linux、Nginx、MariaDB、PHP、php-fpm、SSL，实现 HTTPS</p>



<h3>使用方法</h3>



<p>1. 将网站的网页数据备份、网站的 SSL 公钥、网站的 SSL 私钥、网站的数据库备份和本脚本，5 个文件放在同一目录下<br>2. 如果没有网站的数据库备份则将网页数据备份、网站的 SSL 公钥、网站的 SSL 私钥和本脚本，4 个文件放在同一目录下<br>3. 在此脚本的分割线内写入相应的内容<br>4. 服务器都要开启 SELinux<br>5. 给此脚本添加执行权限<br>6. 执行此脚本：./&lt;此脚本&gt;</p>



<h3>脚本分割线里的变量</h3>



<p>1. webdomain=&#8221;eternalcenter.com&#8221; #网站的域名，注意不要在前面加任何前缀<br>2. webtar=&#8221;eternalcenter-backup-*.tar.gz&#8221;网站的网页数据备份，如果没有这个备份，可以下载一个开源的 WordPress 网页程序<br>3. webcrt=&#8221;eternalcenter.com.crt&#8221; #网站 SSL 的公钥，可以自己创建也可以在 FreeSSL 上申请<br>4. webkey=&#8221;eternalcenter.com.key&#8221; #网站 SSL 的私钥，可以自己创建也可以在 FreeSSL 上申请<br>5. sqlbackup=&#8221;eternalcenter-backup-*.sql&#8221; #网站数据库数据备份，如果没有这个备份（数据库是全量备份），则这里可以为空<br>6. db=&#8221;ec&#8221; #网站在数据库中库<br>7. dbuser=&#8221;ec&#8221; #网站在数据库中的用户<br>8. dbuserpw=&#8221;eternalcenter&#8221; #网站在数据库中的用户密码<br>9. dbrootpw=&#8221;eternalcenter&#8221; #数据库的 root 密码</p>



<h3>注意</h3>



<p>1. 服务器的系统需要是 CentOS 8 版本<br>2. 服务器系统要配置好可用的软件源<br>3. 服务器要能够连接外网</p>



<h2>脚本</h2>



<pre class="wp-block-code"><code>#!/bin/bash

####################### Separator ########################
webdomain="eternalcenter.com"
webtar="eternalcenter-backup-*.tar.gz"
webcrt="eternalcenter.com.crt"
webkey="eternalcenter.com.key"
sqlbackup="eternalcenter-backup-*.sql"
db="ec"
dbuser="ec"
dbuserpw="eternalcenter"
dbrootpw="eternalcenter"
####################### Separator ########################

#Determine whether SELinux is on
getenforce | grep Enforcing
if &#91; $? -ne 0 ];then
	echo "SELinux is not set to enforcing mode and cannot continue"
	exit 2
fi

#Determine whether the required file exists
ls $webtar
if &#91; $? -ne 0 ];then
	echo "No web page data backup, unable to continue"
	exit 2
fi

ls $webcrt
if &#91; $? -ne 0 ];then
	echo "Cannot continue without site public key"
	exit 2
fi

ls $webkey
if &#91; $? -ne 0 ];then
	echo "Unable to continue without site private key"
	exit 2
fi

#Update system
yum clean all
yum repolist
yum makecache
yum -y update

#Make sure the required software is installed
yum -y install tar
yum -y install firewalld

#Deploying Nginx
yum -y install nginx

echo 'worker_processes  1;

events {
    worker_connections  1024;
}

http {
    limit_req_zone $binary_remote_addr zone=one:10m rate=1r/s;
    include       mime.types;
    default_type  application/octet-stream;

    sendfile        on;

    keepalive_timeout  60;
    client_body_timeout 20s;
    client_header_timeout 10s;
    send_timeout 30s;

    server {
        listen       80;
        limit_req zone=one burst=5;
        server_name www.eternalcenter.com eternalcenter.com;

        rewrite ^/(.*)$ https://eternalcenter-sep-2022.github.io/$1 permanent;
      
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }

        }

    server {
        listen       443 ssl;
        server_name www.eternalcenter.com eternalcenter.com;

        if ($request_method !~ ^(GET|POST)$){
        return 444;
        }

        ssl_certificate      /etc/nginx/ssl/eternalcenter.com.crt;
        ssl_certificate_key  /etc/nginx/ssl/eternalcenter.com.key;

        ssl_session_cache    shared:SSL:1m;
        ssl_session_timeout  5m;

        ssl_ciphers  HIGH:!aNULL:!MD5;
        ssl_prefer_server_ciphers  on;

        location ~ \.php$ {
            fastcgi_pass 127.0.0.1:9000;
            fastcgi_index index.php;
            include fastcgi.conf;
            fastcgi_param  SCRIPT_FILENAME  /usr/share/nginx/html/$fastcgi_script_name;
            include fastcgi_params;
        } 

        location / {
        root html;
        index index.php index.html index.htm;

        if (-f $request_filename/index.html){rewrite (.) $1/index.html break;}
        if (-f $request_filename/index.php){rewrite (.) $1/index.php;}
        if (!-f $request_filename){rewrite (.) /index.php;}
        
        }

        location ~ ^/\.user\.ini {
        deny all;
        }
    
        location ~*\.(jpd|jpeg|gif|png|css|js|ico|xml)$ {
        expires 30d;
        }

        error_page  404              /404.html;

        }

        gzip on;
	gzip_min_length 1000;
	gzip_comp_level 4;
	gzip_types text/plain test/css application/json application/x-javascript text/xml application/xml
	application/xml+rss text/javascripts;

	client_header_buffer_size 1k;
	large_client_header_buffers 4 4k;

	open_file_cache max=2000 inactive=20s;
	open_file_cache_valid  60s;
	open_file_cache_min_uses 5;
	open_file_cache_errors off;

}' > /etc/nginx/nginx.conf

sed -i "s/server_name www.eternalcenter.com eternalcenter.com;/server_name www.$webdomain $webdomain;/" /etc/nginx/nginx.conf
sed -i "s@rewrite ^/(.*)$ https://eternalcenter-sep-2022.github.io/\$1 permanent@rewrite ^/(.*)$ https://$webdomain/\$1 permanent@" /etc/nginx/nginx.conf;
sed -i "s/eternalcenter.com.crt/$webcrt/" /etc/nginx/nginx.conf
sed -i "s/eternalcenter.com.key/$webkey/" /etc/nginx/nginx.conf

mkdir /etc/nginx/ssl
mv $webcrt /etc/nginx/ssl
mv $webkey /etc/nginx/ssl
chcon -t httpd_config_t /etc/nginx/ssl/$webcrt
chcon -t httpd_config_t /etc/nginx/ssl/$webkey
chcon -t httpd_config_t /etc/nginx/ssl/

rm -rf /usr/share/nginx/html/*
tar -xvf $webtar -C /usr/share/nginx/html/ &amp;&amp; rm -rf $webtar
chcon -t httpd_sys_content_t -R /usr/share/nginx/html/*

yum -y install sendmail
yum -y install policycoreutils
setsebool -P httpd_can_network_connect 1
setsebool -P httpd_can_network_connect_db 1
setsebool -P httpd_can_sendmail 1
setsebool -P httpd_can_connect_ftp 1
setsebool -P httpd_unified 1
setsebool -P httpd_enable_cgi 1
setsebool -P httpd_builtin_scripting 1
setsebool -P mysql_connect_http 1

systemctl start nginx
systemctl enable nginx

#Deploy MariaDB
yum -y install mariadb mariadb-server

grep "^log_bin=" /etc/my.cnf.d/mariadb-server.cnf
if &#91; $? -ne 0 ];then
	sed -i '/^datadir/a log_bin=ec' /etc/my.cnf.d/mariadb-server.cnf
fi

grep "^binlog_format=" /etc/my.cnf.d/mariadb-server.cnf
if &#91; $? -ne 0 ];then
	sed -i '/^datadir/a binlog_format=\"mixed\"' /etc/my.cnf.d/mariadb-server.cnf
fi

grep "^server_id=" /etc/my.cnf.d/mariadb-server.cnf
if &#91; $? -ne 0 ];then
	sed -i '/^datadir/a server_id=51' /etc/my.cnf.d/mariadb-server.cnf
fi

sed -i 's/^plugin-load-add=auth_gssapi.so/#plugin-load-add=auth_gssapi.so/' /etc/my.cnf.d/auth_gssapi.cnf

sed -i '/^user=.*/d' /etc/my.cnf.d/mariadb-server.cnf
sed -i "/\&#91;mysqld\]/a user=mysql" /etc/my.cnf.d/mariadb-server.cnf

sed -i '/^bind-address=.*/d' /etc/my.cnf.d/mariadb-server.cnf
sed -i "/\&#91;mysqld\]/a bind-address=127.0.0.1" /etc/my.cnf.d/mariadb-server.cnf

chown -R mysql /var/lib/mysql

systemctl start mariadb
systemctl enable mariadb

ls $sqlbackup
if &#91; $? -ne 0 ];then
        mysql -uroot -e "create database $db;"
        mysql -uroot -e "create user \"$dbuser\"@\"localhost\" identified by \"$dbuserpw\";"
        mysql -uroot -e "grant all privileges on $db.* to \"$dbuser\"@\"localhost\" identified by \"$dbuserpw\";"
        mysql -uroot -e "set password for 'root'@'localhost'=password(\"$dbrootpw\")"
else
        mysql -uroot -e "create database $db;"
        mysql -uroot $db &lt; $sqlbackup
	mysql -uroot -e "create user \"$dbuser\"@\"localhost\" identified by \"$dbuserpw\";"
	mysql -uroot -e "grant all privileges on $db.* to \"$dbuser\"@\"localhost\" identified by \"$dbuserpw\";"
	mysql -uroot -e "set password for 'root'@'localhost'=password(\"$dbrootpw\")"
	rm -rf $sqlbackup
fi
	
systemctl restart mariadb

#Deploy PHP
yum -y install php php-fpm php-mysqlnd php-gd php-mbstring php-opcache php-json php-xml php-xmlrpc php-pecl-zip
useradd php-fpm -s /sbin/nologin
chown -R php-fpm:php-fpm /usr/share/nginx/html

sed -i /"^user =.*"/d /etc/php-fpm.conf
sed -i /"^group =.*"/d /etc/php-fpm.conf
sed -i /"^listen =.*"/d /etc/php-fpm.conf
sed -i /"^&#91;www]"/d /etc/php-fpm.conf
sed -i /"^pm = .*"/d /etc/php-fpm.conf
sed -i /"^pm.start_servers = .*"/d /etc/php-fpm.conf
sed -i /"^pm.min_spare_servers = .*"/d /etc/php-fpm.conf
sed -i /"^pm.max_spare_servers = .*"/d /etc/php-fpm.conf
sed -i /"^pm.max_children = .*"/d /etc/php-fpm.conf
sed -i /"^pm.max_requests = .*"/d /etc/php-fpm.conf
sed -i /"^request_terminate_timeout = .*"/d /etc/php-fpm.conf

echo '&#91;www]' >> /etc/php-fpm.conf
echo 'user = php-fpm' >> /etc/php-fpm.conf
echo 'group = php-fpm' >> /etc/php-fpm.conf
echo 'listen = 127.0.0.1:9000' >> /etc/php-fpm.conf
echo 'pm = dynamic' >> /etc/php-fpm.conf
echo 'pm.start_servers = 2' >> /etc/php-fpm.conf
echo 'pm.min_spare_servers = 2' >> /etc/php-fpm.conf
echo 'pm.max_spare_servers = 4' >> /etc/php-fpm.conf
echo 'pm.max_children = 4' >> /etc/php-fpm.conf
echo 'pm.max_requests = 1024' >> /etc/php-fpm.conf
echo 'request_terminate_timeout = 300' >> /etc/php-fpm.conf

systemctl start php-fpm
systemctl enable php-fpm

#Improve system performance
grep "^* soft nofile" /etc/security/limits.conf
if &#91; $? -ne 0 ];then
	echo '* soft nofile 1024' >> /etc/security/limits.conf
fi

grep "^* hard nofile" /etc/security/limits.conf
if &#91; $? -ne 0 ];then
	echo '* hard nofile 1024' >> /etc/security/limits.conf
fi

#Open firewall
systemctl start firewalld
systemctl enable firewalld
firewall-cmd --add-port=80/tcp --permanent
firewall-cmd --add-port=443/tcp --permanent
firewall-cmd --reload

#Limit log space
echo "/var/log/mariadb/mariadb.log {
        create 600 mysql mysql
        notifempty
	daily
        rotate 3
        missingok
        compress
    postrotate
	# just if mysqld is really running
        if &#91; -e /run/mariadb/mariadb.pid ]
        then
           kill -1 $(&lt;/run/mariadb/mariadb.pid)
        fi
    endscript
}" > /etc/logrotate.d/mariadb

echo "/var/log/nginx/*log {
    create 0664 nginx root
    size 1024M
    rotate 1
    missingok
    notifempty
    compress
    sharedscripts
    postrotate
        /bin/kill -USR1 `cat /run/nginx.pid 2>/dev/null` 2>/dev/null || true
    endscript
}" > /etc/logrotate.d/nginx

echo "/var/log/php-fpm/*log {
    size 100M
    rotate 1
    missingok
    notifempty
    sharedscripts
    delaycompress
    postrotate
        /bin/kill -SIGUSR1 `cat /run/php-fpm/php-fpm.pid 2>/dev/null` 2>/dev/null || true
    endscript
}" > /etc/logrotate.d/php-fpm

echo "/var/log/cron
/var/log/maillog
/var/log/messages
/var/log/secure
/var/log/spooler
{
    size 100M
    rotate 1
    missingok
    sharedscripts
    postrotate
        /usr/bin/systemctl kill -s HUP rsyslog.service >/dev/null 2>&amp;1 || true
    endscript
}" > /etc/logrotate.d/syslog

#Delete this script
scriptwhere=`readlink -f "$0"`
rm -rf $scriptwhere

#Restart the system
reboot</code></pre>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>[实验] LNMP 平台的搭建 （openSUSE Leap 15 版）</title>
		<link>https://eternalcenter-sep-2022.github.io/lnmp-build-opensuse-leap-15/</link>
		
		<dc:creator><![CDATA[Mingyu Zhu]]></dc:creator>
		<pubDate>Fri, 27 Mar 2020 14:03:55 +0000</pubDate>
				<category><![CDATA[Chinese (中文)]]></category>
		<category><![CDATA[Database (数据库)]]></category>
		<category><![CDATA[Language (语言)]]></category>
		<category><![CDATA[MariaDB]]></category>
		<category><![CDATA[Nginx]]></category>
		<category><![CDATA[Nginx Installation (安装)]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Relational Database (SQL) (关系型数据库 )]]></category>
		<category><![CDATA[Service (服务)]]></category>
		<category><![CDATA[Website Service (网站服务)]]></category>
		<guid isPermaLink="false">https://eternalcenter-sep-2022.github.io/?p=8681</guid>

					<description><![CDATA[步骤一：LNMP 简介 LNMP 是一个实现网站服务的方法，它由 4 样东西组成：1) Linux 系统2) Nginx 网页服务3) MariaDB 数据库4) PHP 网页程序 步骤二：系统环境要求 1) 服务器的系统需要是 openSUSE 15 版本2) 服务器要关闭防火墙3) 服务器系统要配置好可用的软件源（最好是软件数量最多的官方版本） 步骤三：搭建 LNMP 3.1 Nginx 网页服务 3.1.1 安装 Nginx 网页服务 3.1.2 配置 Nginx 网页服务的配置文件 3.1.2.1 删除原有的 Nginx 服务的配置文件 3.1.2.2 创建新的 Nginx 网页服务的配置文件 3.1.2.3 配置 Nginx 网页服务的配置文件 将其中的： 修改为： （补充：这里以让 Nginx 将对于 PHP 的请求传递到本机的 9000 &#8230; <p class="link-more"><a href="https://eternalcenter-sep-2022.github.io/lnmp-build-opensuse-leap-15/" class="more-link">Continue reading<span class="screen-reader-text"> "[实验] LNMP 平台的搭建 （openSUSE Leap 15 版）"</span></a></p>]]></description>
										<content:encoded><![CDATA[
<h3>步骤一：LNMP 简介</h3>



<p>LNMP 是一个实现网站服务的方法，它由 4 样东西组成：<br>1) Linux 系统<br>2) Nginx 网页服务<br>3) MariaDB 数据库<br>4) PHP 网页程序</p>



<h3>步骤二：系统环境要求</h3>



<p>1) 服务器的系统需要是 openSUSE 15 版本<br>2) 服务器要关闭防火墙<br>3) 服务器系统要配置好可用的软件源（最好是软件数量最多的官方版本）</p>



<h3>步骤三：搭建 LNMP</h3>



<h4>3.1 Nginx 网页服务</h4>



<h5>3.1.1 安装 Nginx 网页服务</h5>



<pre class="wp-block-code"><code># zypper -n install nginx</code></pre>



<h5>3.1.2 配置 Nginx 网页服务的配置文件</h5>



<h5>3.1.2.1 删除原有的 Nginx 服务的配置文件</h5>



<pre class="wp-block-code"><code># rm /etc/nginx/nginx.conf</code></pre>



<h5>3.1.2.2 创建新的 Nginx 网页服务的配置文件</h5>



<pre class="wp-block-code"><code># cp /etc/nginx/nginx.conf.default /etc/nginx.conf</code></pre>



<h5>3.1.2.3 配置 Nginx 网页服务的配置文件</h5>



<pre class="wp-block-code"><code># vi /etc/nginx/nginx.conf</code></pre>



<p>将其中的：</p>



<pre class="wp-block-code"><code>......
        location / {
            root   html;
            index  index.html index.htm;
        }
......
        #location ~ \.php$ {
        #    root           html;
        #    fastcgi_pass   127.0.0.1:9000;
        #    fastcgi_index  index.php;
        #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
        #    include        fastcgi_params;
        #}
......</code></pre>



<p>修改为：</p>



<pre class="wp-block-code"><code>......
        location / {
            root   html;
            index  index.php index.html index.htm;
        }
......
        location ~ \.php$ {
            root           html;
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
        #   fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
            include        fastcgi.conf;
        }
......</code></pre>



<p>（补充：这里以让 Nginx 将对于 PHP 的请求传递到本机的 9000 端口为例）</p>



<h5>3.1.3 启动 Nginx 网页服务</h5>



<pre class="wp-block-code"><code># systemctl start nginx</code></pre>



<h4>3.2 MariaDB 数据库</h4>



<h5>3.2.1 安装 MariaDB 数据库</h5>



<pre class="wp-block-code"><code># zypper -n install mariadb mariadb-server</code></pre>



<h5>3.2.2 启动 MariaDB 数据库</h5>



<pre class="wp-block-code"><code># systemctl start mariadb</code></pre>



<h4>3.3 PHP 环境和连接服务</h4>



<h5>3.3.1 安装 PHP 环境和连接服务</h5>



<pre class="wp-block-code"><code># zypper -n install php7 php7-fpm php7-mysql php7-gd php7-mbstring php7-opcache php7-json php7-xmlrpc php7-zlib</code></pre>



<h5>3.3.2 创建提供 PHP 连接服务的用户</h5>



<pre class="wp-block-code"><code># useradd php-fpm -s /sbin/nologin</code></pre>



<h5>3.3.3 配置 PHP 连接服务的配置文件</h5>



<pre class="wp-block-code"><code># vi /etc/php-fpm.conf</code></pre>



<p>将以下内容：</p>



<pre class="wp-block-code"><code>......
user = nouser
group = nouser
......</code></pre>



<p>修改为：</p>



<pre class="wp-block-code"><code>......
user = php-fpm
group = users
listen = 127.0.0.1:9000
......</code></pre>



<p>（<br>补充：这里以<br>1) 以 php-fpm 用户和 users 用户组的身份启动 php-fpm<br>2) 让 php-fpm 监听本地 9000 端口为例<br>）</p>



<h3>步骤四：后续工作</h3>



<p>1) 给 MariaDB 数据库设置用于存储网页数据的用户和密码<br>2) 将 PHP 网页程序放到 Nginx 的网页目录下（/srv/www/htdocs）<br>3) 给 PHP 网页程序设置用于连接 MariaDB 数据库的用户和密码</p>



<h3>步骤五：测试 LNMP 平台</h3>



<p>使用浏览器访问服务器 IP 地址就可以看到对应 PHP 网页了</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>[实验] LNMP 平台的搭建 （CentOS Linux 8 版）</title>
		<link>https://eternalcenter-sep-2022.github.io/lnmp-build-centos-linux-8/</link>
		
		<dc:creator><![CDATA[Mingyu Zhu]]></dc:creator>
		<pubDate>Tue, 21 Jan 2020 14:59:13 +0000</pubDate>
				<category><![CDATA[Chinese (中文)]]></category>
		<category><![CDATA[Database (数据库)]]></category>
		<category><![CDATA[Language (语言)]]></category>
		<category><![CDATA[MariaDB]]></category>
		<category><![CDATA[Nginx]]></category>
		<category><![CDATA[Nginx Installation (安装)]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Relational Database (SQL) (关系型数据库 )]]></category>
		<category><![CDATA[Website Service (网站服务)]]></category>
		<guid isPermaLink="false">https://eternalcenter-sep-2022.github.io/?p=8078</guid>

					<description><![CDATA[步骤一：LNMP 简介 LNMP 是一个实现网站服务的方法，它由 4 样东西组成：1) Linux 系统2) Nginx 网页服务3) MariaDB 数据库4) PHP 网页程序 步骤二：系统环境要求 步骤三：搭建 LNMP 3.1 Nginx 网页服务 3.1.1 安装 Nginx 网页服务 3.1.2 配置 Nginx 网页服务的配置文件 3.1.2.1 删除原有的 Nginx 服务的配置文件 3.1.2.2 创建新的 Nginx 网页服务的配置文件 3.1.2.3 配置 Nginx 网页服务的配置文件 将其中的： 修改为： （补充：这里以让 Nginx 将对于 PHP 的请求传递到本机的 9000 端口为例） 3.1.3 启动 nginx 网页服务 3.2 MariaDB &#8230; <p class="link-more"><a href="https://eternalcenter-sep-2022.github.io/lnmp-build-centos-linux-8/" class="more-link">Continue reading<span class="screen-reader-text"> "[实验] LNMP 平台的搭建 （CentOS Linux 8 版）"</span></a></p>]]></description>
										<content:encoded><![CDATA[
<h3>步骤一：LNMP 简介</h3>



<p>LNMP 是一个实现网站服务的方法，它由 4 样东西组成：<br>1) Linux 系统<br>2) Nginx 网页服务<br>3) MariaDB 数据库<br>4) PHP 网页程序</p>



<h3>步骤二：系统环境要求</h3>



<pre class="wp-block-code"><code>1) 服务器的系统需要是 CentOS Linux 8 版本
2) 服务器要关闭防火墙
3) 服务器要关闭 SELinux
4) 服务器系统要配置好可用的软件源</code></pre>



<h3>步骤三：搭建 LNMP</h3>



<h4>3.1 Nginx 网页服务</h4>



<h5>3.1.1 安装 Nginx 网页服务</h5>



<pre class="wp-block-code"><code># yum -y install nginx</code></pre>



<h5>3.1.2 配置 Nginx 网页服务的配置文件</h5>



<h5>3.1.2.1 删除原有的 Nginx 服务的配置文件</h5>



<pre class="wp-block-code"><code># rm /etc/nginx/nginx.conf</code></pre>



<h5>3.1.2.2 创建新的 Nginx 网页服务的配置文件</h5>



<pre class="wp-block-code"><code># cp /etc/nginx/nginx.conf.default /etc/nginx.conf</code></pre>



<h5>3.1.2.3 配置 Nginx 网页服务的配置文件</h5>



<pre class="wp-block-code"><code># vi /etc/nginx/nginx.conf</code></pre>



<p>将其中的：</p>



<pre class="wp-block-code"><code>......
        location / {
            root   html;
            index  index.html index.htm;
        }
......
        #location ~ \.php$ {
        #    root           html;
        #    fastcgi_pass   127.0.0.1:9000;
        #    fastcgi_index  index.php;
        #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
        #    include        fastcgi_params;
        #}
......</code></pre>



<p>修改为：</p>



<pre class="wp-block-code"><code>......
        location / {
            root   html;
            index  index.php index.html index.htm;
        }
......
        location ~ \.php$ {
            root           html;
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
        #   fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
            include        fastcgi.conf;
        }
......</code></pre>



<p>（补充：这里以让 Nginx 将对于 PHP 的请求传递到本机的 9000 端口为例）</p>



<h5>3.1.3 启动 nginx 网页服务</h5>



<pre class="wp-block-code"><code># systemctl start nginx</code></pre>



<h4>3.2 MariaDB 数据库</h4>



<h5>3.2.1 安装 MariaDB 数据库</h5>



<pre class="wp-block-code"><code># yum -y install mariadb mariadb-server</code></pre>



<h5>3.2.2 启动 MariaDB 数据库</h5>



<pre class="wp-block-code"><code># systemctl start mariadb</code></pre>



<h4>3.3 PHP 环境和连接服务</h4>



<h5>3.3.1 安装 PHP 环境和连接服务</h5>



<pre class="wp-block-code"><code># yum -y install php php-fpm php-mysqlnd php-gd php-mbstring php-opcache php-json php-xml</code></pre>



<h5>3.3.2 创建提供 PHP 连接服务的用户</h5>



<pre class="wp-block-code"><code># useradd php-fpm -s /sbin/nologin</code></pre>



<h5>3.3.3 配置 PHP 连接服务的配置文件</h5>



<pre class="wp-block-code"><code># vi /etc/php-fpm.conf</code></pre>



<p>添加以下内容：</p>



<pre class="wp-block-code"><code>......
&#91;www]
user = php-fpm
group = php-fpm
listen = 127.0.0.1:9000</code></pre>



<p>（补充：这里以让 php-fpm 监听本地 9000 端口为例）</p>



<h5>3.3.4 启动 PHP 连接服务</h5>



<pre class="wp-block-code"><code># systemctl start php-fpm</code></pre>



<h3>步骤四：后续工作</h3>



<p>1) 给 MariaDB 数据库设置用于存储网页数据的用户和密码<br>2) 将 PHP 网页程序放到 Nginx 的网页目录下<br>3) 给 PHP 网页程序设置用于连接 MariaDB 数据库的用户和密码</p>



<h3>步骤五：测试 LNMP 平台</h3>



<p>使用浏览器访问服务器 IP 地址就可以看到对应 PHP 网页了</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>[SQL] MariaDB &#038; MySQL 索引的设置 （转载）</title>
		<link>https://eternalcenter-sep-2022.github.io/mariadb-mysql-index/</link>
		
		<dc:creator><![CDATA[Mingyu Zhu]]></dc:creator>
		<pubDate>Sat, 14 Dec 2019 15:47:58 +0000</pubDate>
				<category><![CDATA[Chinese (中文)]]></category>
		<category><![CDATA[Database (数据库)]]></category>
		<category><![CDATA[MariaDB]]></category>
		<category><![CDATA[MariaDB SQL]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[MySQL SQL]]></category>
		<category><![CDATA[Relational Database (SQL) (关系型数据库 )]]></category>
		<category><![CDATA[Service (服务)]]></category>
		<guid isPermaLink="false">https://eternalcenter-sep-2022.github.io/?p=7956</guid>

					<description><![CDATA[注明：所有转载内容皆直接从被转载文章网页的标题和内容的文本中复制而来]]></description>
										<content:encoded><![CDATA[
<pre class="wp-block-code"><code>mysql 设置索引

1.添加PRIMARY KEY（主键索引）

 语法：ALTER TABLE `表名` ADD PRIMARY KEY ( `列名称` )

mysql&gt;ALTER TABLE `table_name` ADD PRIMARY KEY ( `column` )


2.添加UNIQUE(唯一索引)

语法：ALTER TABLE `表名` ADD UNIQUE ( `列名称`)

mysql&gt;ALTER TABLE `table_name` ADD UNIQUE ( `column`)

3.添加INDEX(普通索引)

语法：ALTER TABLE `表名` ADD INDEX index_name ( `列名称` )

mysql&gt;ALTER TABLE `table_name` ADD INDEX index_name ( `column` )

4.添加FULLTEXT(全文索引)

语法：ALTER TABLE `表名` ADD FULLTEXT ( `列名称`)

mysql&gt;ALTER TABLE `table_name` ADD FULLTEXT ( `column`)

5.添加多列索引

语法：ALTER TABLE `表名` ADD INDEX index_name ( `列名称`, `列名称`, `列名称` )

mysql&gt;ALTER TABLE `table_name` ADD INDEX index_name ( `column1`, `column2`, `column3` )

 

想要查看表有几个字段设置了索引

语法；SHOW INDEX FROM `表名`

mysql&gt;SHOW INDEX FROM `cccinfo`
————————————————
版权声明：本文为CSDN博主「z793397795」的原创文章，遵循 CC 4.0 BY-SA 版权协议，转载请附上原文出处链接及本声明。
原文链接：https://blog.csdn.net/z793397795/article/details/91491546</code></pre>



<p>注明：所有转载内容皆直接从被转载文章网页的标题和内容的文本中复制而来</p>



<div class="wp-block-image"><figure class="aligncenter size-large"><img width="1009" height="225" src="https://eternalcenter-sep-2022.github.io/wp-content/uploads/2019/12/版权申明证明-MariaDBMySQL-索引设置.png" alt="" class="wp-image-7957" srcset="https://eternalcenter-sep-2022.github.io/wp-content/uploads/2019/12/版权申明证明-MariaDBMySQL-索引设置.png 1009w, https://eternalcenter-sep-2022.github.io/wp-content/uploads/2019/12/版权申明证明-MariaDBMySQL-索引设置-300x67.png 300w, https://eternalcenter-sep-2022.github.io/wp-content/uploads/2019/12/版权申明证明-MariaDBMySQL-索引设置-768x171.png 768w" sizes="(max-width: 767px) 89vw, (max-width: 1000px) 54vw, (max-width: 1071px) 543px, 580px" /><figcaption>CC 4.0 BY-SA 版权协议网址：https://creativecommons.org/licenses/by-sa/4.0/deed.z</figcaption></figure></div>



<p></p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>[SQL] MariaDB &#038; MySQL 用户和权限的管理 （转载）</title>
		<link>https://eternalcenter-sep-2022.github.io/mariadb-mysql-user/</link>
		
		<dc:creator><![CDATA[Mingyu Zhu]]></dc:creator>
		<pubDate>Sat, 14 Dec 2019 15:41:15 +0000</pubDate>
				<category><![CDATA[Chinese (中文)]]></category>
		<category><![CDATA[Database (数据库)]]></category>
		<category><![CDATA[MariaDB]]></category>
		<category><![CDATA[MariaDB SQL]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[MySQL SQL]]></category>
		<category><![CDATA[Relational Database (SQL) (关系型数据库 )]]></category>
		<guid isPermaLink="false">https://eternalcenter-sep-2022.github.io/?p=7953</guid>

					<description><![CDATA[注明：所有转载内容皆直接从被转载文章网页的标题和内容的文本中复制而来]]></description>
										<content:encoded><![CDATA[
<pre class="wp-block-code"><code>MySQL用户管理和权限管理

在项目中，一个数据库有很多人需要使用，不能所有的人都使用相同的权限，如果人比较多，一人一个用户也很难管理。一般来说，会分超级管理员权限，管理员权限，读写权限，只读权限等，这样方便管理。当然，具体怎么管理权限根据实际情况来确定。

无论如何，都需要创建多个用户来管理权限。

root 是数据库的超级管理员用户，对于普通开发人员来说，权限太大了，如果不小心做了一些不可逆的操作，后果是非常严重的，并且还不容易查出责任人。

所以 root 用户不会让开发人员使用，一般会由 DBA 或运维人员统一管理，如果没有 DBA，统一由超级管理员 root 来分配。

1. 查看所有用户

MySQL 中所有的用户及权限信息都存储在默认数据库 mysql 的 user 表中。

进入 mysql 数据库，通过 desc user; 可以查看 user 表的结构。

    use mysql;
    desc user;

可以看到 user 中有40多个字段，字段非常多，只要关注主要字段就行了。

其中的主要字段有：

host: 允许访问的主机地址，localhost 为本机，% 为任何主机。
user: 用户名。
authentication_string: 加密后的密码值。

使用 select * from user; 查看 user 表中当前有哪些用户。

select host,user,authentication_string from user;

在安装 MySQL 后，有三个默认的用户。

2. 创建用户

使用 create user '用户名'@'访问主机' identified by '密码'; 创建用户。

create user 'admin'@'localhost' identified by 'Mysql!123';

创建用户后，查看用户，多了刚才创建的 admin，创建成功。

3. 查看用户权限

使用 show grants for '用户名'@'访问主机'; 查看用户的权限。

show grants for 'admin'@'localhost';

在创建用户的时候，如果没有指定权限，默认会赋予 USAGE 权限，这个权限很小，几乎为0，只有连接数据库和查询information_schema 数据库的权限。虽然 *.* 表示所有数据库的所有表，但因为 USAGE 的限制，不能操作所有数据库。

退出 root 用户，登录到 admin 用户，只能看到 information_schema 数据库。

4. 给用户授权

创建 admin 用户，目的是创建一个管理员，所以要给 admin 授权。退出 admin ，重新登录 root 。

在授权时，常用的权限有 CREATE、ALTER、DROP、INSERT、UPDATE、DELETE、SELECT，ALL PRIVILEGES 表示所有权限。

通过 数据库.数据表 指定对哪个数据库的哪个表授权，*.* 表示所有数据库中的所有表。

通过 '用户名'@'访问主机' 来表示用户可以从哪些主机登录， ‘%’ 表示可以从任何主机登录。

使用 grant 权限 on 数据库.数据表 to '用户名'@'访问主机' identified by '密码'; 来给数据库用户授权。

grant all privileges on *.* to 'admin'@'localhost' identified by 'Mysql!123';

给 admin 用户授权后，权限从 USAGE 变成了 ALL PRIVILEGES ，表示 admin 拥有了所有权限。

如果授权没有生效，记得刷新一下权限，使权限生效。

flush privileges；

再重新登陆到 admin 用户上，可以操作所有数据库了。

给用户授权的时候，必须要指定 '用户名'@'访问主机' 来指定用户。如果 '访问主机' 不相同，不是给用户授权，而是创建一个同名同密码的用户，这个用户与原用户可以登陆的主机不相同，权限不同。

grant all privileges on *.* to 'admin'@'%' identified by 'Mysql!123';

执行上面的语句后，user 表中有两个 admin 用户，用户名和密码都一样，但可以登陆的主机不一样。第一次创建的 admin 访问主机是 localhost，执行上面的语句时指定的访问主机是 % ，访问主机不一样，MySQL 会创建两个用户。虽然用户名密码相同，但这是两个不同的用户，两个用户的权限不一样。给两个用户指定不同的权限，在两个用户都有权限的主机登录时，局部用户的权限会覆盖全局用户的权限，当在 localhost 登录时，'admin'@'localhost' 的权限会覆盖 'admin'@'%' 的权限。

对于可以从任何主机登录的用户，在查看用户权限时，可以使用 show grants for 用户名; 来查看权限，指定主机的用户在查看权限时，要跟上访问主机才能查看权限。

5. 创建用户并授权

使用 grant 权限 on 数据库.数据表 to '用户名'@'访问主机' identified by '密码'; 来创建一个用户并指定权限，与上面授权使用的语句相同。

grant create,select on *.* to 'creater'@'%' identified by 'Mysql!123';

创建了一个有读写权限的用户 creater，这个用户拥有所有数据库的 SELECT 和 CREATE 权限，可以从任何主机登录数据库。

6. 修改用户的权限

使用 grant 权限 on 数据库.数据表 to '用户名'@'访问主机' identified by '密码'; 修改用户的权限，其实前面的授权就是修改权限。

grant all privileges on *.* to 'creater'@'%' identified by 'Mysql!123';

修改用户的权限后，creater 的权限从 SELECT 和 CREATE 权限变成了 ALL PRIVILEGES。

7. 删除用户

使用 drop user '用户名'@'访问主机'; 来删除用户。

drop user 'admin'@'localhost';

执行删除操作后，user 表中不再有该用户。

8. 修改用户名和访问主机

使用 rename user '用户名'@'访问主机' to '新用户名'@'新访问主机'; 来修改用户名和用户的访问主机。

rename user 'creater'@'%' to 'create'@'localhost';

修改之后，creater 用户改名 create ，访问主机从 % 变成了 localhost 。

9. 修改用户密码　　

使用 set password for '用户名'@'访问主机' = password('新密码'); 修改用户的密码。

set password for 'create'@'localhost'=password('Mysql@123');

上面创建的 admin 用户和 create 用户密码相同，现在给 create 修改密码，使密码不一样。

以上就是对数据库用户和权限管理的基本操作。这些操作都是对 mysql 数据库中的 user 表进行操作，所以上面的大部分操作都还有另外一种方法，就是通过对 mysql.user 表的增删改查语句来实现。
————————————————
版权声明：本文为CSDN博主「Python碎片」的原创文章，遵循 CC 4.0 BY-SA 版权协议，转载请附上原文出处链接及本声明。
原文链接：https://blog.csdn.net/weixin_43790276/article/details/102674936</code></pre>



<p>注明：所有转载内容皆直接从被转载文章网页的标题和内容的文本中复制而来</p>



<div class="wp-block-image"><figure class="aligncenter size-large"><img loading="lazy" width="1011" height="195" src="https://eternalcenter-sep-2022.github.io/wp-content/uploads/2019/12/版权申明证明-MariaDBMySQL-用户和权限管理.png" alt="" class="wp-image-7954" srcset="https://eternalcenter-sep-2022.github.io/wp-content/uploads/2019/12/版权申明证明-MariaDBMySQL-用户和权限管理.png 1011w, https://eternalcenter-sep-2022.github.io/wp-content/uploads/2019/12/版权申明证明-MariaDBMySQL-用户和权限管理-300x58.png 300w, https://eternalcenter-sep-2022.github.io/wp-content/uploads/2019/12/版权申明证明-MariaDBMySQL-用户和权限管理-768x148.png 768w" sizes="(max-width: 767px) 89vw, (max-width: 1000px) 54vw, (max-width: 1071px) 543px, 580px" /><figcaption>CC 4.0 BY-SA 版权协议网址：https://creativecommons.org/licenses/by-sa/4.0/deed.z</figcaption></figure></div>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>[SQL] MariaDB &#038; MySQL 数据的查询 （转载）</title>
		<link>https://eternalcenter-sep-2022.github.io/mariadb-mysql-select/</link>
		
		<dc:creator><![CDATA[Mingyu Zhu]]></dc:creator>
		<pubDate>Sat, 14 Dec 2019 15:15:27 +0000</pubDate>
				<category><![CDATA[Chinese (中文)]]></category>
		<category><![CDATA[Database (数据库)]]></category>
		<category><![CDATA[MariaDB]]></category>
		<category><![CDATA[MariaDB SQL]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[MySQL SQL]]></category>
		<category><![CDATA[Relational Database (SQL) (关系型数据库 )]]></category>
		<guid isPermaLink="false">https://eternalcenter-sep-2022.github.io/?p=7950</guid>

					<description><![CDATA[注明：所有转载内容皆直接从被转载文章网页的标题和内容的文本中复制而来]]></description>
										<content:encoded><![CDATA[
<pre class="wp-block-code"><code>MySQL基本查询语句

MySQL基本查询语句是掌握MySQL数据查询的基本操作，处理数据所必要掌握的，提高处理数据的能力，速度要熟练掌握基本的查询语句。

1.limit字句

select * from limit 3；查询前三条数据

select * from limit 5，3；查询从第5+1条开始的后三条数据

2.函数：平均数，总和，最大值，最小值和总信息数

平均数：select AVG(age) as 平均 from info；查询info表的平均年龄

总和：select SUM(age) as 年龄总和 from lx;查询lx表格的年龄的总和

最大值：select MAX(age) as 最大年龄 from lx; 查询lx表格里年龄的最大值

最小值：select MIN(age) as 最小年龄 from lx; 查询lx表格中的年龄的最小值

总信息数：select COUNT(*) as 总人数 from lx; 查询lx中的信息条数

3.where子句中的经常使用的运算符：比较运算符和逻辑运算符

比较运算符：
大于&gt; 小于&lt; 小于等于&lt;= 大于等于&gt;= 等于 = 不等于&lt;&gt; !=

区间 ：between…and…
1.select age from student where age&gt;=18 and age&lt;=22;等价于
2.select age from student where age between 18 and 22;

查想查的信息：in
select age from student where age in(19,20,50);
查年龄是19.20.50的人

模糊查询：like
select age from student where name like ‘王%’; 查询姓王的人 %表示任意长度任意字符

不为空：is null

逻辑运算符：
同时成立：and。任一成立：or。不成立：not

4.笛卡尔积：
select 表1.name,表2.score from 表1 s(表1缩写),表2 g(表2缩写) where s.id = g.gradeId；

5.表连接
内连接：select s.name,g.score from student s inner join grade g on s.id=g.gradeId；

左外连接：select s.name,g.score from student s Left join grade g on s.id=g.gradeId

左外连接：select s.name,g.score from student s right join grade g on s.id=g.gradeId
————————————————
版权声明：本文为CSDN博主「我是超级小白」的原创文章，遵循 CC 4.0 BY-SA 版权协议，转载请附上原文出处链接及本声明。
原文链接：https://blog.csdn.net/lady88888888/article/details/103018101</code></pre>



<p>注明：所有转载内容皆直接从被转载文章网页的标题和内容的文本中复制而来</p>



<div class="wp-block-image"><figure class="aligncenter size-large"><img loading="lazy" width="1014" height="193" src="https://eternalcenter-sep-2022.github.io/wp-content/uploads/2019/12/版权申明证明-MariaDBMySQL-数据查询.png" alt="" class="wp-image-7951" srcset="https://eternalcenter-sep-2022.github.io/wp-content/uploads/2019/12/版权申明证明-MariaDBMySQL-数据查询.png 1014w, https://eternalcenter-sep-2022.github.io/wp-content/uploads/2019/12/版权申明证明-MariaDBMySQL-数据查询-300x57.png 300w, https://eternalcenter-sep-2022.github.io/wp-content/uploads/2019/12/版权申明证明-MariaDBMySQL-数据查询-768x146.png 768w" sizes="(max-width: 767px) 89vw, (max-width: 1000px) 54vw, (max-width: 1071px) 543px, 580px" /><figcaption>CC 4.0 BY-SA 版权协议网址：https://creativecommons.org/licenses/by-sa/4.0/deed.z</figcaption></figure></div>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>[SQL] MariaDB &#038; MySQL 表结构的修改 （转载）</title>
		<link>https://eternalcenter-sep-2022.github.io/mariadb-mysql-alter/</link>
		
		<dc:creator><![CDATA[Mingyu Zhu]]></dc:creator>
		<pubDate>Sat, 14 Dec 2019 15:07:08 +0000</pubDate>
				<category><![CDATA[Chinese (中文)]]></category>
		<category><![CDATA[Database (数据库)]]></category>
		<category><![CDATA[MariaDB]]></category>
		<category><![CDATA[MariaDB SQL]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[MySQL SQL]]></category>
		<category><![CDATA[Relational Database (SQL) (关系型数据库 )]]></category>
		<category><![CDATA[Service (服务)]]></category>
		<guid isPermaLink="false">https://eternalcenter-sep-2022.github.io/?p=7947</guid>

					<description><![CDATA[注明：所有转载内容皆直接从被转载文章网页的标题和内容的文本中复制而来]]></description>
										<content:encoded><![CDATA[
<pre class="wp-block-code"><code>MYSQL的修改表结构SQL语句：

-- 查看创表语句
SHOW CREATE TABLE t_login;

-- 查看表结构
desc t_login1;

-- 增加列
ALTER TABLE t_login1 ADD COLUMN COL_1 VARCHAR(10);

-- 修改列
ALTER TABLE t_login1 MODIFY COLUMN COL_1 INT(10);

-- 修改列名称
ALTER TABLE t_login1 CHANGE COL_1 COL_2 VARCHAR(50);

-- 删除列
ALTER TABLE t_login1 DROP COLUMN COL_2;

-- 修改整个表的字符集
ALTER TABLE t_login1 DEFAULT CHARACTER SET UTF8;

-- 修改某个字段的字符集
ALTER TABLE t_login1  CHANGE stu_num stu_num varchar(20) CHARACTER SET utf8;
————————————————
版权声明：本文为CSDN博主「h_j_c_123」的原创文章，遵循 CC 4.0 BY-SA 版权协议，转载请附上原文出处链接及本声明。
原文链接：https://blog.csdn.net/h_j_c_123/article/details/95035434</code></pre>



<p>注明：所有转载内容皆直接从被转载文章网页的标题和内容的文本中复制而来</p>



<div class="wp-block-image"><figure class="aligncenter size-large"><img loading="lazy" width="1014" height="165" src="https://eternalcenter-sep-2022.github.io/wp-content/uploads/2019/12/版权申明证明-MariaDBMySQL-修改表结构.png" alt="" class="wp-image-7948" srcset="https://eternalcenter-sep-2022.github.io/wp-content/uploads/2019/12/版权申明证明-MariaDBMySQL-修改表结构.png 1014w, https://eternalcenter-sep-2022.github.io/wp-content/uploads/2019/12/版权申明证明-MariaDBMySQL-修改表结构-300x49.png 300w, https://eternalcenter-sep-2022.github.io/wp-content/uploads/2019/12/版权申明证明-MariaDBMySQL-修改表结构-768x125.png 768w" sizes="(max-width: 767px) 89vw, (max-width: 1000px) 54vw, (max-width: 1071px) 543px, 580px" /><figcaption>CC 4.0 BY-SA 版权协议网址：https://creativecommons.org/licenses/by-sa/4.0/deed.z</figcaption></figure></div>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>[内容] MariaDB &#038; MySQL 安全调优思路</title>
		<link>https://eternalcenter-sep-2022.github.io/mariadb-mysql-security/</link>
		
		<dc:creator><![CDATA[Mingyu Zhu]]></dc:creator>
		<pubDate>Thu, 21 Nov 2019 15:45:57 +0000</pubDate>
				<category><![CDATA[Chinese (中文)]]></category>
		<category><![CDATA[Database (数据库)]]></category>
		<category><![CDATA[MariaDB]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[Relational Database (SQL) (关系型数据库 )]]></category>
		<guid isPermaLink="false">https://eternalcenter-sep-2022.github.io/?p=6648</guid>

					<description><![CDATA[内容一：数据库运行环境安全 1.1 保证运行数据库的系统是安全的 （步骤略） 1.2 以最小权限用户运行数据库 1.2.1 停止数据库 （补充：这里以停止 MariaDB 数据库为例） 1.2.2 修改数据库目录的 （补充：MariaDB&#38;MySQL 数据库数据默认存放位置是 /var/lib/mysql） 1.2.3 修改配置文件 在： 下面添加： （补充：这里以 MariaDB 数据库的配置文件是 /etc/my.cnf 为例） 1.2.4 启动数据库 （补充：这里以启动 MariaDB 数据库为例） 1.3 将数据库版本升级到更新的版本 （步骤略） 内容二：数据库库安全 2.1 删除所有不用的库 2.1.1 查看所有库的列表 2.1.2 删除测试库 2.2 删除所有测试库 2.2.1 方法一：手动删除所有测试库 2.2.1.1 查看所有库的列表 2.2.1.2 删除测试库 2.2.2 方法二：使用工具删除所有测试库 2.3 禁用客户端本地数据被读取 2.3.1 修改配置文件 在： &#8230; <p class="link-more"><a href="https://eternalcenter-sep-2022.github.io/mariadb-mysql-security/" class="more-link">Continue reading<span class="screen-reader-text"> "[内容] MariaDB &#038; MySQL 安全调优思路"</span></a></p>]]></description>
										<content:encoded><![CDATA[
<h3>内容一：数据库运行环境安全</h3>



<h4>1.1 保证运行数据库的系统是安全的</h4>



<p>（步骤略）</p>



<h4>1.2 以最小权限用户运行数据库</h4>



<h5>1.2.1 停止数据库</h5>



<pre class="wp-block-code"><code># systemctl stop mariadb</code></pre>



<p>（补充：这里以停止 MariaDB 数据库为例）</p>



<h5>1.2.2 修改数据库目录的</h5>



<pre class="wp-block-code"><code># chown -R mysql /var/lib/mysql</code></pre>



<p>（补充：MariaDB&amp;MySQL 数据库数据默认存放位置是 /var/lib/mysql）</p>



<h5>1.2.3 修改配置文件</h5>



<pre class="wp-block-code"><code># vim /etc/my.cnf</code></pre>



<p>在：</p>



<pre class="wp-block-code"><code>......
&#91;mysqld]</code></pre>



<p>下面添加：</p>



<pre class="wp-block-code"><code>user=mysql
......</code></pre>



<p>（补充：这里以 MariaDB 数据库的配置文件是 /etc/my.cnf 为例）</p>



<h5>1.2.4 启动数据库</h5>



<pre class="wp-block-code"><code># systemctl start mariadb</code></pre>



<p>（补充：这里以启动 MariaDB 数据库为例）</p>



<h4>1.3 将数据库版本升级到更新的版本</h4>



<p>（步骤略）</p>



<h3>内容二：数据库库安全</h3>



<h4>2.1 删除所有不用的库</h4>



<h5>2.1.1 查看所有库的列表</h5>



<pre class="wp-block-code"><code>&gt; show databases;</code></pre>



<h5>2.1.2 删除测试库</h5>



<pre class="wp-block-code"><code>&gt; drop database &lt;database&gt;</code></pre>



<h4>2.2 删除所有测试库</h4>



<h5>2.2.1 方法一：手动删除所有测试库</h5>



<h5>2.2.1.1 查看所有库的列表</h5>



<pre class="wp-block-code"><code>&gt; show databases;</code></pre>



<h5>2.2.1.2 删除测试库</h5>



<pre class="wp-block-code"><code>&gt; drop database &lt;database&gt;</code></pre>



<h5>2.2.2 方法二：使用工具删除所有测试库</h5>



<pre class="wp-block-code"><code># sudo mysql_secure_installation</code></pre>



<h4>2.3 禁用客户端本地数据被读取</h4>



<h5>2.3.1 修改配置文件</h5>



<pre class="wp-block-code"><code># vim /etc/my.cnf</code></pre>



<p>在：</p>



<pre class="wp-block-code"><code>......
&#91;mysqld]</code></pre>



<p>下面添加：</p>



<pre class="wp-block-code"><code>local-infile=0
......</code></pre>



<p>（补充：这里以 MariaDB 数据库的配置文件是 /etc/my.cnf 为例）</p>



<p>（注意：此参数对 MariaDB 数据库无效）</p>



<h5>2.3.2 重启数据库</h5>



<pre class="wp-block-code"><code># systemctl restart mariadb</code></pre>



<p>（补充：这里以重启 MariaDB 数据库为例）</p>



<h4>2.4 保护数据的本地存储</h4>



<p>思路如下：<br>1) 使用加密的文件系统存储存放数据库的数据文件<br>2) 使用数据库之外的存储加密产品<br>3) 使用其他加密产品实现适当的数据保护</p>



<h3>内容三：数据库登录安全</h3>



<h4>3.1 限制数据的导入导出</h4>



<h5>3.1.1 案例一：禁止数据的导入导出</h5>



<h5>3.1.1.1 修改配置文件</h5>



<pre class="wp-block-code"><code># vim /etc/my.cnf</code></pre>



<p>在：</p>



<pre class="wp-block-code"><code>......
&#91;mysqld]</code></pre>



<p>下面添加：</p>



<pre class="wp-block-code"><code>secure_file_priv=null
...... </code></pre>



<p>（补充：这里以 MariaDB 数据库的配置文件是 /etc/my.cnf 为例）</p>



<p>（注意：此参数对 MariaDB 数据库无效）</p>



<h5>3.1.1.2 重启数据库</h5>



<pre class="wp-block-code"><code># systemctl restart mariadb</code></pre>



<p>（补充：这里以重启 MariaDB 数据库为例）</p>



<h5>3.1.2 案例二：只允许将数据从 /root 目录导入或导出到 /root 目录</h5>



<h5>3.1.2.1 修改配置文件</h5>



<pre class="wp-block-code"><code># vim /etc/my.cnf</code></pre>



<p>在：</p>



<pre class="wp-block-code"><code>......
&#91;mysqld]</code></pre>



<p>下面添加：</p>



<pre class="wp-block-code"><code>secure_file_priv=/root/
...... </code></pre>



<p>（补充：这里以 MariaDB 数据库的配置文件是 /etc/my.cnf 为例）</p>



<p>（注意：此参数对 MariaDB 数据库无效）</p>



<h5>3.1.2.2 重启数据库</h5>



<pre class="wp-block-code"><code># systemctl restart mariadb</code></pre>



<p>（补充：这里以重启 MariaDB 数据库为例）</p>



<h5>3.1.3 案例三：不对数据作出导入和导出的限制</h5>



<h5>3.1.3.1 修改配置文件</h5>



<pre class="wp-block-code"><code># vim /etc/my.cnf</code></pre>



<p>删除以下内容：</p>



<pre class="wp-block-code"><code>......
secure_file_priv=*
...... </code></pre>



<p>（补充：这里以 MariaDB 数据库的配置文件是 /etc/my.cnf 为例）</p>



<p>（注意：此参数对 MariaDB 数据库无效）</p>



<h5>3.1.3.2 重启数据库</h5>



<pre class="wp-block-code"><code># systemctl restart mariadb</code></pre>



<p>（补充：这里以重启 MariaDB 数据库为例）</p>



<h4>3.2 删除无用和不需要的用户</h4>



<h5>3.2.1 查看所有用户</h5>



<pre class="wp-block-code"><code>&gt; select user,host from mysql.user;</code></pre>



<h5>3.2.2 删除不需要的用户</h5>



<h5>3.2.2.1 方法一：使用 drop 命令删除用户</h5>



<pre class="wp-block-code"><code>&gt; drop &lt;user&gt;;</code></pre>



<h5>3.2.2.2 方法二：使用 delete 命令删除用户</h5>



<pre class="wp-block-code"><code>&gt; delete from mysql.user where user='&lt;user&gt;' and host='&lt;host&gt;';</code></pre>



<h4>3.3 强制用户使用强密码</h4>



<h5>3.3.1 修改配置文件</h5>



<pre class="wp-block-code"><code># vim /etc/my.cnf</code></pre>



<p>在：</p>



<pre class="wp-block-code"><code>......
&#91;mysqld]</code></pre>



<p>下面添加：</p>



<pre class="wp-block-code"><code>plugin-load=validate_password.so
......</code></pre>



<p>（补充：这里以 MariaDB 数据库的配置文件是 /etc/my.cnf 为例）</p>



<h5>3.3.2 重启数据库</h5>



<pre class="wp-block-code"><code># systemctl restart mariadb</code></pre>



<p>（补充：这里以重启 MariaDB 数据库为例）</p>



<h5>3.3.3 确保 validate_password_policy 被设置的参数是 MEDIUM</h5>



<h5>3.3.3.1 进入数据库</h5>



<pre class="wp-block-code"><code># mysql -p</code></pre>



<h5>3.3.3.2 查看 validate_password_policy 参数</h5>



<pre class="wp-block-code"><code>&gt; show variables like 'validate_password_policy';
+--------------------------+--------+
| Variable_name            | Value  |
+--------------------------+--------+
| validate_password.policy | MEDIUM |
| validate_password_policy | MEDIUM |
+--------------------------+--------+
2 rows in set (0.01 sec)</code></pre>



<p>（补充：MEDIUM 的含义是密码最小的长度是 8 ，并且必须要有一个特殊字符和一个数字）</p>



<h4>3.4 设置用户密码有效期</h4>



<h5>3.4.1 对于 MariaDB 和 MySQL 5.7 及以下的版本无法设置有效期，只能定期修改密码</h5>



<pre class="wp-block-code"><code>&gt; alter user 'root'@'localhost' identified by '&lt;password&gt;';</code></pre>



<h5>3.4.2 设置用户默认有效期的方法</h5>



<h5>3.4.2.1 修改用户密码默认的自动过期时间</h5>



<pre class="wp-block-code"><code>&gt; set global default_password_lifetime=&lt;number&gt;;</code></pre>



<p>（补充：这里的数字代表天数）</p>



<h5>3.4.2.2 让用户密码立刻过期</h5>



<pre class="wp-block-code"><code>&gt; aleter user '&lt;user&gt;'@'&lt;host&gt;' password expire;</code></pre>



<h5>3.4.2.3 让用户密码永不过期</h5>



<pre class="wp-block-code"><code>&gt; aleter user '&lt;user&gt;'@'&lt;host&gt;' password expire never;</code></pre>



<p>（补充：建议普通用户每 90 天修改一次密码，敏感用户每 30 天修改一次密码，服务用户每 365 天修改一次密码）</p>



<h4>3.5 删除无密码用户</h4>



<h5>3.5.1 方法一：手动删除无密码用户</h5>



<h5>3.5.1.1 查看无密码用户</h5>



<h5>3.5.1.1.1 MariaDB 和 MySQL 5.7 及以下版本查看无密码用户的方法</h5>



<pre class="wp-block-code"><code>&gt; select user, host, password from mysql.user;</code></pre>



<h5>3.5.1.1.2 MySQL 8.0 及以上版本查看无密码用户的方法</h5>



<pre class="wp-block-code"><code>&gt; select user, host, authentication_string from mysql.user;</code></pre>



<h5>3.5.1.2 手动删除不需要的用户的方法</h5>



<h5>3.5.1.2.1 手动删除用户的第一种方法：使用 drop 命令删除用户</h5>



<pre class="wp-block-code"><code>&gt; drop user &lt;user&gt;;</code></pre>



<h5>3.5.1.2.2 手动删除用户的第二种方法：使用 delete 命令删除用户</h5>



<pre class="wp-block-code"><code>&gt; delete from mysql.user where user='&lt;user&gt;' and host='&lt;host&gt;';</code></pre>



<h5>3.5.2 方法二：使用工具删除无密码用户</h5>



<pre class="wp-block-code"><code># sudo mysql_secure_installation</code></pre>



<h4>3.6 禁止非 root 用户 拥有 mysql.user 表访问权限</h4>



<pre class="wp-block-code"><code>&gt; show grants for root@localhost \G;
&gt; select * from mysql.user where user='test' \G;</code></pre>



<h4>3.7 让用户只拥有最小但够用的权限</h4>



<h5>3.7.1 查看所有用户</h5>



<pre class="wp-block-code"><code>&gt; select user,host from mysql.user;</code></pre>



<h5>3.7.2 数据库权限层级</h5>



<p>1) 全局层级权限：是指整个数据库级别的权限，存储在 mysql.user 表中<br>格式：</p>



<pre class="wp-block-code"><code>&gt; grant all on *.* ......
&gt; show grants for &lt;user&gt;;
&gt; select * from mysql.user where user='&lt;user&gt;'\G;</code></pre>



<p>2) 库级层级权限：是指数据库中某个库的权限，存储在 mysql.db 和 mysql.host 表中<br>格式：</p>



<pre class="wp-block-code"><code>&gt; grant all on &lt;database&gt;.* ......
&gt; show grants for &lt;user&gt;;
&gt; select * from mysql.db where user='&lt;user&gt;'\G;</code></pre>



<p>3) 表级层级权限：是指数据库中某个库的某个表的权限，存储在 mysql.tables_priv 表中<br>格式：</p>



<pre class="wp-block-code"><code>&gt; grant all on &lt;database&gt;.&lt;table&gt; ......
&gt; show grants for &lt;user&gt;;
&gt; select * from mysql.tables_priv where user='&lt;user&gt;'\G;</code></pre>



<p>4) 列级层级权限：是指数据库中某个库的某个表的某一单列的权限，存储在 mysql.columns_priv 表中<br>格式：</p>



<pre class="wp-block-code"><code>&gt; grant select(&lt;field&gt;,&lt;field&gt;) on &lt;database&gt;.&lt;table&gt; ......
&gt; show grants for &lt;user&gt;;
&gt; select * from mysql.columns_priv where user='&lt;user&gt;'\G;</code></pre>



<p>5) 子程序层级权限：适用于已存储的子程序<br>create routing, alter routing, execute 和 grant 权限适用于已存储的子程序<br>create routing, alter routing, execute 和 grant 权限可以被授予为全局层级和数据库层级<br>alter routing, execute 和 grant 权限可以被授予为子程序层级，并存储在 mysql.procs_priv 表中<br>格式：</p>



<pre class="wp-block-code"><code>&gt; grant execute on &lt;subroutine&gt; &lt;database&gt;.&lt;table&gt; ......
&gt; show grants for &lt;user&gt;;
&gt; select * from mysql.procs_priv where user='&lt;user&gt;'\G;</code></pre>



<h5>3.7.3 查看每一个用户的权限</h5>



<pre class="wp-block-code"><code>&gt; show grants for '&lt;user&gt;'@'&lt;host&gt;';</code></pre>



<h5>3.7.4 删除用户多余的权限</h5>



<p>如果有全局权限(如： FILE,PROCESS,SUPER, or SHUTDOWN 等权限)，就删除这些权限<br>格式：</p>



<pre class="wp-block-code"><code>&gt; revoke &lt;privilege&gt; on *.* from &lt;user&gt;@&lt;host&gt;;
&gt; flush privileages;</code></pre>



<h3>内容四：数据库网络安全</h3>



<h4>4.1 禁止或者限制远程登录</h4>



<p>（步骤略）</p>



<p>(<br>补充：<br>查看可以远程登录的用户的案例</p>



<pre class="wp-block-code"><code>&gt; select user, host from mysql.user where host not in ('::1','127.0.0.1','localhost');</code></pre>



<p>）</p>



<h4>4.1.1 禁止远程登录</h4>



<h5>4.1.1.1 通过 MariaDB &amp; MySQL 的配置文件禁止远程登录</h5>



<h5>4.1.1.1.1 修改配置文件</h5>



<pre class="wp-block-code"><code># vim /etc/my.cnf</code></pre>



<p>在：</p>



<pre class="wp-block-code"><code>......
&#91;mysqld]</code></pre>



<p>下面添加：</p>



<pre class="wp-block-code"><code>skip-networking
bind-address=127.0.0.1
......</code></pre>



<p>（补充：这里以 MariaDB 数据库的配置文件是 /etc/my.cnf 为例）</p>



<p>（注意：加入 skip-networking 这一行会让 MariaDB&amp;MySQL 不再使用和监听任何端口）</p>



<h5>4.1.1.1.2 重启数据库</h5>



<pre class="wp-block-code"><code># systemctl restart mariadb</code></pre>



<p>（补充：这里以重启 MariaDB 数据库为例）</p>



<h5>4.1.1.2 通过防火墙禁止远程登录</h5>



<h5>4.1.2 如果非要进行远程登录则要限制远程登录</h5>



<h5>4.1.2.1 限制访问数据库 TCP 端口的具体 IP 地址</h5>



<p>（步骤略）</p>



<p>（补充：MariaDB&amp;MySQL 数据库的默认端口号是 3306）</p>



<h5>4.1.2.2 禁止有较大权限的用户被远程登录</h5>



<p>1) 有 grant option 权限的用户<br>2) 被给予了全局权限像是 grant all on <em>.</em> 权限的用户<br>3) 一个可以访问 mysql.user 表的用户</p>



<h4>4.2 对网络数据进行加密传输</h4>



<h5>4.2.1 生成 SSL</h5>



<h5>4.2.1.1 创建 CA 证书</h5>



<pre class="wp-block-code"><code># openssl genrsa 2048 &gt; ca-key.pem
Generating RSA private key, 2048 bit long modulus
..+++
...................................+++
e is 65537 (0x10001)

# openssl req -new -x509 -nodes -days 3600 -key ca-key.pem -out ca.pem
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) &#91;XX]:
State or Province Name (full name) &#91;]:
Locality Name (eg, city) &#91;Default City]:
Organization Name (eg, company) &#91;Default Company Ltd]:
Organizational Unit Name (eg, section) &#91;]:
Common Name (eg, your name or your server's hostname) &#91;]:ca
Email Address &#91;]:</code></pre>



<p>（注意：创建 CA 证书、服务端证书、客户端证书时 Common Name 必须要有值，且必须相互不一样）</p>



<h5>4.2.1.2 创建服务端证书，并去除加密，并使用刚刚的 CA 证书进行签名</h5>



<pre class="wp-block-code"><code># openssl req -newkey rsa:2048 -days 3600 -nodes -keyout server-key.pem -out server-req.pem
Generating a 2048 bit RSA private key
.............+++
...+++
writing new private key to 'server-key.pem'
-----
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) &#91;XX]:
State or Province Name (full name) &#91;]:
Locality Name (eg, city) &#91;Default City]:
Organization Name (eg, company) &#91;Default Company Ltd]:
Organizational Unit Name (eg, section) &#91;]:
Common Name (eg, your name or your server's hostname) &#91;]:
Email Address &#91;]:

Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password &#91;]:
An optional company name &#91;]:

# openssl rsa -in server-key.pem -out server-key.pem
writing RSA key

# openssl x509 -req -in server-req.pem -days 3600 -CA ca.pem -CAkey ca-key.pem -set_serial 01 -out server-cert.pem
Signature ok
subject=/C=XX/L=Default City/O=Default Company Ltd
Getting CA Private Key</code></pre>



<p>（注意：创建 CA 证书、服务端证书、客户端证书时 Common Name 必须要有值，且必须相互不一样）</p>



<h5>4.2.1.3 创建客户端证书，并去除加密，并使用刚刚的 CA 证书进行签名</h5>



<pre class="wp-block-code"><code># openssl req -newkey rsa:2048 -days 3600 -nodes -keyout client-key.pem -out client-req.pem
Generating a 2048 bit RSA private key
..................+++
..............................................+++
writing new private key to 'client-key.pem'
-----
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) &#91;XX]:
State or Province Name (full name) &#91;]:
Locality Name (eg, city) &#91;Default City]:
Organization Name (eg, company) &#91;Default Company Ltd]:
Organizational Unit Name (eg, section) &#91;]:
Common Name (eg, your name or your server's hostname) &#91;]:
Email Address &#91;]:

Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password &#91;]:
An optional company name &#91;]:

# openssl rsa -in client-key.pem -out client-key.pem
writing RSA key

# openssl x509 -req -in client-req.pem -days 3600 -CA ca.pem -CAkey ca-key.pem -set_serial 01 -out client-cert.pem
Signature ok
subject=/C=XX/L=Default City/O=Default Company Ltd
Getting CA Private Key</code></pre>



<h5>4.2.1.4 对生成的证书进行验证</h5>



<pre class="wp-block-code"><code># openssl verify -CAfile ca.pem server-cert.pem client-cert.pem
server-cert.pem: OK
client-cert.pem: OK</code></pre>



<h5>4.2.2 将 SSL 添加到 MariaDB &amp; MySQL</h5>



<h5>4.2.2.1 将 SSL 放在指定的位置</h5>



<pre class="wp-block-code"><code># mv ca.pem /home/mysql/sslconfig/ca.pem
# mv server-cert.pem /home/mysql/sslconfig/server-cert.pem
# mv server-key.pem /home/mysql/sslconfig/server-key.pem</code></pre>



<h5>4.2.2.2 修改配置文件</h5>



<pre class="wp-block-code"><code># vim /etc/my.cnf</code></pre>



<p>在：</p>



<pre class="wp-block-code"><code>......
&#91;mysqld]</code></pre>



<p>下面添加：</p>



<pre class="wp-block-code"><code>ssl-ca=/home/mysql/sslconfig/ca.pem
ssl-cert=/home/mysql/sslconfig/server-cert.pem
ssl-key=/home/mysql/sslconfig/server-key.pem
......</code></pre>



<p>（补充：这里以 MariaDB 数据库的配置文件是 /etc/my.cnf 为例）</p>



<h5>4.2.3 重启数据库</h5>



<pre class="wp-block-code"><code># systemctl restart mariadb</code></pre>



<p>（补充：这里以重启 MariaDB 数据库为例）</p>



<h5>4.2.4 验证 SSL</h5>



<h5>4.2.4.1 查看 have_ssl 和 ssl 变量</h5>



<pre class="wp-block-code"><code>&gt; show variables like 'have_%ssl';
&gt; show variables like '%ssl%';</code></pre>



<p>（补充：如果它们的参数为 yes ,表示服务端已经开启 SSL）</p>



<h5>4.2.4.2 查看 SSL 的状态</h5>



<pre class="wp-block-code"><code>&gt; show status like 'ssl_cipher'</code></pre>



<p>（补充：如果出现 “SSL:Cipher in use is DHE-RSA-AES256-SHA“ 则表示客户端已经使用 SSL 连接了）</p>



<h5>4.2.5 确保所有数据库用户使用 SSL</h5>



<pre class="wp-block-code"><code>&gt; grant usage on &lt;database&gt;.&lt;table&gt; to '&lt;user&gt;'@'&lt;host&gt;' reouter ssl;</code></pre>



<h5>4.2.6 用户通过 SSL 连接数据库的方法</h5>



<pre class="wp-block-code"><code>&gt; mysql -u &lt;user&gt; -p -h &lt;host&gt; --ssl-ca=/home/mysql/sslconfig/ca.pem</code></pre>



<h3>内容五：开启审计</h3>



<h4>5.1 开启审计</h4>



<h5>5.1.1 MariaDB 和 MySQL 5.7 及以下版本开启审计的方法</h5>



<pre class="wp-block-code"><code>&gt; set global log_warning=2;</code></pre>



<h5>5.1.2 MySQL 8.0 及以上版本开启审计的方法</h5>



<pre class="wp-block-code"><code>&gt; set global general_log = on;
&gt; set global log_timestamps = SYSTEM;</code></pre>



<h5>5.2 查看 MariaDB &amp; MySQL 日志</h5>



<pre class="wp-block-code"><code># find /I "Access denied for user" &lt;logfile_name&gt;.log
# grep -i 'Access denied for user' &lt;logfile_name&gt;.log</code></pre>



<p>（补充：中止连接、失败连接、尝试连接都将被写进日志）</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>[步骤] MariaDB &#038; MySQL root 密码的重置</title>
		<link>https://eternalcenter-sep-2022.github.io/mariadb-mysql-password-reset/</link>
		
		<dc:creator><![CDATA[Mingyu Zhu]]></dc:creator>
		<pubDate>Mon, 11 Nov 2019 14:58:33 +0000</pubDate>
				<category><![CDATA[Chinese (中文)]]></category>
		<category><![CDATA[Database (数据库)]]></category>
		<category><![CDATA[MariaDB]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[Relational Database (SQL) (关系型数据库 )]]></category>
		<category><![CDATA[Service (服务)]]></category>
		<guid isPermaLink="false">https://eternalcenter-sep-2022.github.io/?p=6592</guid>

					<description><![CDATA[注意： 在重置 MariaDB &#38; MySQL 的 root 密码之前要先安装 MariaDB &#38; MySQL 正文： 步骤一：免密进入数据库 1.1 在 MariaDB&#38;MySQL 文件中添加免密登录参数 将部分内容修改如下： 1.2 使修改的配置生效 1.2.1 MariaDB 使修改的配置生效 （注意：只有当重置 MariaDB 的时候才执行这一步） 1.2.2 MySQL 使修改的配置生效 （注意：只有当重置 MariaDB 的时候才执行这一步） 步骤二：将 root 密码设置为空 2.1 不使用密码进入数据库 （补充：当提示输入密码时直接敲回车） 2.2 清空 root 用户密码 2.2.1 MariaDB 和 MySQL 5.7 及以下的版本将 root 密码设置为空 （注意：只有当是重置 MariaDB 和 MySQL 5.7 &#8230; <p class="link-more"><a href="https://eternalcenter-sep-2022.github.io/mariadb-mysql-password-reset/" class="more-link">Continue reading<span class="screen-reader-text"> "[步骤] MariaDB &#038; MySQL root 密码的重置"</span></a></p>]]></description>
										<content:encoded><![CDATA[
<h1>注意：</h1>



<p>在重置 MariaDB &amp; MySQL 的 root 密码之前要先安装 MariaDB &amp; MySQL</p>



<div class="wp-container-1 is-horizontal is-content-justification-center wp-block-buttons">
<div class="wp-block-button is-style-outline"><a class="wp-block-button__link no-border-radius" href="https://eternalcenter-sep-2022.github.io/mariadb-install/">MariaDB 的安装</a></div>



<div class="wp-block-button is-style-outline"><a class="wp-block-button__link no-border-radius" href="https://eternalcenter-sep-2022.github.io/mysql-install-yum/">MySQL 的安装</a></div>
</div>



<h1>正文：</h1>



<h3>步骤一：免密进入数据库</h3>



<h4>1.1 在 MariaDB&amp;MySQL 文件中添加免密登录参数</h4>



<pre class="wp-block-code"><code># vim /etc/my.cnf</code></pre>



<p>将部分内容修改如下：</p>



<pre class="wp-block-code"><code>......
&#91;mysqld]
skip-grant-tables
......</code></pre>



<h4>1.2 使修改的配置生效</h4>



<h5>1.2.1 MariaDB 使修改的配置生效</h5>



<pre class="wp-block-code"><code># systemctl restart mariadb</code></pre>



<p>（注意：只有当重置 MariaDB 的时候才执行这一步）</p>



<h5>1.2.2 MySQL 使修改的配置生效</h5>



<pre class="wp-block-code"><code># systemctl restart mysqld</code></pre>



<p>（注意：只有当重置 MariaDB 的时候才执行这一步）</p>



<h3>步骤二：将 root 密码设置为空</h3>



<h4>2.1 不使用密码进入数据库</h4>



<pre class="wp-block-code"><code># mysql -u root -p</code></pre>



<p>（补充：当提示输入密码时直接敲回车）</p>



<h4>2.2 清空 root 用户密码</h4>



<h5>2.2.1 MariaDB 和 MySQL 5.7 及以下的版本将 root 密码设置为空</h5>



<pre class="wp-block-code"><code>&gt; update mysql.user set password='' where user='root';</code></pre>



<p>（注意：只有当是重置 MariaDB 和 MySQL 5.7 及以下版本密码的时候才需要执行这一步）</p>



<h5>2.2.2 MySQL 8.0 及以上的版本将 root 密码设置为空</h5>



<pre class="wp-block-code"><code>&gt; update mysql.user set authentication_string='' where user='root';</code></pre>



<p>（注意：只有当是重置 MySQL 8.0 及以上版本密码的时候才需要执行这一步）</p>



<h4>2.3 退出数据库</h4>



<pre class="wp-block-code"><code>&gt; quit;</code></pre>



<h3>步骤三：给 root 设置新密码</h3>



<h4>3.1 在 MariaDB&amp;MySQL 文件中将免密登录参数注释掉</h4>



<pre class="wp-block-code"><code># vim /etc/my.cnf</code></pre>



<p>将部分内容修改如下：</p>



<pre class="wp-block-code"><code>......
&#91;mysqld]
# skip-grant-tables
......</code></pre>



<h4>3.2 使修改的配置生效</h4>



<h5>3.2.1 MariaDB 使修改的配置生效</h5>



<pre class="wp-block-code"><code># systemctl restart mariadb</code></pre>



<p>（注意：只有当重置 MariaDB 的时候才执行这一步）</p>



<h5>3.2.2 MySQL 使修改的配置生效</h5>



<pre class="wp-block-code"><code># systemctl restart mysqld</code></pre>



<p>（注意：只有当重置 MySQL 的时候才执行这一步）</p>



<h4>3.3 进入数据库</h4>



<pre class="wp-block-code"><code>&gt; mysql -u root -p</code></pre>



<p>（补充：当提示输入密码时直接敲回车）</p>



<h4>3.4 给 root 设置新密码</h4>



<pre class="wp-block-code"><code>&gt; alter user 'root'@'localhost' identified by '&lt;password&gt;';</code></pre>



<h4>3.5 退出数据库</h4>



<pre class="wp-block-code"><code>&gt; quit;</code></pre>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>[实验] MariaDB &#038; MySQL 主从同步的搭建 （互为主从）</title>
		<link>https://eternalcenter-sep-2022.github.io/mariadb-mysql-master-master/</link>
		
		<dc:creator><![CDATA[Mingyu Zhu]]></dc:creator>
		<pubDate>Fri, 08 Nov 2019 15:48:18 +0000</pubDate>
				<category><![CDATA[Chinese (中文)]]></category>
		<category><![CDATA[Cluster (集群)]]></category>
		<category><![CDATA[Database (数据库)]]></category>
		<category><![CDATA[Database Cluster (数据库集群)]]></category>
		<category><![CDATA[MariaDB]]></category>
		<category><![CDATA[MariaDB & MySQL Database Cluster (MariaDB & MySQL 数据库集群)]]></category>
		<category><![CDATA[MariaDB & MySQL Database High Availability Cluster (MariaDB & MySQL 数据库高可用集群)]]></category>
		<category><![CDATA[MariaDB & MySQL High Availability (高可用)]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[Relational Database (SQL) (关系型数据库 )]]></category>
		<category><![CDATA[纪念 Anniversary]]></category>
		<guid isPermaLink="false">https://eternalcenter-sep-2022.github.io/?p=6576</guid>

					<description><![CDATA[纪念：站主于 2019 年 11 月完成了此开源实验，并将过程中的所有命令经过整理和注释以后，形成以下教程 步骤一：规划拓扑 1.1 服务器列表 数据库服务器 21 IP 地址:192.168.1.21数据库服务器 22 IP 地址:192.168.1.22 1.2 服务器列表简介 数据库服务器 21 和 数据库服务器 22 相互同步对方的数据 步骤二：系统环境要求 1) 所有服务器的系统都需要是 CentOS 7 版本2) 所有服务器都要关闭防火墙3) 所有服务器都要关闭 SELinux4) 所有服务器系统都要配置好可用的软件源5) 需要按照拓扑图给对应的服务器配置好 IP 地址和主机名6) 所有服务器都要可以相互 ping 通自己和对方的 IP 地址和主机名 步骤三：所有数据库服务器安装 MariaDB 或 MySQL 数据库 3.1 所有数据库服务器安装 MariaDB 或 MySQL （分别在数据库服务器 21 和数据库服务器 22 &#8230; <p class="link-more"><a href="https://eternalcenter-sep-2022.github.io/mariadb-mysql-master-master/" class="more-link">Continue reading<span class="screen-reader-text"> "[实验] MariaDB &#038; MySQL 主从同步的搭建 （互为主从）"</span></a></p>]]></description>
										<content:encoded><![CDATA[
<p class="has-vivid-red-color has-text-color has-medium-font-size"><strong>纪念：站主于 2019 年 11 月完成了此开源实验，并将过程中的所有命令经过整理和注释以后，形成以下教程</strong></p>



<h3 id="步骤一-规划拓扑1-1-服务器列表">步骤一：规划拓扑</h3>



<h4 id="步骤一-规划拓扑1-1-服务器列表">1.1 服务器列表</h4>



<p>数据库服务器 21 IP 地址:192.168.1.21<br>数据库服务器 22 IP 地址:192.168.1.22</p>



<h4 id="1-2-服务器列表简介">1.2 服务器列表简介</h4>



<p>数据库服务器 21 和 数据库服务器 22 相互同步对方的数据</p>



<h3 id="步骤二-系统环境要求">步骤二：系统环境要求</h3>



<p>1) 所有服务器的系统都需要是 CentOS 7 版本<br>2) 所有服务器都要关闭防火墙<br>3) 所有服务器都要关闭 SELinux<br>4) 所有服务器系统都要配置好可用的软件源<br>5) 需要按照拓扑图给对应的服务器配置好 IP 地址和主机名<br>6) 所有服务器都要可以相互 ping 通自己和对方的 IP 地址和主机名</p>



<h3 id="步骤三-所有数据库服务器安装-mariadb-或-mysql-数据库3-1-所有数据库服务器安装-mariadb-或-mysql">步骤三：所有数据库服务器安装 MariaDB 或 MySQL 数据库</h3>



<h4 id="步骤三-所有数据库服务器安装-mariadb-或-mysql-数据库3-1-所有数据库服务器安装-mariadb-或-mysql">3.1 所有数据库服务器安装 MariaDB 或 MySQL</h4>



<p>（分别在数据库服务器 21 和数据库服务器 22 上执行以下步骤）</p>



<pre class="wp-block-code"><code># yum -y install mariadb-server</code></pre>



<p>（补充：这里以安装 MariaDB 数据库为例）</p>



<h4 id="3-2-设置所有数据库服务器开机自启-mariadb-或-mysql">3.2 设置所有数据库服务器开机自启 MariaDB 或 MySQL</h4>



<p>（分别在数据库服务器 21 和数据库服务器 22 上执行以下步骤）</p>



<pre class="wp-block-code"><code># systemctl enable mariadb</code></pre>



<p>（补充：这里以开机自启 MariaDB 数据库为例）</p>



<h3 id="步骤四-配置-mairadb-mysql-互为主从结构4-1-将数据库服务器-22-设置为数据库服务器-21-的从库4-1-1-开启数据库服务器-21-的-server-id-和-binlog-日志">步骤四：配置 MairaDB &amp; MySQL 互为主从结构</h3>



<h4 id="步骤四-配置-mairadb-mysql-互为主从结构4-1-将数据库服务器-22-设置为数据库服务器-21-的从库4-1-1-开启数据库服务器-21-的-server-id-和-binlog-日志">4.1 将数据库服务器 22 设置为数据库服务器 21 的从库</h4>



<h5 id="步骤四-配置-mairadb-mysql-互为主从结构4-1-将数据库服务器-22-设置为数据库服务器-21-的从库4-1-1-开启数据库服务器-21-的-server-id-和-binlog-日志">4.1.1 开启数据库服务器 21 的 server-id 和 binlog 日志</h5>



<p>（只在数据库服务器 21 上执行以下步骤）</p>



<pre class="wp-block-code"><code># vi /etc/my.cnf</code></pre>



<p>将部分内容修改如下：</p>



<pre class="wp-block-code"><code>&#91;mysqld]
server-id=1
log-bin=mariadb-bin
......</code></pre>



<p>（<br>补充：这里以<br>1) 将 server-id 设置为 1<br>2) 启动 binlog 日志，并将 binlog 日志的前缀设置为 mariadb-bin<br>为例<br>）</p>



<p>（注意： 集群里的各个数据库的 server id 不能一样）</p>



<h5 id="4-1-2-重启数据库服务器-21-的数据库">4.1.2 重启数据库服务器 21 的数据库</h5>



<p>（只在数据库服务器 21 上执行以下步骤）</p>



<pre class="wp-block-code"><code># systemctl restart mariadb</code></pre>



<p>（补充：这里以重启 MariaDB 数据库为例）</p>



<h5 id="4-1-3-在数据库服务器-21-的数据库中创建用于同步的用户4-1-3-1-进入数据库">4.1.3 在数据库服务器 21 的数据库中创建用于同步的用户</h5>



<h5 id="4-1-3-在数据库服务器-21-的数据库中创建用于同步的用户4-1-3-1-进入数据库">4.1.3.1 进入数据库</h5>



<p>（只在数据库服务器 21 上执行以下步骤）</p>



<pre class="wp-block-code"><code># mysql -p</code></pre>



<h5 id="4-1-3-2-创建数据库服务器-21-用于被数据库服务器-22-同步的-mariadb-用户">4.1.3.2 创建数据库服务器 21 用于被数据库服务器 22 同步的 MariaDB 用户</h5>



<p>（只在数据库服务器 21 上执行以下步骤）</p>



<pre class="wp-block-code"><code>&gt; grant replication slave on *.* to 'backup'@'192.168.1.22' identified by 'backup';</code></pre>



<h5 id="4-1-3-3-刷新数据库服务器-21-里所有用户的权限">4.1.3.3 刷新数据库服务器 21 里所有用户的权限</h5>



<p>（只在数据库服务器 21 上执行以下步骤）</p>



<pre class="wp-block-code"><code>&gt; flush privileges;</code></pre>



<h5 id="4-1-3-4-显示数据库服务器-21-的-mariadb-的主库参数">4.1.3.4 显示数据库服务器 21 的 MariaDB 的主库参数</h5>



<p>（只在数据库服务器 21 上执行以下步骤）</p>



<pre class="wp-block-code"><code>&gt; show master status;
+--------------------+----------+--------------+------------------+
| File               | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+--------------------+----------+--------------+------------------+
| mariadb-bin.000003 |      475 |              |                  |
+--------------------+----------+--------------+------------------+
1 row in set (0.00 sec)</code></pre>



<p>（补充：这里显示的 master_log_file 和 master_log_pos 的参数会在后面配置从库中使用）</p>



<h5 id="4-1-4-让数据库服务器-22-同步数据库服务器-214-1-4-1-启动数据库服务器-22">4.1.4 让数据库服务器 22 同步数据库服务器 21</h5>



<h5 id="4-1-4-让数据库服务器-22-同步数据库服务器-214-1-4-1-启动数据库服务器-22">4.1.4.1 启动数据库服务器 22</h5>



<p>（只在数据库服务器 22 上执行以下步骤）</p>



<pre class="wp-block-code"><code># systemctl start mariadb</code></pre>



<p>（补充：这里以启动 MariaDB 数据库为例）</p>



<h5 id="4-1-4-2-进入数据库服务器-22-的数据库">4.1.4.2 进入数据库服务器 22 的数据库</h5>



<p>（只在数据库服务器 22 上执行以下步骤）</p>



<pre class="wp-block-code"><code># mysql -p</code></pre>



<h5 id="4-1-4-3-同步主库">4.1.4.3 同步主库</h5>



<p>（只在数据库服务器 22 上执行以下步骤）</p>



<pre class="wp-block-code"><code>&gt; change master to master_host="192.168.1.21",master_user='backup',master_password='backup',master_log_file='mariadb-bin.000003',master_log_pos=475;</code></pre>



<h5 id="4-1-4-4-启动从库状态">4.1.4.4 启动从库状态</h5>



<p>（只在数据库服务器 22 上执行以下步骤）</p>



<pre class="wp-block-code"><code>&gt; start slave;</code></pre>



<h5 id="4-1-4-5-显示从库状态">4.1.4.5 显示从库状态</h5>



<p>（只在数据库服务器 22 上执行以下步骤）</p>



<pre class="wp-block-code"><code>&gt; show slave status\G;
          Master_Host: 192.168.1.21
              ......
          Slave_IO_Running: Yes  
          Last_IO_Error: ......
              ......
          Slave_SQL_Running: Yes
          Last_SQL_Error: ......
              ......</code></pre>



<p>（补充：这里显示它的主服务器是 192.168.1.21）</p>



<p>（注意：这里要确保 Slave_IO_Running: 和 Slave_SQL_Running: 后面没有报错信息）</p>



<h4 id="4-2-将数据库服务器-21-设置为数据库服务器-22-的从库4-2-1-关闭数据库服务器-22-的数据库">4.2 将数据库服务器 21 设置为数据库服务器 22 的从库</h4>



<h5 id="4-2-将数据库服务器-21-设置为数据库服务器-22-的从库4-2-1-关闭数据库服务器-22-的数据库">4.2.1 关闭数据库服务器 22 的数据库</h5>



<p>（只在数据库服务器 22 上执行以下步骤）</p>



<pre class="wp-block-code"><code># systemctl stop mariadb</code></pre>



<p>（补充：这里以停止 MariaDB 数据库为例）</p>



<h5 id="4-2-2-开启数据库服务器-21-的-server-id-和-binlog-日志">4.2.2 开启数据库服务器 21 的 server-id 和 binlog 日志</h5>



<p>（只在数据库服务器 22 上执行以下步骤）</p>



<pre class="wp-block-code"><code># vi /etc/my.cnf</code></pre>



<p>（将部分内容修改如下）</p>



<pre class="wp-block-code"><code>&#91;mysqld]
server-id=2
log-bin=mariadb-bin
......</code></pre>



<p>（<br>补充：这里以<br>1) 将 server-id 设置为 2<br>2) 启动 binlog 日志，并将 binlog 日志的前缀设置为 mariadb-bin<br>为例<br>）</p>



<p>（注意： 集群里的各个数据库的 server id 不能一样）</p>



<h5 id="4-2-3-启动数据库服务器-22-的数据库">4.2.3 启动数据库服务器 22 的数据库</h5>



<p>（只在数据库服务器 22 上执行以下步骤）</p>



<pre class="wp-block-code"><code># systemctl start mariadb</code></pre>



<p>（补充：这里以重启 MariaDB 数据库为例）</p>



<h5 id="4-2-4-在数据库服务器-22-的数据库中创建用于同步的用户4-2-4-1-进入数据库">4.2.4 在数据库服务器 22 的数据库中创建用于同步的用户</h5>



<h5 id="4-2-4-在数据库服务器-22-的数据库中创建用于同步的用户4-2-4-1-进入数据库">4.2.4.1 进入数据库</h5>



<p>（只在数据库服务器 22 上执行以下步骤）</p>



<pre class="wp-block-code"><code># mysql -p</code></pre>



<h5 id="4-2-4-2-创建数据库服务器-21-用于被数据库服务器-22-同步的-mariadb-用户">4.2.4.2 创建数据库服务器 21 用于被数据库服务器 22 同步的 MariaDB 用户</h5>



<p>（只在数据库服务器 22 上执行以下步骤）</p>



<pre class="wp-block-code"><code>&gt; grant replication slave on *.* to 'backup'@'192.168.1.21' identified by 'backup';</code></pre>



<h5 id="4-2-4-3-刷新数据库服务器-22-数据库里所有用户的权限">4.2.4.3 刷新数据库服务器 22 数据库里所有用户的权限</h5>



<p>（只在数据库服务器 22 上执行以下步骤）</p>



<pre class="wp-block-code"><code>&gt; flush privileges;</code></pre>



<h5 id="4-2-4-4-显示数据库服务器-22-的-mariadb-的主库参数">4.2.4.4 显示数据库服务器 22 的 MariaDB 的主库参数</h5>



<p>（只在数据库服务器 22 上执行以下步骤）</p>



<pre class="wp-block-code"><code>&gt; show master status;
+--------------------+----------+--------------+------------------+
| File               | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+--------------------+----------+--------------+------------------+
| mariadb-bin.000003 |      475 |              |                  |
+--------------------+----------+--------------+------------------+
1 row in set (0.00 sec)</code></pre>



<p>（补充：这里显示的 master_log_file 和 master_log_pos 的参数会在后面配置从库中使用）</p>



<h5 id="4-2-5-让数据库服务器-21-同步数据库服务器-224-2-5-1-进入数据库服务器-21-的数据库">4.2.5 让数据库服务器 21 同步数据库服务器 22</h5>



<h5 id="4-2-5-让数据库服务器-21-同步数据库服务器-224-2-5-1-进入数据库服务器-21-的数据库">4.2.5.1 进入数据库服务器 21 的数据库</h5>



<p>（只在数据库服务器 21 上执行以下步骤）</p>



<pre class="wp-block-code"><code># mysql -p</code></pre>



<h5 id="4-2-5-2-同步主库">4.2.5.2 同步主库</h5>



<p>（只在数据库服务器 21 上执行以下步骤）</p>



<pre class="wp-block-code"><code>&gt; change master to master_host="192.168.1.22",master_user='backup',master_password='backup',master_log_file='mariadb-bin.000003',master_log_pos=475;</code></pre>



<h5 id="4-2-5-3-启动从库状态">4.2.5.3 启动从库状态</h5>



<p>（只在数据库服务器 21 上执行以下步骤）</p>



<pre class="wp-block-code"><code>&gt; start slave;</code></pre>



<h5 id="4-2-5-4-显示从库状态">4.2.5.4 显示从库状态</h5>



<p>（只在数据库服务器 21 上执行以下步骤）</p>



<pre class="wp-block-code"><code>&gt; show slave status\G;
          Master_Host: 192.168.1.22
              ......
          Slave_IO_Running: Yes  
          Last_IO_Error: ......
              ......
          Slave_SQL_Running: Yes
          Last_SQL_Error: ......
              ......</code></pre>



<p>（补充：这里显示它的主服务器是 192.168.1.21）</p>



<p>（注意：这里要确保 Slave_IO_Running: 和 Slave_SQL_Running: 后面没有报错信息）</p>



<h3 id="步骤五-测试-mariadb-mysql-互为主从集群5-1-进入数据库">步骤五：测试 MariaDB &amp; MySQL 互为主从集群</h3>



<h4 id="步骤五-测试-mariadb-mysql-互为主从集群5-1-进入数据库">5.1 进入数据库</h4>



<p>（分别在数据库服务器 21 和数据库服务器 22 上执行以下步骤）</p>



<pre class="wp-block-code"><code># mysql -uroot -p</code></pre>



<h4 id="5-2-创建测试库">5.2 创建测试库</h4>



<p>（只在数据库服务器 21 上执行以下步骤）</p>



<pre class="wp-block-code"><code>&gt; create database test1;</code></pre>



<h4 id="5-3-进入测试库">5.3 进入测试库</h4>



<p>（分别在数据库服务器 21 和数据库服务器 22 上执行以下步骤）</p>



<pre class="wp-block-code"><code>&gt; use test1;</code></pre>



<h4 id="5-4-创建测试表">5.4 创建测试表</h4>



<p>（只在数据库服务器 21 上执行以下步骤）</p>



<pre class="wp-block-code"><code>&gt; create table test1a(id int(10),name char(100),age int(10));</code></pre>



<p>（补充：这里随意创建了一张表格）</p>



<h4 id="5-5-在数据库服务器-21-上插入测试数据">5.5 在数据库服务器 21 上插入测试数据</h4>



<p>（只在数据库服务器 21 上执行以下步骤）</p>



<pre class="wp-block-code"><code>&gt; insert into test1a(id,name,age) values('1','zmy','10');</code></pre>



<p>（补充：这里随意插入了一条数据）</p>



<h4 id="5-6-在数据库服务器-22-上插入测试数据">5.6 在数据库服务器 22 上插入测试数据</h4>



<p>（只在数据库服务器 22 上执行以下步骤）</p>



<pre class="wp-block-code"><code>&gt; insert into test1a(id,name,age) values('2','ming','20');</code></pre>



<p>（补充：这里随意插入了一条数据）</p>



<h4 id="5-7-在两个数据库里都可以看到对方插入的测试数据">5.7 在两个数据库里都可以看到对方插入的测试数据</h4>



<p>（分别在数据库服务器 21 和数据库服务器 22 上执行以下步骤）</p>



<pre class="wp-block-code"><code>&gt; select * from test1a;
+------+------+------+
| id   | name | age  |
+------+------+------+
|    1 | zmy  |   10 |
|    2 | ming |   20 |
+------+------+------+
2 rows in set (0.00 sec)</code></pre>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>[步骤] WordPress 数据库的修复 （通过 WordPress 官方修复工具实现）</title>
		<link>https://eternalcenter-sep-2022.github.io/wordpress-db-repair/</link>
		
		<dc:creator><![CDATA[Mingyu Zhu]]></dc:creator>
		<pubDate>Wed, 21 Aug 2019 04:23:11 +0000</pubDate>
				<category><![CDATA[Chinese (中文)]]></category>
		<category><![CDATA[Database (数据库)]]></category>
		<category><![CDATA[Language (语言)]]></category>
		<category><![CDATA[MariaDB]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[Personal Website Building (个人网站建设)]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Project (项目)]]></category>
		<category><![CDATA[Relational Database (SQL) (关系型数据库 )]]></category>
		<category><![CDATA[Website Programs (网页程序)]]></category>
		<guid isPermaLink="false">https://eternalcenter-sep-2022.github.io/?p=5385</guid>

					<description><![CDATA[步骤一：修改网页文件 wp-config.php 1.1 修改使用默认源码安装的 Nginx 网页文件的方法 添加以下内容： 1.2 修改使用 CentOS&#38;RHEL yum 默认安装的 Nginx 网页的方法 添加以下内容： 步骤二：在图形浏览器上输入以下网址 &#60;website&#62;/wp-admin/maint/repair.php 步骤三：根据网页提示修复数据库 （步骤略）]]></description>
										<content:encoded><![CDATA[
<h3>步骤一：修改网页文件 wp-config.php</h3>



<h4>1.1 修改使用默认源码安装的 Nginx 网页文件的方法</h4>



<pre class="wp-block-code"><code># vim /usr/local/nginx/html/wp-config.php</code></pre>



<p>添加以下内容：</p>



<pre class="wp-block-code"><code>......
define('WP_ALLOW_REPAIR', true);
?&gt;</code></pre>



<h4>1.2 修改使用 CentOS&amp;RHEL yum 默认安装的 Nginx 网页的方法</h4>



<pre class="wp-block-code"><code># vim /usr/share/nginx/html/wp-config.php</code></pre>



<p>添加以下内容：</p>



<pre class="wp-block-code"><code>......
define('WP_ALLOW_REPAIR', true);
?&gt;</code></pre>



<h3>步骤二：在图形浏览器上输入以下网址</h3>



<p>&lt;website&gt;/wp-admin/maint/repair.php</p>



<h3>步骤三：根据网页提示修复数据库</h3>



<p>（步骤略）</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>[工具] Shell 半自动化部署 LNMP 平台 + SSL （CentOS Linux 7 版）</title>
		<link>https://eternalcenter-sep-2022.github.io/shell-lnmp-installation-linux-centos-7/</link>
		
		<dc:creator><![CDATA[Mingyu Zhu]]></dc:creator>
		<pubDate>Sat, 27 Jul 2019 14:33:02 +0000</pubDate>
				<category><![CDATA[Chinese (中文)]]></category>
		<category><![CDATA[Database (数据库)]]></category>
		<category><![CDATA[Language (语言)]]></category>
		<category><![CDATA[MariaDB]]></category>
		<category><![CDATA[Nginx]]></category>
		<category><![CDATA[Nginx Installation (安装)]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Relational Database (SQL) (关系型数据库 )]]></category>
		<category><![CDATA[Shell]]></category>
		<category><![CDATA[Shell Deployment (部署)]]></category>
		<category><![CDATA[Shell Tools (工具)]]></category>
		<category><![CDATA[Shell Website (网站)]]></category>
		<category><![CDATA[Website Service (网站服务)]]></category>
		<guid isPermaLink="false">https://eternalcenter-sep-2022.github.io/?p=4896</guid>

					<description><![CDATA[介绍 基本信息 作者：朱明宇脚本名称：半自动化部署 LNMP 平台 + SSL作用：半自动化安装 LNMP，即 Nginx、Mariadb、PHP、php-fpm，实现 HTTPS 使用方法 为了安全起见，设置系统用户和数据库用户和数据库权限的工作请按照脚本最后的步骤进行手动设置 注意 1. 执行本脚本之前请确保 Nginx、PHP、网站程序文件、SQL、SSL 的公钥、SSL 的私钥、shell、本脚本 8 个文件，如果是新建网站的话，不用准备 SQL 文件2. Nginx 文件：请将 Nginx 源码安装包放在 /root/3. PHP 文件：请将 PHP 源码安装包放在 /root/4. 网站程序文件:请将网站程序文件的名字中包含“eternalcenter-backup-”字段，并且是 tar 包，并放在 /root/5. SQL 文件:如果是恢复网站的话,请将备份的数据文件 *.sql 放在 /root/，注意这是一个 MySQL 备份文件6. SSL 的公钥文件和 SSL 私钥文件:请将网站安全证书的公钥和私钥分别命名为：eternalcenter.com.crt 和 eternalcenter.com.key，并放在 /root/7. shell 文件:请将监控脚本命名为 port_monitoring.sh 并放在 /root/8. &#8230; <p class="link-more"><a href="https://eternalcenter-sep-2022.github.io/shell-lnmp-installation-linux-centos-7/" class="more-link">Continue reading<span class="screen-reader-text"> "[工具] Shell 半自动化部署 LNMP 平台 + SSL （CentOS Linux 7 版）"</span></a></p>]]></description>
										<content:encoded><![CDATA[
<h2>介绍</h2>



<h3>基本信息</h3>



<p>作者：朱明宇<br>脚本名称：半自动化部署 LNMP 平台 + SSL<br>作用：半自动化安装 LNMP，即 Nginx、Mariadb、PHP、php-fpm，实现 HTTPS</p>



<h3>使用方法</h3>



<p>为了安全起见，设置系统用户和数据库用户和数据库权限的工作请按照脚本最后的步骤进行手动设置</p>



<h3>注意</h3>



<p>1. 执行本脚本之前请确保 Nginx、PHP、网站程序文件、SQL、SSL 的公钥、SSL 的私钥、shell、本脚本 8 个文件，如果是新建网站的话，不用准备 SQL 文件<br>2. Nginx 文件：请将 Nginx 源码安装包放在 /root/<br>3. PHP 文件：请将 PHP 源码安装包放在 /root/<br>4. 网站程序文件:请将网站程序文件的名字中包含“eternalcenter-backup-”字段，并且是 tar 包，并放在 /root/<br>5. SQL 文件:如果是恢复网站的话,请将备份的数据文件 *.sql 放在 /root/，注意这是一个 MySQL 备份文件<br>6. SSL 的公钥文件和 SSL 私钥文件:请将网站安全证书的公钥和私钥分别命名为：eternalcenter.com.crt 和 eternalcenter.com.key，并放在 /root/<br>7. shell 文件:请将监控脚本命名为 port_monitoring.sh 并放在 /root/<br>8. 除此之外 /root/ 目录下请不要放任何文件<br>9. 服务器的系统需要是 CentOS 7 版本<br>10. 服务器系统要配置好可用的软件源（最好是软件数量最多的官方版本）<br>11. 服务器要能够连接外网<br></p>



<h3>补充</h3>



<p>1. Nginx 下载网址：https://nginx.org/<br>2. PHP 下载网址：https://www.php.net/downloads.php<br>3. WordPress 是一款开源的 php 网站程序，建议使用，下载网址：https://cn.wordpress.org/download/<br>4. 网站安全证书的公钥和私钥可以在这里申请：https://freessl.cn/</p>



<h3>其他</h3>


<div class="wp-block-image">
<figure class="aligncenter"><img loading="lazy" width="734" height="564" src="https://eternalcenter-sep-2022.github.io/wp-content/uploads/2019/08/lnmp-install-shell.png" alt="" class="wp-image-5184" srcset="https://eternalcenter-sep-2022.github.io/wp-content/uploads/2019/08/lnmp-install-shell.png 734w, https://eternalcenter-sep-2022.github.io/wp-content/uploads/2019/08/lnmp-install-shell-300x231.png 300w" sizes="(max-width: 734px) 100vw, 734px" /></figure></div>


<p>　　运行此脚本所需要的文件如下，请尽量使用图中的命名规则给他们命名，并将他们全部放在 /root/ 目录下，请保证 /root/ 下有且仅有这些文件，并以 root 的身份运行，否则脚本会执行失败。其中：</p>



<p>　　eternalcenter-backup-2019-08-12-13.sql 指的是 mariadb 的数据库备份文件，如果是新建网站的话可以不要。</p>



<p>　　eternalcenter-backup-2019-08-13.tar 指的是网页程序的压缩包，必须是 tar 格式，如果是新建的网站的话，这个也可以换成，新网站的网页程序。</p>



<p>　　eternalcenter.com.crt 指的是网站的公钥，需要单独申请，方法可以在搜索引擎上搜索。</p>



<p>　　eternalcenter.com.key 指的是网站的私钥，需要单独申请，方法可以在搜索引擎上搜索。</p>



<p>　　install.sh 就是指的本脚本。</p>



<p>　　nginx-1.16.0.tar.gz 指的是 nginx 的源码安装包，这里的 -1.16.0.tar.gz 可以任意命名，只用保证这个文件名字里包含 nginx 就行了，这个文件可以在 nginx 官网上下载。</p>



<p>　　php-7.2.2-.tar.xz 指的是 php 的源码安装包，同样 这里的 -7.2.2-tar.xz 可以任意命名，只用保证这个文件名字包含 php 就行了，这个文件可以在 php 官网上下载。</p>



<p>　　port_monitoring.sh 只是一个监控端口的脚本，可以不要，使用者可以根据自我需求写一个，站主是通过这个脚本定期检查并自动启动需要启动但是没有启动的端口，关闭不需要但是启动了的端口。</p>



<h2>脚本</h2>



<pre class="wp-block-code"><code>#!/bin/bash

# variable initialization
cd
nginxp=`ls | grep "nginx"`
phpp=`ls | grep "php"`
webp=`ls | egrep "eternalcenter-backup-.*tar$"`
nginxr=${nginxp%%.tar*}
phpr=${phpp%%.tar*}


# upgrade system
yum makecache
yum -y update

yum clean all
yum repolist


# remove useless software
yum -y remove php*

yum -y remove mariadb*

systemctl stop postfix
yum -y remove postfix

systemctl stop chronyd
yum -y remove chrony

yum -y update


# install dependency package
yum -y install gcc pcre-devel openssl-devel libxml2-devel curl-devel libpng libpng-devel


# install nginx
cd
tar -xvf $nginxp -C /root/
cd $nginxr

useradd -s /sbin/nologin nginx
./configure --user=nginx --group=nginx --with-http_ssl_module
make &amp;&amp; make install
echo 'worker_processes  1;

events {
    worker_connections  65536;
}

http {
    limit_req_zone $binary_remote_addr zone=one:10m rate=1r/s;
    include       mime.types;
    default_type  application/octet-stream;

    sendfile        on;

    keepalive_timeout  65;

    server {
        listen       80;
        limit_req zone=one burst=5;
        server_name www.eternalcenter.com eternalcenter.com;

        rewrite ^/(.*)$ https://eternalcenter-sep-2022.github.io/$1 permanent;
      
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }

        }

    server {
        listen       443 ssl;
        server_name www.eternalcenter.com eternalcenter.com;

        if ($request_method !~ ^(GET|POST)$){
        return 444;
        }

        ssl_certificate      /usr/local/nginx/ssl/eternalcenter.com.crt;
        ssl_certificate_key  /usr/local/nginx/ssl/eternalcenter.com.key;

        ssl_session_cache    shared:SSL:1m;
        ssl_session_timeout  5m;

        ssl_ciphers  HIGH:!aNULL:!MD5;
        ssl_prefer_server_ciphers  on;

        location ~ \.php$ {
            fastcgi_pass 127.0.0.1:9000;
            include fastcgi.conf;
        } 

        location / {
        root html;
        index index.php index.html index.htm;
        }

        location ~ ^/\.user\.ini {
        deny all;
        }
    
        location ~*\.(jpd|jpeg|gif|png|css|js|ico|xml)$ {
        expires 30d;
        }

        error_page  404              /404.html;
        }

        gzip on;
	gzip_min_length 1000;
	gzip_comp_level 4;
	gzip_types text/plain test/css application/json application/x-javascript text/xml application/xml
	application/xml+rss text/javascripts;

	client_header_buffer_size 1k;
	large_client_header_buffers 4 4k;

	open_file_cache max=2000 inactive=20s;
	open_file_cache_valid  60s;
	open_file_cache_min_uses 5;
	open_file_cache_errors off;

}' > /usr/local/nginx/conf/nginx.conf
cd
mkdir /usr/local/nginx/ssl
mv eternalcenter.com.crt /usr/local/nginx/ssl
mv eternalcenter.com.key /usr/local/nginx/ssl

# install php
cd
tar -xvf $phpp -C /root/
cd $phpr
useradd -s /sbin/nologin php-fpm 
./configure --with-config-file-path=/usr/local/php/etc --enable-fpm --with-fpm-user=php-fpm --with-fpm-group=php-fpm --prefix=/usr/local/php --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --enable-mysqlnd --enable-mbstring --with-curl --with-gd --with-zlib
make &amp;&amp; make install
cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
cp /usr/local/php/etc/php-fpm.d/www.conf.default /usr/local/php/etc/php-fpm.d/www.conf
chown -R php-fpm:php-fpm /usr/local/nginx/html/

# install mariadb
yum -y install mariadb mariadb-server mariadb-devel
sed -i "/^datadir/a log_bin=ec" /etc/my.cnf
sed -i "/^datadir/a binlog_format="mixed"" /etc/my.cnf
sed -i "/^datadir/a server_id=51" /etc/my.cnf
systemctl enable mariadb

# deploy web software
cd
rm -rf /usr/local/nginx/html/*
mkdir websoftcache
tar -xvf $webp -C websoftcache
cd websoftcache
websoftcachen=`ls | wc -l`

if &#91; $websoftcachen -ne 1 ];then
        cd
        tar -xvf $webp -C /usr/local/nginx/html/
else
        webdir=`ls`
        cd $webdir
        mv * /usr/local/nginx/html/
fi

chown -R php-fpm:php-fpm /usr/local/nginx/html

# recover database
systemctl start mariadb
cd
mysql -uroot &lt; *.sql &amp;> /dev/null
systemctl stop mariadb

# set the concurrency number accepted by the system to 65535
echo '* soft nofile 65535
* hard nofile 65535' >> /etc/security/limits.conf

# open firewall port
firewall-cmd --add-port=80/tcp --permanent
firewall-cmd --add-port=443/tcp --permanent
systemctl restart firewalld

# move the monitoring scripts that need to be used regularly to the specified location(/root/shell/port_monitoring.sh you need to write it yourself)
mkdir /shell
mv port_monitoring.sh /shell
chmod u+x /shell/*

# set up regular automatic running monitoring script(/root/shell/port_monitoring.sh you need to write it yourself)
echo '*/1 * * * * root /shell/port_monitoring.sh' >> /etc/crontab

# add another user（for data backup）
useradd zhumingyu
mkdir /cache
chown -R zhumingyu:zhumingyu /cache

# delete redundant files
cd
rm -rf *

# restart the server
reboot</code></pre>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>[工具] Shell 批量修改多个 MySQL root 的初始密码</title>
		<link>https://eternalcenter-sep-2022.github.io/shell-mysql-password-change/</link>
		
		<dc:creator><![CDATA[Mingyu Zhu]]></dc:creator>
		<pubDate>Wed, 16 Jan 2019 11:13:14 +0000</pubDate>
				<category><![CDATA[Chinese (中文)]]></category>
		<category><![CDATA[Database (数据库)]]></category>
		<category><![CDATA[Language (语言)]]></category>
		<category><![CDATA[MariaDB]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[Relational Database (SQL) (关系型数据库 )]]></category>
		<category><![CDATA[Shell]]></category>
		<category><![CDATA[Shell Database (数据库)]]></category>
		<category><![CDATA[Shell Deployment (部署)]]></category>
		<category><![CDATA[Shell Tools (工具)]]></category>
		<guid isPermaLink="false">https://eternalcenter-sep-2022.github.io/?p=1259</guid>

					<description><![CDATA[介绍 基本信息 作者：朱明宇名称：批量修改多个 MySQL root 的初始密码作用：批量修改多个 MySQL root 的初始密码 使用方法 1. 确认 MariaDB&#38;MySQL 已提前装好2. 在此脚本的分割线内写入相应的内容3. 给此脚本添加执行权限4. 执行此脚本 脚本分割线里的变量 1. nm=192.168.4.0 #网段，网段必须为 C 类网段，请保证格式和前三个网络位一定正确2. sip=51 #起始 ip，ip 的范围是 0-2553. lip=53 #结束 ip，ip 的范围是 0-2554. pd=123456 #想要修改的 MySQL 密码,至少必须要 ６ 个数 注意 此脚本执行前必须要先保证执行本脚本的用户能无密码 ssh 远程这些远程服务器 脚本]]></description>
										<content:encoded><![CDATA[
<h2>介绍</h2>



<h3>基本信息</h3>



<p>作者：朱明宇<br>名称：批量修改多个 MySQL root 的初始密码<br>作用：批量修改多个 MySQL root 的初始密码</p>



<h3>使用方法</h3>



<p>1. 确认 MariaDB&amp;MySQL 已提前装好<br>2. 在此脚本的分割线内写入相应的内容<br>3. 给此脚本添加执行权限<br>4. 执行此脚本</p>



<h3>脚本分割线里的变量</h3>



<p>1. nm=192.168.4.0 #网段，网段必须为 C 类网段，请保证格式和前三个网络位一定正确<br>2. sip=51 #起始 ip，ip 的范围是 0-255<br>3. lip=53 #结束 ip，ip 的范围是 0-255<br>4. pd=123456 #想要修改的 MySQL 密码,至少必须要 ６ 个数</p>



<h3>注意</h3>



<p>此脚本执行前必须要先保证执行本脚本的用户能无密码 ssh 远程这些远程服务器</p>



<h2>脚本</h2>



<pre class="wp-block-code"><code>#!/bin/bash

####################### Separator ########################

nm=192.168.4.0
sip=51
lip=53
pd=123456

####################### Separator ########################

fnm=${nm%.*}

set timeout 3

rpm -q expect

if &#91; $? -ne 0 ];then
        yum -y install expect &amp;&gt; /dev/null
fi

for i in `seq $sip $lip`
do

        echo $fnm.$i

        ssh $fnm.$i 'grep validate_password_policy=0 /etc/my.cnf'
        if &#91; $? -ne 0 ];then
                ssh $fnm.$i 'sed -i "/^\&#91;mysqld\]$/a validate_password_policy=0" /etc/my.cnf'
        fi

        ssh $fnm.$i 'grep validate_password_length=6 /etc/my.cnf'
        if &#91; $? -ne 0 ];then
                ssh $fnm.$i 'sed -i "/^\&#91;mysqld\]$/a validate_password_length=6" /etc/my.cnf'
        fi

        ssh $fnm.$i 'systemctl restart mysqld'

        a=`ssh $fnm.$i "grep 'password is generated for root@localhost' /var/log/mysqld.log" |tail -1 | awk '{print $NF}'`

        expect &lt;&lt; EOF
        spawn ssh $fnm.$i "mysqladmin -uroot -p password $pd "
        expect "Enter password:"            {send "$a\r"}
        expect "#"                          {send "\r"}
        EOF

done</code></pre>
]]></content:encoded>
					
		
		
			</item>
	</channel>
</rss>
