MySQL所有的安裝部署方式

来源:https://www.cnblogs.com/renshengdezheli/archive/2020/05/28/12981371.html
-Advertisement-
Play Games

一.前言 ​ linux安裝軟體的方式多種多樣,MySQL也不例外,本文將介紹MySQL所有的安裝方式。 二.關於MySQL的安裝 ​ MySQL一般可以採用四種安裝方式,每種方式各有優點,使用場景各有不同: yum安裝MySQL,優點:簡單,方便,適用場景:可以訪問網路的環境 離線源碼編譯安裝My ...


目錄

一.前言

​ linux安裝軟體的方式多種多樣,MySQL也不例外,本文將介紹MySQL所有的安裝方式。

二.關於MySQL的安裝

​ MySQL一般可以採用四種安裝方式,每種方式各有優點,使用場景各有不同:

  • yum安裝MySQL,優點:簡單,方便,適用場景:可以訪問網路的環境
  • 離線源碼編譯安裝MySQL,優點:可定製,適用性強,適用場景:無網路,需要定製MySQL,平臺相容性不強(記憶體最好大於4G不然編譯會出現記憶體不足的報錯)
  • RPM包安裝MySQL,優點:簡單,方便,適用場景:redhat系統
  • 通用二進位包安裝MySQL,優點:簡單,好維護,適用場景:大部分環境都適用(推薦)

三.部署規劃

3.1 伺服器規劃

伺服器 操作系統版本 CPU架構 MySQL安裝方式
node6 CentOS Linux release 7.4.1708 x86_64 源碼編譯安裝MySQL
node7 CentOS Linux release 7.4.1708 x86_64 通用二進位包安裝MySQL
node8 CentOS Linux release 7.4.1708 x86_64 RPM包安裝MySQL
node9 CentOS Linux release 7.4.1708 x86_64 yum安裝MySQL

3.2 資料庫目錄規劃

文件類型 文件部署位置
數據目錄datadir /data/data(/data目錄請確保足夠大)
配置文件my.cnf /etc/my.cnf
錯誤日誌log-error /data/log/mysql_error.log
二進位日誌log-bin /data/binlogs/mysql-bin(用於資料庫恢復和主從複製,以及審計(audit)操作)
慢查詢日誌slow_query_log_file /data/log/mysql_slow_query.log
套接字文件socket /data/run/mysql.sock
進程ID文件mysql.pid /data/run/mysql.pid

四.準備工具

1.MySQL通用二進位包:mysql-5.7.28-linux-glibc2.12-x86_64.tar.gz

下載地址:https://dev.mysql.com/downloads/mysql/5.7.html#downloads

2.MySQLRPM包:mysql-community-client-5.7.28-1.el7.x86_64.rpm

​ mysql-community-common-5.7.28-1.el7.x86_64.rpm

​ mysql-community-devel-5.7.28-1.el7.x86_64.rpm

​ mysql-community-libs-5.7.28-1.el7.x86_64.rpm

​ mysql-community-libs-compat-5.7.28-1.el7.x86_64.rpm

​ mysql-community-server-5.7.28-1.el7.x86_64.rpm

下載地址:https://dev.mysql.com/downloads/mysql/5.7.html#downloads

1575168892245

3.MySQL源碼包:mysql-boost-5.7.28.tar.gz

下載地址:https://dev.mysql.com/downloads/mysql/5.7.html#downloads

1575168777801

4.MySQL的Yum源:mysql57-community-release-el7-10.noarch.rpm

或者mysql-community-release-el7-5.noarch.rpm

下載方法:wget -i -c http://dev.mysql.com/get/mysql57-community-release-el7-10.noarch.rpm

或者wget http://repo.mysql.com/mysql-community-release-el7-5.noarch.rpm

五.通用二進位包安裝MySQL

5.1 上傳MySQL通用二進位安裝包到node7的/usr/local/src目錄下

[root@node7 src]# pwd
/usr/local/src
[root@node7 src]# ls
mysql-5.7.26-linux-glibc2.12-x86_64.tar.gz

5.2 解壓MySQL到指定目錄並改名

[root@node7 src]# tar -zxf mysql-5.7.26-linux-glibc2.12-x86_64.tar.gz -C /usr/local/
[root@node7 src]# cd /usr/local/
[root@node7 local]# ls
bin  etc  games  include  lib  lib64  libexec  mysql-5.7.26-linux-glibc2.12-x86_64  sbin  share  src
[root@node7 local]# mv mysql-5.7.26-linux-glibc2.12-x86_64 mysql
[root@node7 local]# ls
bin  etc  games  include  lib  lib64  libexec  mysql  sbin  share  src

5.3 創建MySQL用戶和用戶組

[root@node7 local]# groupadd -g 1111 mysql
[root@node7 local]# useradd -g mysql -u 1111 -s /sbin/nologin mysql
[root@node7 local]# id mysql    #查看用戶信息
uid=1111(mysql) gid=1111(mysql) groups=1111(mysql)

5.4 配置MySQL的bin目錄到PATH路徑

[root@node7 local]# echo "export PATH=$PATH:/usr/local/mysql/bin" >> /etc/profile
[root@node7 local]# source /etc/profile
[root@node7 local]# mysql    #輸入MySQL之後雙擊tab鍵,即可列出候選MySQL命令
mysql                       mysql_client_test_embedded  mysqld-debug                mysqldumpslow               mysql_plugin                mysqlslap                   mysql_upgrade
mysqladmin                  mysql_config                mysqld_multi                mysql_embedded              mysqlpump                   mysql_ssl_rsa_setup         mysqlxtest
mysqlbinlog                 mysql_config_editor         mysqld_safe                 mysqlimport                 mysql_secure_installation   mysqltest_embedded          
mysqlcheck                  mysqld                      mysqldump                   mysql_install_db            mysqlshow                   mysql_tzinfo_to_sql

5.5 創建MySQL數據存放目錄

[root@node7 ~]# mkdir -p /data/{data,log,binlogs,run}
[root@node7 ~]# tree /data    #如果沒有tree命令,則yum -y install tree安裝
/data
├── binlogs
├── data
├── log
└── run

