首页 > 数据库 >使用ansible自动化安装MySQL8的mysql-router+mysql-shell+mysql架构InnoDB ReplicaSet

使用ansible自动化安装MySQL8的mysql-router+mysql-shell+mysql架构InnoDB ReplicaSet

时间:2024-06-04 11:33:35浏览次数:27  
标签:10 shell xx7 ReplicaSet changed item mysql xx8

【说明】

当前数据库MySQL Community Server 8.4.0 LTS版本已经发行,使用InnoDB ReplicaSet架构自动化搭建

 

【自动化安装】

使用ansible安装mysql-router+mysql-shell+mysql

tree mysql8/
mysql8/
├── mysql_ms.yaml
└── roles
    └── mysql_ms
        ├── tasks
        │   └── main.yml
        ├── templates
        │   ├── auto_mysqlroute_pass.sh
        │   ├── my.cnf
        │   ├── readme.md
        │   ├── replicaset_addinstance.js
        │   ├── replicaset_configure.js
        │   ├── replicaset_create.js
        │   └── replicaset_sleep.sql
        └── vars
            └── main.yml

【剧本说明】

环境变量信息,填写对应的介质及路径
cat main.yml 
---

mysql_tgz: mysql-8.4.0-linux-glibc2.17-x86_64.tar.xz
tgz_extracted: mysql-8.4.0-linux-glibc2.17-x86_64
mysqlsh_tgz: mysql-shell-8.4.0-linux-glibc2.17-x86-64bit.tar.gz
shtgz_extracted: mysql-shell-8.4.0-linux-glibc2.17-x86-64bit
mysql_router: mysql-router-community-8.4.0-1.el7.x86_64.rpm
db_data: /db/mysql
monitor_user: monitor
download_target: /tmp/deployer

 

ansible的hosts配置文件,这里将密码汇总是方便hosts文件加密
[mysql_ms] 10.x.x.xx7 ansible_user=root ansible_ssh_pass=xxxxxxxx cluster_role=master server_id=103306 10.x.x.xx8 ansible_user=root ansible_ssh_pass=xxxxxxxx cluster_role=slave server_id=103307 [mysql_ms:vars] mysql_pass='xxxxxxxx' dbadmin_pass='xxxxxxxx' repl_pass='xxxxxxxx' monitor_pass='xxxxxxxx'

 

主要运行的剧本信息
cat main.yml 
---

- name: create mysql user and group
  user:
    name: mysql
    shell: /sbin/nologin

- name: download installation media
  copy:
    src: "{{download_target}}/{{mysql_tgz}}"
    dest: /tmp/{{mysql_tgz}}

- name: decompress mysql package
  shell: tar -xf /tmp/{{mysql_tgz}} -C /usr/local/

- name: add mysql conf
  template:
    src: my.cnf
    dest: /etc/my.cnf
    owner: mysql
    group: mysql

- name: link mysql
  file:
    src: /usr/local/{{tgz_extracted}}
    dest: /usr/local/mysql
    owner: mysql
    group: mysql
    state: link

- name: create data directory
  file:
    path: '{{db_data}}/{{item}}'
    state: directory
    owner: mysql
    group: mysql
    recurse: yes
  loop:
   - mysql
   - logs
   - relaylog
   - binlog

- name: init mysql
  shell: /usr/local/mysql/bin/mysqld --initialize-insecure --user=mysql --basedir=/usr/local/mysql

- name: copy mysql server script
  copy:
    src: /usr/local/mysql/support-files/mysql.server
    dest: /etc/init.d/mysql
    owner: mysql
    group: mysql
    mode: "0755"

- name: checkconfig mysql
  shell: chkconfig --add mysql

- name: Ensure mysql  is enabled
  systemd:
    daemon_reload: yes
    name: mysql
    enabled: yes

- name: Start mysql
  service: 
    name: mysql
    state: restarted
    enabled: yes

- name: Pause for 5 seconds
  pause:
    seconds: 5