4 directories, 0 files
[root@node7 ~]# chown -R mysql:mysql /data
[root@node7 ~]# ll /data/
total 0
drwxr-xr-x 2 mysql mysql 6 Dec  3 11:07 binlogs
drwxr-xr-x 2 mysql mysql 6 Dec  3 11:07 data
drwxr-xr-x 2 mysql mysql 6 Dec  3 11:07 log
drwxr-xr-x 2 mysql mysql 6 Dec  3 11:07 run

5.6 配置MySQL配置文件

[root@node7 mysql]# rm -rf /etc/my.cnf
[root@node7 mysql]# touch /etc/my.cnf
#my.cnf配置文件詳解,請查看我上一篇blog的#https://www.cnblogs.com/renshengdezheli/p/11913248.html的“MySQL配置文件優化參考”
[root@node7 mysql]# cat /etc/my.cnf
[client]
port=3306
socket=/data/run/mysql.sock

[mysqld]
port=3306
socket=/data/run/mysql.sock
pid_file=/data/run/mysql.pid
datadir=/data/data
default_storage_engine=InnoDB
max_allowed_packet=512M
max_connections=2048
open_files_limit=65535

skip-name-resolve
lower_case_table_names=1

character-set-server=utf8mb4
collation-server=utf8mb4_unicode_ci
init_connect='SET NAMES utf8mb4'

innodb_buffer_pool_size=1024M
innodb_log_file_size=2048M
innodb_file_per_table=1
innodb_flush_log_at_trx_commit=0

key_buffer_size=64M

log-error=/data/log/mysql_error.log
log-bin=/data/binlogs/mysql-bin
slow_query_log=1
slow_query_log_file=/data/log/mysql_slow_query.log
long_query_time=5

tmp_table_size=32M
max_heap_table_size=32M
query_cache_type=0
query_cache_size=0

server-id=1

5.7 初始化MySQL資料庫

[root@node7 mysql]# mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/data/data
[root@node7 mysql]# echo $?
0
[root@node7 mysql]# grep 'temporary password' /data/log/mysql_error.log    #查看MySQL初始化密碼
2019-12-03T03:47:42.639938Z 1 [Note] A temporary password is generated for root@localhost: lhrh>J,p<8gw

5.8 生成ssl(可選)

#關於MySQL開啟ssl查看https://www.cnblogs.com/mysql-dba/p/7061300.html
[root@node7 mysql]# mysql_ssl_rsa_setup --basedir=/usr/local/mysql --datadir=/data/data
Generating a 2048 bit RSA private key
......................................+++
.+++
writing new private key to 'ca-key.pem'
-----
Generating a 2048 bit RSA private key
....................................+++
............................+++
writing new private key to 'server-key.pem'
-----
Generating a 2048 bit RSA private key
.....................................................................................+++
..............................................+++
writing new private key to 'client-key.pem'
-----
#執行完成之後,會有在datadir目錄生成*.pem文件
[root@node7 mysql]# ls /data/data/
auto.cnf    client-cert.pem  ibdata1      mysql               public_key.pem   sys
ca-key.pem  client-key.pem   ib_logfile0  performance_schema  server-cert.pem
ca.pem      ib_buffer_pool   ib_logfile1  private_key.pem     server-key.pem

5.9 配置MySQL啟動項並設置開機自啟動

5.9.1 centos6版本

cd /usr/local/mysql
cp support-files/mysql.server /etc/init.d/mysql.server
chkconfig --add mysql.server
chkconfig  mysql.server on
chkconfig --list

5.9.2 centos7版本

[root@node7 system]# cd /usr/lib/systemd/system
[root@node7 system]# touch mysqld.service 
[root@node7 system]# vim mysqld.service 
[root@node7 system]# cat mysqld.service 
# Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; version 2 of the License.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
#
# systemd service file for MySQL forking server
#

[Unit]
Description=MySQL Server
Documentation=man:mysqld(5.7)
Documentation=http://dev.mysql.com/doc/refman/en/using-systemd.html
After=network.target
After=syslog.target

[Install]
WantedBy=multi-user.target

[Service]
User=mysql
Group=mysql

Type=forking

PIDFile=/data/run/mysql.pid

# Disable service start and stop timeout logic of systemd for mysqld service.
TimeoutSec=0

# Execute pre and post scripts as root
PermissionsStartOnly=true

# Needed to create system tables
#ExecStartPre=/usr/bin/mysqld_pre_systemd

# Start main service
ExecStart=/usr/local/mysql/bin/mysqld --daemonize --pid-file=/data/run/mysql.pid $MYSQLD_OPTS

# Use this to switch malloc implementation
EnvironmentFile=-/etc/sysconfig/mysql

# Sets open_files_limit
LimitNOFILE = 65535

Restart=on-failure

RestartPreventExitStatus=1

PrivateTmp=false

[root@node7 system]# systemctl daemon-reload    #重新載入服務配置文件
[root@node7 system]# systemctl enable mysqld    #設置MySQL開機自啟動
Created symlink from /etc/systemd/system/multi-user.target.wants/mysqld.service to /usr/lib/systemd/system/mysqld.service.
[root@node7 system]# systemctl is-enabled mysqld   #查看MySQL開機自啟動是否設置成功
enabled

5.10 啟動MySQL

[root@node7 system]# systemctl start mysqld
[root@node7 system]# systemctl status mysqld    #查看MySQL啟動狀態
● mysqld.service - MySQL Server
   Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
   Active: active (running) since Tue 2019-12-03 14:42:14 CST; 9s ago
     Docs: man:mysqld(5.7)
           http://dev.mysql.com/doc/refman/en/using-systemd.html
  Process: 2905 ExecStart=/usr/local/mysql/bin/mysqld --daemonize --pid-file=/data/run/mysql.pid $MYSQLD_OPTS (code=exited, status=0/SUCCESS)
 Main PID: 2907 (mysqld)
   CGroup: /system.slice/mysqld.service
           └─2907 /usr/local/mysql/bin/mysqld --daemonize --pid-file=/data/run/mysql.pid

Dec 03 14:42:13 node7 systemd[1]: Starting MySQL Server...
Dec 03 14:42:14 node7 systemd[1]: Started MySQL Server.
[root@node7 system]# ps -ef | grep mysql         #查看MySQL進程
mysql      2907      1  2 14:42 ?        00:00:00 /usr/local/mysql/bin/mysqld --daemonize --pid-file=/data/run/mysql.pid
root       2942   2576  0 14:42 pts/0    00:00:00 grep --color=auto mysql