- name: set  mysql root password
  shell: /usr/local/mysql/bin/mysqladmin -uroot password {{mysql_pass}}

- name: add profile for mysql
  lineinfile: dest=/etc/profile line='{{ item.line }}'
  with_items:
  - line: " "
  - line: "### for mysql "
  - line: "export PATH=/usr/local/mysql/bin:$PATH"

- name: download installation mysqlsh media
  copy:
    src: "{{download_target}}/{{mysqlsh_tgz}}"
    dest: /tmp/{{mysqlsh_tgz}}

- name: decompress mysqlsh package
  shell: tar -xf /tmp/{{mysqlsh_tgz}} -C /usr/local/

- name: link mysqlsh
  file:
    src: /usr/local/{{shtgz_extracted}}
    dest: /usr/local/mysqlsh
    owner: mysql
    group: mysql
    state: link

- name: add profile for mysqlsh
  lineinfile: dest=/etc/profile line='{{ item.line }}'
  with_items:
  - line: " "
  - line: "### for mysqlsh "
  - line: "export PATH=/usr/local/mysqlsh/bin:$PATH"

- name: add dbadmin user
  command: /usr/local/mysql/bin/mysql -uroot -p{{mysql_pass}} -e "create user root@'%' identified by '{{mysql_pass}}';GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, RELOAD, SHUTDOWN, PROCESS, FILE, REFERENCES, INDEX, ALTER, SHOW DATABASES, SUPER, CREATE TEMPORARY TABLES, LOCK TABLES, EXECUTE, REPLICATION SLAVE, REPLICATION CLIENT, CREATE VIEW, SHOW VIEW, CREATE ROUTINE, ALTER ROUTINE, CREATE USER, EVENT, TRIGGER, CREATE TABLESPACE, CREATE ROLE, DROP ROLE ON *.* TO `root`@`%` WITH GRANT OPTION;GRANT ALLOW_NONEXISTENT_DEFINER,APPLICATION_PASSWORD_ADMIN,AUDIT_ABORT_EXEMPT,AUDIT_ADMIN,AUTHENTICATION_POLICY_ADMIN,BACKUP_ADMIN,BINLOG_ADMIN,BINLOG_ENCRYPTION_ADMIN,CLONE_ADMIN,CONNECTION_ADMIN,ENCRYPTION_KEY_ADMIN,FIREWALL_EXEMPT,FLUSH_OPTIMIZER_COSTS,FLUSH_STATUS,FLUSH_TABLES,FLUSH_USER_RESOURCES,GROUP_REPLICATION_ADMIN,GROUP_REPLICATION_STREAM,INNODB_REDO_LOG_ARCHIVE,INNODB_REDO_LOG_ENABLE,PASSWORDLESS_USER_ADMIN,PERSIST_RO_VARIABLES_ADMIN,REPLICATION_APPLIER,REPLICATION_SLAVE_ADMIN,RESOURCE_GROUP_ADMIN,RESOURCE_GROUP_USER,ROLE_ADMIN,SENSITIVE_VARIABLES_OBSERVER,SERVICE_CONNECTION_ADMIN,SESSION_VARIABLES_ADMIN,SET_ANY_DEFINER,SHOW_ROUTINE,SYSTEM_USER,SYSTEM_VARIABLES_ADMIN,TABLE_ENCRYPTION_ADMIN,TELEMETRY_LOG_ADMIN,XA_RECOVER_ADMIN ON *.* TO `root`@`%` WITH GRANT OPTION;GRANT PROXY ON ``@`` TO `root`@`%` WITH GRANT OPTION ;"

- name: mysql cluster
  set_fact:
    mysql_cluster_servers_group: []

- name: declare host group
  set_fact:
    mysql_cluster_servers_group: "{{mysql_cluster_servers_group}} + [ '{{ item }}' ]"
  with_items: "{{ groups['mysql_ms'] }}"

- name: copy db replicatset files
  template:
    src: ../templates/{{ item }}
    dest: /tmp/{{ item }}
    mode: 0775
  with_items:
    ['replicaset_configure.js','replicaset_sleep.sql','replicaset_create.js','replicaset_addinstance.js','auto_mysqlroute_pass.sh']

- name: replicaset configure
  shell: /usr/local/mysqlsh/bin/mysqlsh -uroot -p{{mysql_pass}} -S /db/mysql/mysql/mysqld.sock --file=/tmp/replicaset_configure.js
  when: cluster_role == "master"

- name: replicaset sleep
  shell: /usr/local/mysqlsh/bin/mysqlsh -uroot -p{{mysql_pass}} -S /db/mysql/mysql/mysqld.sock --file=/tmp/replicaset_sleep.sql
  when: cluster_role == "master"

- name: replicaset create
  shell: /usr/local/mysqlsh/bin/mysqlsh -uroot -p{{mysql_pass}} -S /db/mysql/mysql/mysqld.sock --file=/tmp/replicaset_create.js
  when: cluster_role == "master"

- name: replicaset sleep
  shell: /usr/local/mysqlsh/bin/mysqlsh -uroot -p{{mysql_pass}} -S /db/mysql/mysql/mysqld.sock --file=/tmp/replicaset_sleep.sql
  when: cluster_role == "master"

- name: replicaset addinstance
  shell: /usr/local/mysqlsh/bin/mysqlsh -uroot -p{{mysql_pass}} -S /db/mysql/mysql/mysqld.sock --file=/tmp/replicaset_addinstance.js
  when: cluster_role == "master"

- name: download installation mysql router media
  copy:
    src: "{{download_target}}/{{mysql_router}}"
    dest: /tmp/{{mysql_router}}

- name: install mysql router  rpm on all node
  yum:
    name: '/tmp/{{ item }}'
    state: present
  with_items:
    - "{{ mysql_router }}"

- name: mysqlrouter add replicaset
  shell: /usr/bin/expect -f /tmp/auto_mysqlroute_pass.sh

- name: ensure mysqlrouter is enabled
  systemd:
    daemon_reload: yes
    name: mysqlrouter
    enabled: yes

- name: start mysqlrouter
  service: 
    name: mysqlrouter
    state: restarted
    enabled: yes

 

使用mysql shell创建集群的步骤,这里有sleep原因是太快执行会导致初始化元数据还没有加载导致异常报错

这里需要注意如果是低版本的话,configureReplicaSetInstance时候需要添加一个password参数,代表传入root密码,8.4.0版本不需要这个参数

cat replicaset_configure.js
dba.configureReplicaSetInstance('root@{{ mysql_cluster_servers_group[0] }}:3306', {clusterAdmin: "'repl'@'%'", clusterAdminPassword: 'Repl_xxxx'});

cat replicaset_sleep.sql
select sleep(10);

cat replicaset_create.js
rs = dba.createReplicaSet("replicaset");

cat replicaset_addinstance.js
var rs =dba.getReplicaSet();
rs.addInstance('{{ mysql_cluster_servers_group[1] }}:3306',{recoveryMethod: "clone"});

  

使用mysql router命令添加集群脚本,因为查看到没有参数直接添加root密码,当前使用expect命令方式自动输入密码,防止交互式中断

cat auto_mysqlroute_pass.sh
#!/usr/bin/expect -f

set timeout 30
spawn  mysqlrouter --bootstrap root@{{ mysql_cluster_servers_group[0] }}:3306 --user=mysqlrouter
expect "Please enter MySQL password for root:"
send {{ mysql_pass }}\n
expect off

 

【脚本运行情况】

ansible-playbook mysql_ms.yaml

PLAY [mysql_ms] ******************************************************************************************************************************************************************************************

TASK [mysql_ms : create mysql user and group] ************************************************************************************************************************************************************
ok: [10.x.x.xx7]
ok: [10.x.x.xx8]