5.11 進行MySQL安全初始化(可選)

[root@node7 system]# mysql_secure_installation 

Securing the MySQL server deployment.

Enter password for user root:    #這裡輸入MySQL初始化時生成的密碼(grep 'temporary password' /data/log/mysql_error.log)

The existing password for the user account root has expired. Please set a new password.

New password:   #輸入新密碼

Re-enter new password: 

VALIDATE PASSWORD PLUGIN can be used to test passwords
and improve security. It checks the strength of password
and allows the users to set only those passwords which are
secure enough. Would you like to setup VALIDATE PASSWORD plugin?

Press y|Y for Yes, any other key for No: n   #y安裝MySQL密碼插件
Using existing password for root.
Change the password for root ? ((Press y|Y for Yes, any other key for No) : n

 ... skipping.
By default, a MySQL installation has an anonymous user,
allowing anyone to log into MySQL without having to have
a user account created for them. This is intended only for
testing, and to make the installation go a bit smoother.
You should remove them before moving into a production
environment.

Remove anonymous users? (Press y|Y for Yes, any other key for No) : y  #y移除匿名用戶
Success.


Normally, root should only be allowed to connect from
'localhost'. This ensures that someone cannot guess at
the root password from the network.

Disallow root login remotely? (Press y|Y for Yes, any other key for No) : n  #是否允許root遠程登錄

 ... skipping.
By default, MySQL comes with a database named 'test' that
anyone can access. This is also intended only for testing,
and should be removed before moving into a production
environment.


Remove test database and access to it? (Press y|Y for Yes, any other key for No) : y  #是否移除test資料庫
 - Dropping test database...
Success.

 - Removing privileges on test database...
Success.

Reloading the privilege tables will ensure that all changes
made so far will take effect immediately.

Reload privilege tables now? (Press y|Y for Yes, any other key for No) : y  #刷新許可權表
Success.

All done!

5.12 修改密碼,給用戶賦許可權(根據自己情況賦許可權)

[root@node7 ~]# mysql -uroot -p111111
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.26-log MySQL Community Server (GPL)

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

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

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

mysql> SET PASSWORD = PASSWORD('123456');#修改root密碼為123456,如果提示ERROR 1819 (HY000): Your password does not satisfy the current policy requirements,則說明密碼設置太簡單,如果想設置123456這樣的簡單密碼,可在SQL中執行:
	#mysql> set global validate_password_policy=0;
	#mysql> set global validate_password_length=1;
	#這樣再次執行SET PASSWORD = PASSWORD('123456')就可成功。
Query OK, 0 rows affected, 1 warning (0.01 sec)

mysql> UPDATE mysql.user SET authentication_string =PASSWORD('123456') WHERE User='mysql';    #修改MySQL的mysql用戶的密碼為123456
Query OK, 0 rows affected, 1 warning (0.00 sec)
Rows matched: 0  Changed: 0  Warnings: 1

mysql> GRANT ALL PRIVILEGES ON *.* TO mysql@localhost IDENTIFIED BY '123456' WITH GRANT OPTION;   
Query OK, 0 rows affected, 2 warnings (0.00 sec)

mysql> GRANT ALL PRIVILEGES ON *.* TO mysql@"%" IDENTIFIED BY '123456' WITH GRANT OPTION;   #賦予mysql用戶可以在任何機器上登錄,並擁有所有表的所有許可權
Query OK, 0 rows affected, 1 warning (0.00 sec)

mysql> GRANT ALL PRIVILEGES ON *.* TO root@localhost IDENTIFIED BY '123456' WITH GRANT OPTION;
Query OK, 0 rows affected, 2 warnings (0.00 sec)

mysql> GRANT ALL PRIVILEGES ON *.* TO root@"%" IDENTIFIED BY '123456' WITH GRANT OPTION;
Query OK, 0 rows affected, 1 warning (0.07 sec)

mysql> FLUSH PRIVILEGES ;   #刷新許可權,讓修改立即生效
Query OK, 0 rows affected (0.00 sec)

mysql> exit;
Bye

--------------------------------------------------------------------------------------
#以下是為MySQL賦許可權的介紹
mysql> grant 許可權1,許可權2,…許可權n on 資料庫名稱.表名稱 to 用戶名@用戶地址 identified by ‘連介面令’;
許可權1,許可權2,…許可權n代表select,insert,update,delete,create,drop,index,alter,grant,references,reload,shutdown,process,file等14個許可權。
當許可權1,許可權2,…許可權n被all privileges或者all代替,表示賦予用戶全部許可權。
當資料庫名稱.表名稱被*.*代替,表示賦予用戶操作伺服器上所有資料庫所有表的許可權。
用戶地址可以是localhost,也可以是ip地址、機器名字、功能變數名稱。也可以用’%'表示從任何地址連接。
‘連介面令’不能為空,否則創建失敗。
比如:
mysql>grant select,insert,update,delete,create,drop on vtdc.employee to [email protected] identified by ‘123′;
給來自10.163.225.87的用戶joe分配可對資料庫vtdc的employee表進行select,insert,update,delete,create,drop等操作的許可權,並設定口令為123。
 
mysql>grant all privileges on vtdc.* to [email protected] identified by ‘123′;
給來自10.163.225.87的用戶joe分配可對資料庫vtdc所有表進行所有操作的許可權,並設定口令為123。
--------------------------------------------------------------------------------------

5.13 導入時區信息到MySQL庫

[root@node7 system]# mysql_tzinfo_to_sql /usr/share/zoneinfo | mysql -uroot -p111111 mysql
#執行上述操作之後,time_zone,time_zone_leap_second,time_zone_name,time_zone_transition   ,time_zone_transition_type表就有時區數據了
[root@node7 system]# mysql -uroot -p111111 mysql
mysql> show tables;
+---------------------------+
| Tables_in_mysql           |
+---------------------------+
| columns_priv              |
| db                        |
| engine_cost               |
| event                     |
| func                      |
| general_log               |
| gtid_executed             |
| help_category             |
| help_keyword              |
| help_relation             |
| help_topic                |
| innodb_index_stats        |
| innodb_table_stats        |
| ndb_binlog_index          |
| plugin                    |
| proc                      |
| procs_priv                |
| proxies_priv              |
| server_cost               |
| servers                   |
| slave_master_info         |
| slave_relay_log_info      |
| slave_worker_info         |
| slow_log                  |
| tables_priv               |
| time_zone                 |
| time_zone_leap_second     |
| time_zone_name            |
| time_zone_transition      |
| time_zone_transition_type |
| user                      |
+---------------------------+
31 rows in set (0.00 sec)

5.14 查看MySQL版本信息

[root@node7 system]# mysql -V
mysql  Ver 14.14 Distrib 5.7.26, for linux-glibc2.12 (x86_64) using  EditLine wrapper
[root@node7 system]# mysqladmin version -uroot -p111111
mysqladmin: [Warning] Using a password on the command line interface can be insecure.
mysqladmin  Ver 8.42 Distrib 5.7.26, for linux-glibc2.12 on x86_64
Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Server version		5.7.26-log
Protocol version	10
Connection		Localhost via UNIX socket
UNIX socket		/data/run/mysql.sock
Uptime:			31 min 53 sec

Threads: 1  Questions: 8855  Slow queries: 0  Opens: 214  Flush tables: 1  Open tables: 203  Queries per second avg: 4.628

5.15 如果防火牆開著,則需要開放3306埠

[root@node7 system]# systemctl status firewalld
● firewalld.service - firewalld - dynamic firewall daemon
   Loaded: loaded (/usr/lib/systemd/system/firewalld.service; disabled; vendor preset: enabled)
   Active: active (running) since Tue 2019-12-03 15:22:18 CST; 3s ago
     Docs: man:firewalld(1)
 Main PID: 3343 (firewalld)
   CGroup: /system.slice/firewalld.service
           └─3343 /usr/bin/python -Es /usr/sbin/firewalld --nofork --nopid

Dec 03 15:22:17 node7 systemd[1]: Starting firewalld - dynamic firewall daemon...
Dec 03 15:22:18 node7 systemd[1]: Started firewalld - dynamic firewall daemon.
Dec 03 15:22:18 node7 firewalld[3343]: WARNING: ICMP type 'beyond-scope' is not supported by the kernel for ipv6.
Dec 03 15:22:18 node7 firewalld[3343]: WARNING: beyond-scope: INVALID_ICMPTYPE: No supported ICMP type., ignoring...-time.
Dec 03 15:22:18 node7 firewalld[3343]: WARNING: ICMP type 'failed-policy' is not supported by the kernel for ipv6.
Dec 03 15:22:18 node7 firewalld[3343]: WARNING: failed-policy: INVALID_ICMPTYPE: No supported ICMP type., ignorin...-time.
Dec 03 15:22:18 node7 firewalld[3343]: WARNING: ICMP type 'reject-route' is not supported by the kernel for ipv6.
Dec 03 15:22:18 node7 firewalld[3343]: WARNING: reject-route: INVALID_ICMPTYPE: No supported ICMP type., ignoring...-time.
Hint: Some lines were ellipsized, use -l to show in full.
#添加防火牆規則
[root@node7 system]# firewall-cmd --permanent --zone=public --add-port=3306/tcp
success
#重新載入防火牆規則
[root@node7 system]# firewall-cmd --reload
success
#檢查規則是否設置生效
[root@node7 system]# firewall-cmd --zone=public --query-port=3306/tcp
yes
#列出防火牆所有開放的埠
[root@node7 system]# firewall-cmd --list-all
public (active)
  target: default
  icmp-block-inversion: no
  interfaces: ens33
  sources: 
  services: ssh dhcpv6-client
  ports: 3306/tcp
  protocols: 
  masquerade: no
  forward-ports: 
  source-ports: 
  icmp-blocks: 
  rich rules: 

5.16 利用logrotate對MySQL日誌進行輪轉(日誌自動備份切割)

#logrotate配置詳解請查看:https://www.linuxidc.com/Linux/2019-02/157099.htm
[root@node7 ~]# touch /root/.my.cnf
[root@node7 ~]# vim /root/.my.cnf 
[root@node7 ~]# cat /root/.my.cnf 
[mysqladmin]  
password=111111
user=root
[root@node7 ~]# chmod 600 /root/.my.cnf 
[root@node7 ~]# cp /usr/local/mysql/support-files/mysql-log-rotate /etc/logrotate.d/
[root@node7 ~]# chmod 644 /etc/logrotate.d/mysql-log-rotate 
[root@node7 ~]# vim /etc/logrotate.d/mysql-log-rotate 
[root@node7 ~]# cat /etc/logrotate.d/mysql-log-rotate 
# The log file name and location can be set in
# /etc/my.cnf by setting the "log-error" option
# in either [mysqld] or [mysqld_safe] section as
# follows:
#
# [mysqld]
# log-error=/usr/local/mysql/data/mysqld.log
#
# In case the root user has a password, then you
# have to create a /root/.my.cnf configuration file
# with the following content:
#
# [mysqladmin]
# password = <secret> 
# user= root
#
# where "<secret>" is the password. 
#
# ATTENTION: The /root/.my.cnf file should be readable
# _ONLY_ by root !

/data/log/mysql_*.log {
        # create 600 mysql mysql
        notifempty  #當日誌文件為空時,不進行輪轉
        daily  #預設每一天執行一次rotate輪轉工作
        rotate 52  #保留多少個日誌文件(輪轉幾次).預設保留四個.就是指定日誌文件刪除之前輪轉的次數,0 指沒有備份,此處表示保留52天的日誌
        missingok   #如果日誌文件丟失,不要顯示錯誤
        compress    #通過gzip 壓縮轉儲以後的日誌
    postrotate   #執行的指令
	# just if mysqld is really running
	if test -x /usr/local/mysql/bin/mysqladmin && \
	   /usr/local/mysql/bin/mysqladmin ping &>/dev/null
	then
	   /usr/local/mysql/bin/mysqladmin flush-logs
	fi
    endscript
}
[root@node7 ~]# 
[root@node7 ~]# logrotate -fv /etc/logrotate.d/mysql-log-rotate #強制進行日誌輪轉
reading config file /etc/logrotate.d/mysql-log-rotate
Allocating hash table for state file, size 15360 B

Handling 1 logs

rotating pattern: /data/log/mysql_*.log  forced from command line (52 rotations)
empty log files are not rotated, old logs are removed
considering log /data/log/mysql_error.log
  log needs rotating
considering log /data/log/mysql_slow_query.log
  log needs rotating
rotating log /data/log/mysql_error.log, log->rotateCount is 52
dateext suffix '-20191203'
glob pattern '-[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]'
renaming /data/log/mysql_error.log.52.gz to /data/log/mysql_error.log.53.gz 
(t -- won't try to dispose of it
.................
renaming /data/log/mysql_slow_query.log to /data/log/mysql_slow_query.log.1
running postrotate script
compressing log with: /bin/gzip
[root@node7 ~]# 
[root@node7 ~]# echo $?
0
#此時查看日誌目錄,發現日誌已經進行輪轉,並壓縮
[root@node7 ~]# ls /data/log/
mysql_error.log  mysql_error.log.1.gz  mysql_slow_query.log  mysql_slow_query.log.1.gz

自此,通用二進位包安裝MySQL完畢

六.使用RPM包安裝MySQL

6.1 上傳MySQL的RPM包到/usr/local/src目錄下

[root@node8 local]# cd /usr/local/src/
[root@node8 src]# ls
mysql-community-client-5.7.23-1.el7.x86_64.rpm  mysql-community-libs-5.7.23-1.el7.x86_64.rpm
mysql-community-common-5.7.23-1.el7.x86_64.rpm  mysql-community-libs-compat-5.7.23-1.el7.x86_64.rpm
mysql-community-devel-5.7.23-1.el7.x86_64.rpm   mysql-community-server-5.7.23-1.el7.x86_64.rpm

6.2 安裝RPM包

[root@node8 src]# rpm -ivh ./*.rpm
warning: ./mysql-community-client-5.7.23-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
error: Failed dependencies:
	mariadb-libs is obsoleted by mysql-community-libs-5.7.23-1.el7.x86_64
	mariadb-libs is obsoleted by mysql-community-libs-compat-5.7.23-1.el7.x86_64
#出現上述錯誤說明:和mariadb-libs組件衝突,卸載mariadb-libs相關組件即可
[root@node8 src]# rpm -qa | grep mariadb*    #查看mariadb-libs相關的組件
mariadb-libs-5.5.56-2.el7.x86_64
[root@node8 src]# rpm -e --nodeps mariadb-libs-5.5.56-2.el7.x86_64 #卸載mariadb-libs組件
warning: /etc/my.cnf saved as /etc/my.cnf.rpmsave
[root@node8 src]# rpm -ivh ./*.rpm
warning: ./mysql-community-client-5.7.23-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Preparing...                          ################################# [100%]
Updating / installing...
   1:mysql-community-common-5.7.23-1.e################################# [ 17%]
   2:mysql-community-libs-5.7.23-1.el7################################# [ 33%]
   3:mysql-community-client-5.7.23-1.e################################# [ 50%]
   4:mysql-community-server-5.7.23-1.e################################# [ 67%]
   5:mysql-community-devel-5.7.23-1.el################################# [ 83%]
   6:mysql-community-libs-compat-5.7.2################################# [100%]
#此時RPM包安裝完畢

6.3 啟動MySQL,修改密碼,為用戶賦權

[root@node8 src]# service mysqld status
Redirecting to /bin/systemctl status mysqld.service
● mysqld.service - MySQL Server
   Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
   Active: inactive (dead)
     Docs: man:mysqld(8)
           http://dev.mysql.com/doc/refman/en/using-systemd.html
[root@node8 src]# service mysqld start
Redirecting to /bin/systemctl start mysqld.service
[root@node8 src]# grep password /var/log/mysqld.log 
2019-12-03T10:16:32.931929Z 1 [Note] A temporary password is generated for root@localhost: 3yGgt,Eipr%z
[root@node8 src]# mysql -uroot -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.23

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

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

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

mysql> SET PASSWORD = PASSWORD('123456');#修改root密碼為123456,如果提示ERROR 1819 (HY000): Your password does not satisfy the current policy requirements,則說明密碼設置太簡單,如果想設置123456這樣的簡單密碼,可在SQL中執行:
	#mysql> set global validate_password_policy=0;
	#mysql> set global validate_password_length=1;
	#這樣再次執行SET PASSWORD = PASSWORD('123456')就可成功。
Query OK, 0 rows affected, 1 warning (0.01 sec)

mysql> UPDATE mysql.user SET authentication_string =PASSWORD('123456') WHERE User='mysql';    #修改MySQL的mysql用戶的密碼為123456
Query OK, 0 rows affected, 1 warning (0.00 sec)
Rows matched: 0  Changed: 0  Warnings: 1

mysql> GRANT ALL PRIVILEGES ON *.* TO mysql@localhost IDENTIFIED BY '123456' WITH GRANT OPTION;   
Query OK, 0 rows affected, 2 warnings (0.00 sec)

mysql> GRANT ALL PRIVILEGES ON *.* TO mysql@"%" IDENTIFIED BY '123456' WITH GRANT OPTION;   #賦予mysql用戶可以在任何機器上登錄,並擁有所有表的所有許可權
Query OK, 0 rows affected, 1 warning (0.00 sec)

mysql> GRANT ALL PRIVILEGES ON *.* TO root@localhost IDENTIFIED BY '123456' WITH GRANT OPTION;
Query OK, 0 rows affected, 2 warnings (0.00 sec)

mysql> GRANT ALL PRIVILEGES ON *.* TO root@"%" IDENTIFIED BY '123456' WITH GRANT OPTION;
Query OK, 0 rows affected, 1 warning (0.07 sec)

mysql> FLUSH PRIVILEGES ;   #刷新許可權,讓修改立即生效
Query OK, 0 rows affected (0.00 sec)

mysql> exit;
Bye

--------------------------------------------------------------------------------------
#以下是為MySQL賦許可權的介紹
mysql> grant 許可權1,許可權2,…許可權n on 資料庫名稱.表名稱 to 用戶名@用戶地址 identified by ‘連介面令’;
許可權1,許可權2,…許可權n代表select,insert,update,delete,create,drop,index,alter,grant,references,reload,shutdown,process,file等14個許可權。
當許可權1,許可權2,…許可權n被all privileges或者all代替,表示賦予用戶全部許可權。
當資料庫名稱.表名稱被*.*代替,表示賦予用戶操作伺服器上所有資料庫所有表的許可權。
用戶地址可以是localhost,也可以是ip地址、機器名字、功能變數名稱。也可以用’%'表示從任何地址連接。
‘連介面令’不能為空,否則創建失敗。
比如:
mysql>grant select,insert,update,delete,create,drop on vtdc.employee to [email protected] identified by ‘123′;
給來自10.163.225.87的用戶joe分配可對資料庫vtdc的employee表進行select,insert,update,delete,create,drop等操作的許可權,並設定口令為123。
 
mysql>grant all privileges on vtdc.* to [email protected] identified by ‘123′;
給來自10.163.225.87的用戶joe分配可對資料庫vtdc所有表進行所有操作的許可權,並設定口令為123。
--------------------------------------------------------------------------------------

自此MySQL的RPM安裝就完畢了,此方法自動生成/etc/my.cnf,查看配置文件可知道MySQL的日誌目錄和數據目錄

七.使用yum安裝MySQL

7.1 下載並安裝MySQL官方的 Yum Repository

[root@node9 ~]# wget -i -c http://dev.mysql.com/get/mysql57-community-release-el7-10.noarch.rpm
--2019-12-03 23:23:44--  http://dev.mysql.com/get/mysql57-community-release-el7-10.noarch.rpm
Resolving dev.mysql.com (dev.mysql.com)... 137.254.60.11
Connecting to dev.mysql.com (dev.mysql.com)|137.254.60.11|:80... connected.
HTTP request sent, awaiting response... 301 Moved Permanently
Location: https://dev.mysql.com/get/mysql57-community-release-el7-10.noarch.rpm [following]
--2019-12-03 23:23:57--  https://dev.mysql.com/get/mysql57-community-release-el7-10.noarch.rpm
Connecting to dev.mysql.com (dev.mysql.com)|137.254.60.11|:443... connected.
HTTP request sent, awaiting response... 302 Found
Location: https://repo.mysql.com//mysql57-community-release-el7-10.noarch.rpm [following]
--2019-12-03 23:24:00--  https://repo.mysql.com//mysql57-community-release-el7-10.noarch.rpm
Resolving repo.mysql.com (repo.mysql.com)... 184.29.107.217
Connecting to repo.mysql.com (repo.mysql.com)|184.29.107.217|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 25548 (25K) [application/x-redhat-package-manager]
Saving to: ‘mysql57-community-release-el7-10.noarch.rpm’

100%[================================================================================>] 25,548      21.5KB/s   in 1.2s   

2019-12-03 23:24:03 (21.5 KB/s) - ‘mysql57-community-release-el7-10.noarch.rpm’ saved [25548/25548]

-c: No such file or directory
No URLs found in -c.
FINISHED --2019-12-03 23:24:03--
Total wall clock time: 19s
Downloaded: 1 files, 25K in 1.2s (21.5 KB/s)

[root@node9 ~]# yum -y install mysql57-community-release-el7-10.noarch.rpm 
Loaded plugins: fastestmirror
Examining mysql57-community-release-el7-10.noarch.rpm: mysql57-community-release-el7-10.noarch
Marking mysql57-community-release-el7-10.noarch.rpm to be installed
Resolving Dependencies
--> Running transaction check
---> Package mysql57-community-release.noarch 0:el7-10 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

==========================================================================================================================
 Package                           Arch           Version          Repository                                        Size
==========================================================================================================================
Installing:
 mysql57-community-release         noarch         el7-10           /mysql57-community-release-el7-10.noarch          30 k

Transaction Summary
==========================================================================================================================
Install  1 Package

Total size: 30 k
Installed size: 30 k
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : mysql57-community-release-el7-10.noarch                                                                1/1 
  Verifying  : mysql57-community-release-el7-10.noarch                                                                1/1 

Installed:
  mysql57-community-release.noarch 0:el7-10                                                                               

Complete!

7.2 安裝MySQL-server

#yum安裝MySQL會自動解決依賴,一條命令即可,但是需要網路訪問許可權
[root@node9 ~]# yum -y install mysql-community-server 
.....

Installed:
  mysql-community-libs.x86_64 0:5.7.28-1.el7                mysql-community-libs-compat.x86_64 0:5.7.28-1.el7             
  mysql-community-server.x86_64 0:5.7.28-1.el7             

Dependency Installed:
  mysql-community-client.x86_64 0:5.7.28-1.el7                mysql-community-common.x86_64 0:5.7.28-1.el7               

Replaced:
  mariadb-libs.x86_64 1:5.5.56-2.el7                                                                                      

Complete!

7.3 啟動MySQL,查看MySQL初始化密碼

[root@node9 ~]# systemctl start mysqld
[root@node9 ~]# systemctl status mysqld
● mysqld.service - MySQL Server
   Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
   Active: active (running) since Wed 2019-12-04 10:22:00 CST; 1min 22s ago
     Docs: man:mysqld(8)
           http://dev.mysql.com/doc/refman/en/using-systemd.html
  Process: 15965 ExecStart=/usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid $MYSQLD_OPTS (code=exited, status=0/SUCCESS)
  Process: 15947 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS)
 Main PID: 15968 (mysqld)
   CGroup: /system.slice/mysqld.service
           └─15968 /usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid

Dec 04 10:22:00 node9 mysqld[15965]: 2019-12-04T02:22:00.774472Z 0 [Warning] CA certificate ca.pem is self signed.
Dec 04 10:22:00 node9 mysqld[15965]: 2019-12-04T02:22:00.774677Z 0 [Note] Skipping generation of RSA key pair as ...ctory.
Dec 04 10:22:00 node9 mysqld[15965]: 2019-12-04T02:22:00.774897Z 0 [Note] Server hostname (bind-address): '*'; port: 3306
Dec 04 10:22:00 node9 mysqld[15965]: 2019-12-04T02:22:00.774962Z 0 [Note] IPv6 is available.
Dec 04 10:22:00 node9 mysqld[15965]: 2019-12-04T02:22:00.774980Z 0 [Note]   - '::' resolves to '::';
Dec 04 10:22:00 node9 mysqld[15965]: 2019-12-04T02:22:00.775003Z 0 [Note] Server socket created on IP: '::'.
Dec 04 10:22:00 node9 mysqld[15965]: 2019-12-04T02:22:00.791933Z 0 [Note] Event Scheduler: Loaded 0 events
Dec 04 10:22:00 node9 mysqld[15965]: 2019-12-04T02:22:00.792180Z 0 [Note] /usr/sbin/mysqld: ready for connections.
Dec 04 10:22:00 node9 mysqld[15965]: Version: '5.7.28'  socket: '/var/lib/mysql/mysql.sock'  port: 3306  MySQL Co... (GPL)
Dec 04 10:22:00 node9 systemd[1]: Started MySQL Server.
Hint: Some lines were ellipsized, use -l to show in full.

[root@node9 ~]# grep "password" /var/log/mysqld.log   #查看MySQL初始化密碼
2019-11-05T06:35:28.565529Z 1 [Note] A temporary password is generated for root@localhost: T<&loC3=%t+Q

7.4 修改MySQL的root密碼,並給用戶賦許可權

mysql>ALTER USER 'root'@'localhost' IDENTIFIED BY 'new password';

mysql> SET PASSWORD = PASSWORD('123456');#修改root密碼為123456,如果提示ERROR 1819 (HY000): Your password does not satisfy the current policy requirements,則說明密碼設置太簡單,如果想設置123456這樣的簡單密碼,可在SQL中執行:
	#mysql> set global validate_password_policy=0;
	#mysql> set global validate_password_length=1;
	#這樣再次執行SET PASSWORD = PASSWORD('123456')就可成功。
Query OK, 0 rows affected, 1 warning (0.01 sec)

mysql> UPDATE mysql.user SET authentication_string =PASSWORD('123456') WHERE User='mysql';    #修改MySQL的mysql用戶的密碼為123456
Query OK, 0 rows affected, 1 warning (0.00 sec)
Rows matched: 0  Changed: 0  Warnings: 1

mysql> GRANT ALL PRIVILEGES ON *.* TO mysql@localhost IDENTIFIED BY '123456' WITH GRANT OPTION;   
Query OK, 0 rows affected, 2 warnings (0.00 sec)

mysql> GRANT ALL PRIVILEGES ON *.* TO mysql@"%" IDENTIFIED BY '123456' WITH GRANT OPTION;   #賦予mysql用戶可以在任何機器上登錄,並擁有所有表的所有許可權
Query OK, 0 rows affected, 1 warning (0.00 sec)

mysql> GRANT ALL PRIVILEGES ON *.* TO root@localhost IDENTIFIED BY '123456' WITH GRANT OPTION;
Query OK, 0 rows affected, 2 warnings (0.00 sec)

mysql> GRANT ALL PRIVILEGES ON *.* TO root@"%" IDENTIFIED BY '123456' WITH GRANT OPTION;
Query OK, 0 rows affected, 1 warning (0.07 sec)

mysql> FLUSH PRIVILEGES ;   #刷新許可權,讓修改立即生效
Query OK, 0 rows affected (0.00 sec)

mysql> exit;
Bye

--------------------------------------------------------------------------------------
#以下是為MySQL賦許可權的介紹
mysql> grant 許可權1,許可權2,…許可權n on 資料庫名稱.表名稱 to 用戶名@用戶地址 identified by ‘連介面令’;
許可權1,許可權2,…許可權n代表select,insert,update,delete,create,drop,index,alter,grant,references,reload,shutdown,process,file等14個許可權。
當許可權1,許可權2,…許可權n被all privileges或者all代替,表示賦予用戶全部許可權。
當資料庫名稱.表名稱被*.*代替,表示賦予用戶操作伺服器上所有資料庫所有表的許可權。
用戶地址可以是localhost,也可以是ip地址、機器名字、功能變數名稱。也可以用’%'表示從任何地址連接。
‘連介面令’不能為空,否則創建失敗。
比如:
mysql>grant select,insert,update,delete,create,drop on vtdc.employee to [email protected] identified by ‘123′;
給來自10.163.225.87的用戶joe分配可對資料庫vtdc的employee表進行select,insert,update,delete,create,drop等操作的許可權,並設定口令為123。
 
mysql>grant all privileges on vtdc.* to [email protected] identified by ‘123′;
給來自10.163.225.87的用戶joe分配可對資料庫vtdc所有表進行所有操作的許可權,並設定口令為123。
--------------------------------------------------------------------------------------

7.5 卸載Yum Repository

#由於安裝了Yum Repository,所以每次yum操作都會自動更新,需要把這個卸載掉
[root@node9 ~]# yum -y remove mysql57-community-release-el7-10.noarch
Loaded plugins: fastestmirror
Resolving Dependencies
--> Running transaction check
---> Package mysql57-community-release.noarch 0:el7-10 will be erased
--> Finished Dependency Resolution

Dependencies Resolved

==========================================================================================================================
 Package                                   Arch                   Version                 Repository                 Size
==========================================================================================================================
Removing:
 mysql57-community-release                 noarch                 el7-10                  installed                  30 k

Transaction Summary
==========================================================================================================================
Remove  1 Package

Installed size: 30 k
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Erasing    : mysql57-community-release-el7-10.noarch                                                                1/1 
  Verifying  : mysql57-community-release-el7-10.noarch                                                                1/1 

Removed:
  mysql57-community-release.noarch 0:el7-10                                                                 
Complete!

自此,yum安裝MySQL完畢

八.源碼編譯安裝MySQL

​ 源碼編譯安裝MySQL可以查看我的上一篇博客:https://www.cnblogs.com/renshengdezheli/p/11913248.html,在此不再贅述。

九.參考文獻

https://www.cnblogs.com/luohanguo/p/9045391.html


您的分享是我們最大的動力!

-Advertisement-
Play Games
更多相關文章
  • Ubuntu系統安裝軟體時報以下錯誤: E: Sub-process /usr/bin/dpkg returned an error code (1) 解決: mv /var/lib/dpkg/info /var/lib/dpkg/info_old mkdir /var/lib/dpkg/info ...
  • Win10企業版遠程桌面結合frp實現公網遠程 前言 由於經常下班後還要處理問題,但是又沒有運維那麼頻繁,就不想天天背著電腦來回跑,剛開始用的teamviewer,後來被商業勸退了(就是不讓用了,讓買序列號),剛開始想到的替代品是RealVNC,以前見運維提供winServer伺服器遠程桌面的時候用 ...
  • 0 個人信息 張櫻姿 201821121038 計算1812 1 實驗目的 通過編程進一步瞭解信號量。 2 實驗內容 在伺服器上用Vim編寫一個程式:使用信號量解決任一個經典PV問題,測試給出結果,並對運行結果進行解釋。 3 實驗報告 3.1 選擇哲學家進餐問題 五個哲學家共用一張圓桌,分別坐在周圍 ...
  • 1.關機 (系統的關機、重啟以及登出 ) 的命令 shutdown -h now 關閉系統(1) init 0 關閉系統(2) telinit 0 關閉系統(3) shutdown -h hours:minutes & 按預定時間關閉系統 shutdown -c 取消按預定時間關閉系統 shutdo ...
  • 實驗目的:使用corosync v1 + pacemaker部署httpd高可用服務(+NFS)。本實驗使用Centos 6.8系統,FileSystem資源伺服器,NA1節點1,NA2節點2,VIP192.168.94.222目錄結構:(好煩啊,佈局一塌糊塗)1、corosync v1 + pac... ...
  • 在上一篇文章《Linux的運行級別與目標》中,我介紹過 Linux 用 systemd 來取代 init 作為系統的初始化進程。儘管這一改變引來了很多爭議,但大多數發行版,包括 RedHat、Fedora、CentOS、Debian、Ubuntu、openSUSE、Arch 等等都已經做出了調整。不 ...
  • 什麼是數據完整性? 數據完整性 = 數據準確性 + 數據可靠性 數據完整性如何分類? 1,實體完整性 (行) 2,域完整性 (列) 3,引用完整性 (表與表之間鍵的關係) 4,自定義完整性 如何保證數據的完整性? 必須在建表時分別對資料庫實施完整性約束: 實體完整性約束 (行) 主鍵約束(prima ...
  • Mycat安裝部署簡單使用1. 軟體準備Mycat:下載地址:https://github.com/MyCATApache/Mycat-download。下載界面圖 1‑1 Mycat首頁下載界面。任意選中RELEASE版本,進入RELEASE版本目錄,如下所示圖 1‑2 1.4RELEASE目錄下 ...
一周排行
    -Advertisement-
    Play Games
  • 移動開發(一):使用.NET MAUI開發第一個安卓APP 對於工作多年的C#程式員來說,近來想嘗試開發一款安卓APP,考慮了很久最終選擇使用.NET MAUI這個微軟官方的框架來嘗試體驗開發安卓APP,畢竟是使用Visual Studio開發工具,使用起來也比較的順手,結合微軟官方的教程進行了安卓 ...
  • 前言 QuestPDF 是一個開源 .NET 庫,用於生成 PDF 文檔。使用了C# Fluent API方式可簡化開發、減少錯誤並提高工作效率。利用它可以輕鬆生成 PDF 報告、發票、導出文件等。 項目介紹 QuestPDF 是一個革命性的開源 .NET 庫,它徹底改變了我們生成 PDF 文檔的方 ...
  • 項目地址 項目後端地址: https://github.com/ZyPLJ/ZYTteeHole 項目前端頁面地址: ZyPLJ/TreeHoleVue (github.com) https://github.com/ZyPLJ/TreeHoleVue 目前項目測試訪問地址: http://tree ...
  • 話不多說,直接開乾 一.下載 1.官方鏈接下載: https://www.microsoft.com/zh-cn/sql-server/sql-server-downloads 2.在下載目錄中找到下麵這個小的安裝包 SQL2022-SSEI-Dev.exe,運行開始下載SQL server; 二. ...
  • 前言 隨著物聯網(IoT)技術的迅猛發展,MQTT(消息隊列遙測傳輸)協議憑藉其輕量級和高效性,已成為眾多物聯網應用的首選通信標準。 MQTTnet 作為一個高性能的 .NET 開源庫,為 .NET 平臺上的 MQTT 客戶端與伺服器開發提供了強大的支持。 本文將全面介紹 MQTTnet 的核心功能 ...
  • Serilog支持多種接收器用於日誌存儲,增強器用於添加屬性,LogContext管理動態屬性,支持多種輸出格式包括純文本、JSON及ExpressionTemplate。還提供了自定義格式化選項,適用於不同需求。 ...
  • 目錄簡介獲取 HTML 文檔解析 HTML 文檔測試參考文章 簡介 動態內容網站使用 JavaScript 腳本動態檢索和渲染數據,爬取信息時需要模擬瀏覽器行為,否則獲取到的源碼基本是空的。 本文使用的爬取步驟如下: 使用 Selenium 獲取渲染後的 HTML 文檔 使用 HtmlAgility ...
  • 1.前言 什麼是熱更新 游戲或者軟體更新時,無需重新下載客戶端進行安裝,而是在應用程式啟動的情況下,在內部進行資源或者代碼更新 Unity目前常用熱更新解決方案 HybridCLR,Xlua,ILRuntime等 Unity目前常用資源管理解決方案 AssetBundles,Addressable, ...
  • 本文章主要是在C# ASP.NET Core Web API框架實現向手機發送驗證碼簡訊功能。這裡我選擇是一個互億無線簡訊驗證碼平臺,其實像阿裡雲,騰訊雲上面也可以。 首先我們先去 互億無線 https://www.ihuyi.com/api/sms.html 去註冊一個賬號 註冊完成賬號後,它會送 ...
  • 通過以下方式可以高效,並保證數據同步的可靠性 1.API設計 使用RESTful設計,確保API端點明確,並使用適當的HTTP方法(如POST用於創建,PUT用於更新)。 設計清晰的請求和響應模型,以確保客戶端能夠理解預期格式。 2.數據驗證 在伺服器端進行嚴格的數據驗證,確保接收到的數據符合預期格 ...