TASK [mysql_ms : download installation media] ************************************************************************************************************************************************************
ok: [10.x.x.xx8]
ok: [10.x.x.xx7]

TASK [mysql_ms : decompress mysql package] ***************************************************************************************************************************************************************
[WARNING]: Consider using the unarchive module rather than running 'tar'.  If you need to use command because unarchive is insufficient you can add 'warn: false' to this command task or set
'command_warnings=False' in ansible.cfg to get rid of this message.
changed: [10.x.x.xx7]
changed: [10.x.x.xx8]

TASK [mysql_ms : add mysql conf] *************************************************************************************************************************************************************************
changed: [10.x.x.xx7]
changed: [10.x.x.xx8]

TASK [mysql_ms : link mysql] *****************************************************************************************************************************************************************************
ok: [10.x.x.xx7]
ok: [10.x.x.xx8]

TASK [mysql_ms : create data directory] ******************************************************************************************************************************************************************
changed: [10.x.x.xx8] => (item=mysql)
changed: [10.x.x.xx8] => (item=logs)
changed: [10.x.x.xx8] => (item=relaylog)
changed: [10.x.x.xx8] => (item=binlog)
changed: [10.x.x.xx7] => (item=mysql)
changed: [10.x.x.xx7] => (item=logs)
changed: [10.x.x.xx7] => (item=relaylog)
changed: [10.x.x.xx7] => (item=binlog)

TASK [mysql_ms : init mysql] *****************************************************************************************************************************************************************************
changed: [10.x.x.xx7]
changed: [10.x.x.xx8]

TASK [mysql_ms : copy mysql server script] ***************************************************************************************************************************************************************
changed: [10.x.x.xx7]
changed: [10.x.x.xx8]

TASK [mysql_ms : checkconfig mysql] **********************************************************************************************************************************************************************
changed: [10.x.x.xx8]
changed: [10.x.x.xx7]

TASK [mysql_ms : Ensure mysql  is enabled] ***************************************************************************************************************************************************************
ok: [10.x.x.xx8]
ok: [10.x.x.xx7]

TASK [mysql_ms : Start mysql] ****************************************************************************************************************************************************************************
changed: [10.x.x.xx7]
changed: [10.x.x.xx8]

TASK [mysql_ms : Pause for 5 seconds] ********************************************************************************************************************************************************************
Pausing for 5 seconds
(ctrl+C then 'C' = continue early, ctrl+C then 'A' = abort)
ok: [10.x.x.xx7]

TASK [mysql_ms : set  mysql root password] ***************************************************************************************************************************************************************
changed: [10.x.x.xx8]
changed: [10.x.x.xx7]

TASK [mysql_ms : add profile for mysql] ******************************************************************************************************************************************************************
ok: [10.x.x.xx8] => (item={u'line': u' '})
ok: [10.x.x.xx8] => (item={u'line': u'### for mysql '})
ok: [10.x.x.xx8] => (item={u'line': u'export PATH=/usr/local/mysql/bin:$PATH'})
ok: [10.x.x.xx7] => (item={u'line': u' '})
ok: [10.x.x.xx7] => (item={u'line': u'### for mysql '})
ok: [10.x.x.xx7] => (item={u'line': u'export PATH=/usr/local/mysql/bin:$PATH'})

TASK [mysql_ms : download installation mysqlsh media] ****************************************************************************************************************************************************
ok: [10.x.x.xx7]
ok: [10.x.x.xx8]

TASK [mysql_ms : decompress mysqlsh package] *************************************************************************************************************************************************************
changed: [10.x.x.xx7]
changed: [10.x.x.xx8]

TASK [mysql_ms : link mysqlsh] ***************************************************************************************************************************************************************************
changed: [10.x.x.xx8]
changed: [10.x.x.xx7]

TASK [mysql_ms : add profile for mysqlsh] ****************************************************************************************************************************************************************
ok: [10.x.x.xx8] => (item={u'line': u' '})
ok: [10.x.x.xx7] => (item={u'line': u' '})
ok: [10.x.x.xx8] => (item={u'line': u'### for mysqlsh '})
ok: [10.x.x.xx7] => (item={u'line': u'### for mysqlsh '})
ok: [10.x.x.xx8] => (item={u'line': u'export PATH=/usr/local/mysqlsh/bin:$PATH'})
ok: [10.x.x.xx7] => (item={u'line': u'export PATH=/usr/local/mysqlsh/bin:$PATH'})

TASK [mysql_ms : add dbadmin user] ***********************************************************************************************************************************************************************
changed: [10.x.x.xx7]
changed: [10.x.x.xx8]

TASK [mysql_ms : mysql cluster] **************************************************************************************************************************************************************************
ok: [10.x.x.xx7]
ok: [10.x.x.xx8]

TASK [mysql_ms : declare host group] *********************************************************************************************************************************************************************
ok: [10.x.x.xx7] => (item=10.x.x.xx7)
ok: [10.x.x.xx7] => (item=10.x.x.xx8)
ok: [10.x.x.xx8] => (item=10.x.x.xx7)
ok: [10.x.x.xx8] => (item=10.x.x.xx8)

TASK [mysql_ms : copy db replicatset files] **************************************************************************************************************************************************************
changed: [10.x.x.xx8] => (item=replicaset_configure.js)
ok: [10.x.x.xx7] => (item=replicaset_configure.js)
changed: [10.x.x.xx8] => (item=replicaset_sleep.sql)
ok: [10.x.x.xx7] => (item=replicaset_sleep.sql)
changed: [10.x.x.xx8] => (item=replicaset_create.js)
ok: [10.x.x.xx7] => (item=replicaset_create.js)
ok: [10.x.x.xx7] => (item=replicaset_addinstance.js)
ok: [10.x.x.xx7] => (item=auto_mysqlroute_pass.sh)
changed: [10.x.x.xx8] => (item=replicaset_addinstance.js)
changed: [10.x.x.xx8] => (item=auto_mysqlroute_pass.sh)

TASK [mysql_ms : replicaset configure] *******************************************************************************************************************************************************************
skipping: [10.x.x.xx8]
changed: [10.x.x.xx7]

TASK [mysql_ms : replicaset sleep] ***********************************************************************************************************************************************************************
skipping: [10.x.x.xx8]
changed: [10.x.x.xx7]

TASK [mysql_ms : replicaset create] **********************************************************************************************************************************************************************
skipping: [10.x.x.xx8]
changed: [10.x.x.xx7]

TASK [mysql_ms : replicaset sleep] ***********************************************************************************************************************************************************************
skipping: [10.x.x.xx8]
changed: [10.x.x.xx7]

TASK [mysql_ms : replicaset addinstance] *****************************************************************************************************************************************************************
skipping: [10.x.x.xx8]
changed: [10.x.x.xx7]

TASK [mysql_ms : download installation mysql router media] ***********************************************************************************************************************************************
ok: [10.x.x.xx8]
ok: [10.x.x.xx7]

TASK [mysql_ms : download installation mysql router media] ***********************************************************************************************************************************************
ok: [10.x.x.xx8]
ok: [10.x.x.xx7]

TASK [mysql_ms : install mysql router  rpm on all node] **************************************************************************************************************************************************
changed: [10.x.x.xx8] => (item=[u'/tmp/mysql-router-community-8.4.0-1.el7.x86_64.rpm'])
changed: [10.x.x.xx7] => (item=[u'/tmp/mysql-router-community-8.4.0-1.el7.x86_64.rpm'])

TASK [mysql_ms : mysqlrouter add replicaset] *************************************************************************************************************************************************************
changed: [10.x.x.xx8]
changed: [10.x.x.xx7]

TASK [mysql_ms : ensure mysqlrouter is enabled] **********************************************************************************************************************************************************
changed: [10.x.x.xx8]
changed: [10.x.x.xx7]

TASK [mysql_ms : start mysqlrouter] **********************************************************************************************************************************************************************
changed: [10.x.x.xx7]
changed: [10.x.x.xx8]

PLAY RECAP ***********************************************************************************************************************************************************************************************
10.x.x.xx7                 : ok=32   changed=20   unreachable=0    failed=0    skipped=0    rescued=0    ignored=0   
10.x.x.xx8                 : ok=26   changed=16   unreachable=0    failed=0    skipped=5    rescued=0    ignored=0   

 

【查看状态】

 MySQL  localhost  JS > var rs=dba.getReplicaSet();
You are connected to a member of replicaset 'replicaset'.
 MySQL  localhost  JS > 
 MySQL  localhost  JS > rs.status()
{
    "replicaSet": {
        "name": "replicaset", 
        "primary": "xxx01:3306", 
        "status": "AVAILABLE", 
        "statusText": "All instances available.", 
        "topology": {
            "rac01:3306": {
                "address": "xxx01:3306", 
                "instanceRole": "PRIMARY", 
                "mode": "R/W", 
                "status": "ONLINE"
            }, 
            "rac02:3306": {
                "address": "xxx02:3306", 
                "instanceRole": "SECONDARY", 
                "mode": "R/O", 
                "replication": {
                    "applierStatus": "APPLIED_ALL", 
                    "applierThreadState": "Waiting for an event from Coordinator", 
                    "applierWorkerThreads": 6, 
                    "receiverStatus": "ON", 
                    "receiverThreadState": "Waiting for source to send event", 
                    "replicationLag": null, 
                    "replicationSsl": "TLS_AES_128_GCM_SHA256 TLSv1.3", 
                    "replicationSslMode": "REQUIRED"
                }, 
                "status": "ONLINE"
            }
        }, 
        "type": "ASYNC"
    }
}
 MySQL  localhost  JS >

 

【测试同步】

 MySQL  localhost  JS > \sql
Switching to SQL mode... Commands end with ;
 MySQL  localhost  SQL > create database sbtest;
Query OK, 1 row affected (0.0071 sec)
 MySQL  localhost  SQL > use sbtest;
Default schema set to `sbtest`.
Fetching global names, object names from `sbtest` for auto-completion... Press ^C to stop.
 MySQL  localhost  sbtest  SQL > create table sbtest(id int primary key,v_name varchar(20));
Query OK, 0 rows affected (0.0486 sec)
 MySQL  localhost  sbtest  SQL > insert into sbtest values(1,'sbtest1');
Query OK, 1 row affected (0.0064 sec)
 MySQL  localhost  sbtest  SQL > select * from sbtest.sbtest;
+----+---------+
| id | v_name  |
+----+---------+
|  1 | sbtest1 |
+----+---------+
1 row in set (0.0008 sec)

 

【测试读写分离】

## MySQL Classic protocol

- Read/Write Connections: localhost:6446
- Read/Only Connections:  localhost:6447
- Read/Write Split Connections: localhost:6450

写测试
mysql -uroot -ptBuiA54MMz -hx.x.x.xxx -P6447 -e 'select @@hostname,@@port'
读测试
mysql -uroot -ptBuiA54MMz -hx.x.x.xxx -P6446 -e "START TRANSACTION; SELECT @@hostname,@@port; ROLLBACK;"


自动读写分离测试
mysql -uroot -ptBuiA54MMz -hx.x.x.xxx -P6450 -e 'select @@hostname,@@port'
mysql -uroot -ptBuiA54MMz -hx.x.x.xxx -P6450 -e "START TRANSACTION; SELECT @@hostname,@@port; ROLLBACK;"

标签:10,shell,xx7,ReplicaSet,changed,item,mysql,xx8
From: https://www.cnblogs.com/zetanchen/p/18230454

相关文章

  • MySql 使用 NOT IN 返回值包含null值,返回数据不全
      mysqlnotin()找不到nullstatusnin('100','200','300','500')换成statusin('400')isnottrue      来源:https://blog.csdn.net/qq_35387940/article/details/127959272?spm=1001.2101.3001.6650.17&......
  • 记一次“有手就行”的从SQL注入到文件上传Getshell的简单过程
    0x01前台SQL注入漏洞原理SQL注入漏洞的原理是应用程序没有对用户输入进行充分的验证和过滤,导致攻击者可以在输入框中插入恶意的SQL代码。当应用程序将用户输入的数据拼接到SQL查询语句中时,攻击者插入的恶意代码也会被执行,从而绕过身份验证和访问控制,直接访问或修改数据库......
  • Linux下使用mysql
    安装源码安装和yum安装。可以看教程:菜鸟教程:mysql安装使用日常操作命令启停服务1.查看进程状态ps-ef|grepmysql2.mysql服务启停sudosystemctlstartmysql#启动sudosystemctlstopmysql#关闭sudosystemctlrestartmysql#重启sudosystemctlstatusmysql......
  • 如何理解mysql小表驱动大表
    就像自行车爬坡一样么,小齿轮驱动大齿轮MySQL采用“小表驱动大表”的策略,确实在某种程度上类似于自行车爬坡时小齿轮驱动大齿轮的原理,目的都是为了更高效地利用有限的资源达到目标。在数据库查询的上下文中,这个策略背后的逻辑可以这样理解:1.**效率最大化**:小表数据量少,遍历小......
  • 虚拟机CentOS8无法连接外网以及Xshell无法连接虚拟机
    自己调试时出现的问题,记录一下目录1.Linux虚拟机连接不上网络1.1问题内容 1.2解决方法1.2.1VMWare配置1.2.2虚拟机设置1.2.3虚拟机系统文件配置2.Xshell连接不上虚拟机2.1问题内容2.2解决方法2.2.1防火墙设置2.2.2网络连接设置1.Linux虚拟机连接不上......
  • 成为MySQL DBA后,再看ORACLE数据库(六、逻辑存储结构)
    数据库的逻辑存储结构也可以叫做存储层次体系,ORACLE的存储层次体系按照层次从高到低分为:表空间(tablespace)、段(segment)、区(extent)、块(block)。熟悉数据库的逻辑存储结构可以帮助我们分析与定位数据库的空间容量问题。一、段段是表空间的主要组织结构。段就是占用存储空间的数据库......
  • MySQL——事务补充
    十一、RR和RC的本质区别select*from表名(lockinsharemode)#当不加共享锁时,说明此时进行的是快照读,加了共享锁则进行的是当前读;​当进行快照读的时候才会形成readview结构;​readview形成的时机不同,会影响事务的可见性,会造成RR和RC级别下事务可见性的不同;当RR......
  • 基于SSM+Jsp+Mysql的高校二手交易平台
    开发语言:Java框架:ssm技术:JSPJDK版本:JDK1.8服务器:tomcat7数据库:mysql5.7(一定要5.7版本)数据库工具:Navicat11开发软件:eclipse/myeclipse/ideaMaven包:Maven3.3.9系统展示前台首页用户注册用户登录个人中心商品信息管理员登录商品上架管理商品信息管理客服聊天管......
  • 【MySQL】MySQL Connect -- 详解
    一、Connector /C使用要使用 C 语言连接MySQL,需要使用MySQL 官网提供的库,可以去官网进行下载:MySQL::MySQLCommunityDownloads我们使用 C 接口库来进行连接,要正确使用,还需要做一些准备工作:保证 MySQL 服务有效。在官网上下载合适自己平台的 MySQLConnec......
  • 持续性学习-Day17(MySQL)
    1、初识MySQLJavaEE:企业级Java开发Web前段(页面展示,数据)后端(连接点:连接数据库JDBC;链接前端:控制,控制反转,给前台传数据)数据库(存数据)1.1数据库分类关系型数据库(SQL):MySQL、Oracle、SqlServer、DB2、SQLlite通过表和表、行和列之间的关系进行数据的存储非关系型数......