Keepalived MySQL master-master配置高可用

本文涉及的产品
云数据库 RDS MySQL,集群系列 2核4GB
推荐场景:
搭建个人博客
RDS MySQL Serverless 基础系列,0.5-2RCU 50GB
应用型负载均衡 ALB,每月750个小时 15LCU
简介:

一、软件需求:

1.环境描述

操 作 系 统: CentOS 6.5 X64

MySQL数据库: MySQL 5.1.71.1

keepalived角色划分:

MASTER:10.8.1.11

BACKUP:10.8.1.12

VIP:10.8.1.13

2.系统包安装

1)gcc\keepalived相关

yum install -y pcre-devel openssl-devel popt-devel

2)MySQL相关

yum install -y mysql-server mysql


二、配置MySQL数据库Dual-Master

  1. MySQL服务器配置

同一时刻只有一台keepalived角色MASTER STATE的MySQL数据库主机提供读写服务。

1)mdb01

[root@mdb01 ~]# more /etc/my.cnf 

[mysqld]

server-id = 1

log-bin = mysql-bin

binlog-ignore-db = mysql,information_schema

auto-increment-increment = 2

auto-increment-offset = 1

slave-skip-errors = all

datadir=/var/lib/mysql

socket=/var/lib/mysql/mysql.sock

user=mysql

# Disabling symbolic-links is recommended to prevent assorted security risks

symbolic-links=0


[mysqld_safe]

log-error=/var/log/mysqld.log

pid-file=/var/run/mysqld/mysqld.pid

[root@mdb01 ~]#


2)mdb02

[root@mdb02 ~]# more /etc/my.cnf 

[mysqld]

server-id = 2

log-bin = mysql-bin

binlog-ignore-db = mysql,information_schema

auto-increment-increment = 2

auto-increment-offset = 1

slave-skip-errors = all

datadir=/var/lib/mysql

socket=/var/lib/mysql/mysql.sock

user=mysql

# Disabling symbolic-links is recommended to prevent assorted security risks

symbolic-links=0


[mysqld_safe]

log-error=/var/log/mysqld.log

pid-file=/var/run/mysqld/mysqld.pid

[root@mdb02 ~]# 


2.复制配置

1)复制用户设置

GRANT REPLICATION SLAVE ON *.* TO 'replication'@'10.8.1.%' IDENTIFIED BY 'replication';

flush privileges;

2)配置复制点

change  master to

master_host='10.8.1.12',(Master IP)

master_user='replication',

master_password='replication',

master_log_file='mysql-bin.000001',(Master binlog)

master_log_pos=106; (Master binlog position)

3)启动复制进程

start  slave;  

4)查看复制状态

mysql> show slave status\G;

 ....

 ....

 Slave_IO_Running: Yes

 Slave_SQL_Running: Yes

 ....

 ....


5)验证配置

在两个数据库端分别建立数据库、表,插入记录,如果在两边客户端均可见即成功。

三、安装配置keepalived

1.安装keepalived

[root@mdb01 keepalived-1.2.7]# tar zxvf keepalived-1.2.7.tar.gz

[root@mdb01 keepalived-1.2.7]# cd keepalived-1.2.7

[root@mdb01 keepalived-1.2.7]# ./configure --prefix=/usr/local/keepalived

 ....

 ....

Keepalived configuration

------------------------

Keepalived version       : 1.2.7

Compiler                 : gcc

Compiler flags           : -g -O2

Extra Lib                : -lpopt -lssl -lcrypto 

Use IPVS Framework       : Yes

IPVS sync daemon support : Yes

IPVS use libnl           : No

Use VRRP Framework       : Yes

Use VRRP VMAC            : Yes

SNMP support             : No

Use Debug flags          : No

[root@mdb01 keepalived-1.2.7]#

[root@mdb01 keepalived-1.2.7]# make 

[root@mdb01 keepalived-1.2.7]# make install


2.复制相关文件

# cp /usr/local/keepalived/etc/rc.d/init.d/keepalived /etc/init.d/

# cp /usr/local/keepalived/etc/sysconfig/keepalived /etc/sysconfig/

# mkdir /etc/keepalived/

# cp /usr/local/keepalived/etc/keepalived/keepalived.conf /etc/keepalived/

# cp /usr/local/keepalived/sbin/keepalived /usr/sbin/


3.设置启动项

启动优先级:启动MySQL之后启动keepalived


4.keepalived配置文件

1)mdb01

[root@mdb01 ~]# more /etc/keepalived/keepalived.conf 

! Configuration File forkeepalived

global_defs {

notification_email {

test@sina.com

 }

notification_email_from  admin@test.com

smtp_server 127.0.0.1

smtp_connect_timeout 30

router_id MYSQL_HA      

}

vrrp_instance VI_1 {

 state BACKUP          

 interface eth0

 virtual_router_id 51      

 priority 100         

 advert_int 1

 nopreempt  

 authentication {

 auth_type PASS

 auth_pass 1111

 }

 virtual_ipaddress {

 10.8.1.13

 }

}

virtual_server 10.8.1.13 3306 {

 delay_loop 2

 #lb_algo rr              

 #lb_kind DR              

 persistence_timeout 50  

 protocol TCP

 real_server 10.8.1.11 3306 {   

 weight 3

 notify_down /usr/local/keepalived/mysql.sh    

 TCP_CHECK {

 connect_timeout 3    

 nb_get_retry 3       

 delay_before_retry 3 

  }

 }

}

[root@mdb01 ~]# 


2)mdb02

[root@mdb02 ~]# more /etc/keepalived/keepalived.conf 

! Configuration File forkeepalived

global_defs {

notification_email {

test@sina.com

 }

notification_email_from  admin@test.com

smtp_server 127.0.0.1

smtp_connect_timeout 30

router_id MYSQL_HA      

}

vrrp_instance VI_1 {

 state BACKUP          

 interface eth0

 virtual_router_id 51      

 priority 90         

 advert_int 1 

 authentication {

 auth_type PASS

 auth_pass 1111

 }

 virtual_ipaddress {

 10.8.1.13

 }

}

virtual_server 10.8.1.13 3306 {

 delay_loop 2

 #lb_algo rr              

 #lb_kind DR              

 persistence_timeout 50  

 protocol TCP

 real_server 10.8.1.12 3306 {   

 weight 3

 notify_down /usr/local/keepalived/mysql.sh    

 TCP_CHECK {

 connect_timeout 3    

 nb_get_retry 3       

 delay_before_retry 3 

  }

 }

}

[root@mdb02 ~]# 


5.相关切换脚本

当检测到MySQL进程端口不存在时执行以下脚本mysql.sh,

停止本机keepalived进程及移除VIP,备机状态由Backup转换 

Master State同时获取VIP。

[root@mdb01 ~]# more /usr/local/keepalived/mysql.sh 

#!/bin/bash

#pkill keepalived(此行可能会出现VIP漂移过程中两台都有VIP的现象,杀进程不彻底)

/etc/init.d/keepalived stop

[root@mdb01 ~]# 


6.启动keepalived

查看VIP绑定情况


四.切换测试

1.停止master state主机MySQL数据库

[root@mdb02 ~]# /etc/init.d/mysqld stop

Stopping mysqld:  [  OK  ]


2.mdb02移除VIP和停止keepalived进程

1)mdb02移除 protocol VIPs.

注意命令行输出中已无VIP显示

[root@mdb02 ~]# ip addr

1: lo: <LOOPBACK,UP,LOWER_UP> mtu 16436 qdisc noqueue state UNKNOWN 

    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00

    inet 127.0.0.1/8 scope host lo

    inet6 ::1/128 scope host 

       valid_lft forever preferred_lft forever

2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000

    link/ether 00:0c:29:ec:6e:29 brd ff:ff:ff:ff:ff:ff

    inet 10.8.1.12/16 brd 10.8.255.255 scope global eth0

    inet6 fe80::20c:29ff:feec:6e29/64 scope link 

       valid_lft forever preferred_lft forever

[root@mdb02 ~]# 


Keepalived日志输出:

[root@mdb02 ~]# tail -f /var/log/messages 

Dec  1 22:01:05 mdb02 Keepalived_healthcheckers[1121]: TCP connection to [10.8.1.12]:3306 failed !!!

Dec  1 22:01:05 mdb02 Keepalived_healthcheckers[1121]: Removing service [10.8.1.12]:3306 from VS [10.8.1.13]:3306

Dec  1 22:01:05 mdb02 Keepalived_healthcheckers[1121]: IPVS: Service not defined

Dec  1 22:01:05 mdb02 Keepalived_healthcheckers[1121]: Executing [/usr/local/keepalived/mysql.sh] for service [10.8.1.12]:3306 in VS [10.8.1.13]:3306

Dec  1 22:01:05 mdb02 Keepalived_healthcheckers[1121]: Lost quorum 1-0=1 > 0 for VS [10.8.1.13]:3306

Dec  1 22:01:05 mdb02 Keepalived_healthcheckers[1121]: Remote SMTP server [127.0.0.1]:25 connected.

Dec  1 22:01:05 mdb02 Keepalived[1118]: Stopping Keepalived v1.2.7 (12/01,2015)

Dec  1 22:01:05 mdb02 Keepalived_healthcheckers[1121]: IPVS: No such service

Dec  1 22:01:05 mdb02 Keepalived_vrrp[1122]: VRRP_Instance(VI_1) sending 0 priority

Dec  1 22:01:05 mdb02 Keepalived_vrrp[1122]: VRRP_Instance(VI_1) removing protocol VIPs.


2)keepalived进程消失

[root@mdb02 ~]# /etc/init.d/keepalived status

keepalived is stopped


3.mdb01 绑定VIP

[root@mdb01 ~]# ip addr

1: lo: <LOOPBACK,UP,LOWER_UP> mtu 16436 qdisc noqueue state UNKNOWN 

    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00

    inet 127.0.0.1/8 scope host lo

    inet6 ::1/128 scope host 

       valid_lft forever preferred_lft forever

2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000

    link/ether 00:0c:29:02:3a:68 brd ff:ff:ff:ff:ff:ff

    inet 10.8.1.11/16 brd 10.8.255.255 scope global eth0

    inet 10.8.1.13/32 scope global eth0

    inet6 fe80::20c:29ff:fe02:3a68/64 scope link 

       valid_lft forever preferred_lft forever


4.mdb01转换为MASTER STATE

[root@mdb01 ~]# tail -f /var/log/messages 


Dec  1 22:06:34 mdb01 Keepalived_vrrp[1137]: VRRP_Instance(VI_1) Transition to MASTER STATE

Dec  1 22:06:35 mdb01 Keepalived_vrrp[1137]: VRRP_Instance(VI_1) Entering MASTER STATE

Dec  1 22:06:35 mdb01 Keepalived_vrrp[1137]: VRRP_Instance(VI_1) setting protocol VIPs.

Dec  1 22:06:35 mdb01 Keepalived_vrrp[1137]: VRRP_Instance(VI_1) Sending gratuitous ARPs on eth0 for 10.8.1.13

Dec  1 22:06:35 mdb01 Keepalived_healthcheckers[1136]: Netlink reflector reports IP 10.8.1.13 added

Dec  1 22:06:40 mdb01 Keepalived_vrrp[1137]: VRRP_Instance(VI_1) Sending gratuitous ARPs on eth0 for 10.8.1.13


5.mdb02启动MySQL和Keepalived

MySQL和Keepalived服务均启动后,主机转换为BACKUP STATE

[root@mdb02 ~]# tail -f /var/log/messages

Dec  1 22:10:54 mdb02 Keepalived[2484]: Starting Keepalived v1.2.7 (12/01,2015)

Dec  1 22:10:54 mdb02 Keepalived[2485]: Starting Healthcheck child process, pid=2487

Dec  1 22:10:54 mdb02 Keepalived[2485]: Starting VRRP child process, pid=2488

Dec  1 22:10:54 mdb02 Keepalived_vrrp[2488]: Interface queue is empty

Dec  1 22:10:54 mdb02 Keepalived_vrrp[2488]: Netlink reflector reports IP 10.8.1.12 added

Dec  1 22:10:54 mdb02 Keepalived_vrrp[2488]: Netlink reflector reports IP fe80::20c:29ff:feec:6e29 added

Dec  1 22:10:54 mdb02 Keepalived_vrrp[2488]: Registering Kernel netlink reflector

Dec  1 22:10:54 mdb02 Keepalived_vrrp[2488]: Registering Kernel netlink command channel

Dec  1 22:10:54 mdb02 Keepalived_vrrp[2488]: Registering gratuitous ARP shared channel

Dec  1 22:10:54 mdb02 Keepalived_vrrp[2488]: Opening file '/etc/keepalived/keepalived.conf'.

Dec  1 22:10:54 mdb02 Keepalived_healthcheckers[2487]: Interface queue is empty

Dec  1 22:10:54 mdb02 Keepalived_healthcheckers[2487]: Netlink reflector reports IP 10.8.1.12 added

Dec  1 22:10:54 mdb02 Keepalived_healthcheckers[2487]: Netlink reflector reports IP fe80::20c:29ff:feec:6e29 added

Dec  1 22:10:54 mdb02 Keepalived_healthcheckers[2487]: Registering Kernel netlink reflector

Dec  1 22:10:54 mdb02 Keepalived_healthcheckers[2487]: Registering Kernel netlink command channel

Dec  1 22:10:54 mdb02 Keepalived_healthcheckers[2487]: Opening file '/etc/keepalived/keepalived.conf'.

Dec  1 22:10:54 mdb02 Keepalived_vrrp[2488]: Configuration is using : 62808 Bytes

Dec  1 22:10:54 mdb02 Keepalived_vrrp[2488]: Using LinkWatch kernel netlink reflector...

Dec  1 22:10:54 mdb02 Keepalived_healthcheckers[2487]: Configuration is using : 11379 Bytes

Dec  1 22:10:54 mdb02 Keepalived_vrrp[2488]: VRRP_Instance(VI_1) Entering BACKUP STATE

Dec  1 22:10:54 mdb02 Keepalived_vrrp[2488]: VRRP sockpool: [ifindex(2), proto(112), fd(11,12)]

Dec  1 22:10:54 mdb02 Keepalived_healthcheckers[2487]: IPVS: Scheduler not found

Dec  1 22:10:54 mdb02 Keepalived_healthcheckers[2487]: IPVS: No such process

Dec  1 22:10:54 mdb02 Keepalived_healthcheckers[2487]: Using LinkWatch kernel netlink reflector...

Dec  1 22:10:54 mdb02 Keepalived_healthcheckers[2487]: Activating healthchecker for service [10.8.1.12]:3306

Dec  1 22:10:54 mdb02 kernel: IPVS: Scheduler module ip_vs_ not found

Dec  1 22:10:55 mdb02 Keepalived_healthcheckers[2487]: TCP connection to [10.8.1.12]:3306 failed !!!

Dec  1 22:10:55 mdb02 Keepalived_healthcheckers[2487]: Removing service [10.8.1.12]:3306 from VS [10.8.1.13]:3306

Dec  1 22:10:55 mdb02 Keepalived_healthcheckers[2487]: IPVS: Service not defined

Dec  1 22:10:55 mdb02 Keepalived_healthcheckers[2487]: Executing [/usr/local/keepalived/mysql.sh] for service [10.8.1.12]:3306 in VS [10.8.1.13]:3306

Dec  1 22:10:55 mdb02 Keepalived_healthcheckers[2487]: Lost quorum 1-0=1 > 0 for VS [10.8.1.13]:3306

Dec  1 22:10:55 mdb02 Keepalived_healthcheckers[2487]: Remote SMTP server [127.0.0.1]:25 connected.

Dec  1 22:10:55 mdb02 Keepalived[2485]: Stopping Keepalived v1.2.7 (12/01,2015)

Dec  1 22:10:55 mdb02 Keepalived_healthcheckers[2487]: IPVS: No such service


VIP不做漂移

[root@mdb02 ~]# ip addr

1: lo: <LOOPBACK,UP,LOWER_UP> mtu 16436 qdisc noqueue state UNKNOWN 

    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00

    inet 127.0.0.1/8 scope host lo

    inet6 ::1/128 scope host 

       valid_lft forever preferred_lft forever

2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000

    link/ether 00:0c:29:ec:6e:29 brd ff:ff:ff:ff:ff:ff

    inet 10.8.1.12/16 brd 10.8.255.255 scope global eth0

    inet6 fe80::20c:29ff:feec:6e29/64 scope link 

       valid_lft forever preferred_lft forever

[root@mdb02 ~]# 


五、总结:

正常情况下两台Master机器的MySQL及Keepalived均为启动状态:

1.当角色为MASTER STATE的MySQL数据库主机3306端口无法连接时即发生切换

1)停止keepalived进程。

2)移除VIP,

3)主机为故障状态,需要人工修复。

2.BACKUP STATE状态主机切换过程:

1).转变角色为MASTER STATE。

向224.0.0.18发送VRRP心跳信息。

[root@mdb02 ~]# tcpdump vrrp

tcpdump: verbose output suppressed, use -v or -vv for full protocol decode

listening on eth0, link-type EN10MB (Ethernet), capture size 65535 bytes

22:24:42.550593 IP mdb02 > 224.0.0.18: VRRPv2, Advertisement, vrid 51, prio 90, authtype simple, intvl 1s, length 20

22:24:43.563523 IP mdb02 > 224.0.0.18: VRRPv2, Advertisement, vrid 51, prio 90, authtype simple, intvl 1s, length 20

22:24:44.565224 IP mdb02 > 224.0.0.18: VRRPv2, Advertisement, vrid 51, prio 90, authtype simple, intvl 1s, length 20

22:24:45.567882 IP mdb02 > 224.0.0.18: VRRPv2, Advertisement, vrid 51, prio 90, authtype simple, intvl 1s, length 20

22:24:46.570211 IP mdb02 > 224.0.0.18: VRRPv2, Advertisement, vrid 51, prio 90, authtype simple, intvl 1s, length 20

22:24:47.572696 IP mdb02 > 224.0.0.18: VRRPv2, Advertisement, vrid 51, prio 90, authtype simple, intvl 1s, length 20

22:24:48.575324 IP mdb02 > 224.0.0.18: VRRPv2, Advertisement, vrid 51, prio 90, authtype simple, intvl 1s, length 20

22:24:49.578470 IP mdb02 > 224.0.0.18: VRRPv2, Advertisement, vrid 51, prio 90, authtype simple, intvl 1s, length 20

22:24:50.580935 IP mdb02 > 224.0.0.18: VRRPv2, Advertisement, vrid 51, prio 90, authtype simple, intvl 1s, length 20

2).绑定VIP,对外提供读写服务。

3.正常情况下,步骤1的故障主机修复后需要继续对外服务,启动需按照如下顺序:

1)启动MySQL数据库。

2)启动keepalived进程。

3)角色为BACKUP STATE。

4)接收vrrp心跳信息。

root@mdb01 ~]# tcpdump vrrp

tcpdump: verbose output suppressed, use -v or -vv for full protocol decode

listening on eth0, link-type EN10MB (Ethernet), capture size 65535 bytes

22:29:35.056846 IP 10.8.1.12 > 224.0.0.18: VRRPv2, Advertisement, vrid 51, prio 90, authtype simple, intvl 1s, length 20

22:29:36.058852 IP 10.8.1.12 > 224.0.0.18: VRRPv2, Advertisement, vrid 51, prio 90, authtype simple, intvl 1s, length 20

22:29:37.061641 IP 10.8.1.12 > 224.0.0.18: VRRPv2, Advertisement, vrid 51, prio 90, authtype simple, intvl 1s, length 20

5)不对外提供读写服务。

注意事项:

1.当两台服务器MySQL及Keepalived均为启动状态时,当发送故障切换,

VIP在故障机与备份机漂移需要适当时间间隔,一般10-20秒左右。

2.授权两台Mysql服务器允许root远程登录,用于在其他服务器登陆测试!

mysql> grant all on *.* to'root'@'10.8.1.%' identified by '123456';

mysql> flush privileges;


本文转自 pgmia 51CTO博客,原文链接:http://blog.51cto.com/heyiyi/1718363


相关实践学习
如何快速连接云数据库RDS MySQL
本场景介绍如何通过阿里云数据管理服务DMS快速连接云数据库RDS MySQL,然后进行数据表的CRUD操作。
全面了解阿里云能为你做什么
阿里云在全球各地部署高效节能的绿色数据中心,利用清洁计算为万物互联的新世界提供源源不断的能源动力,目前开服的区域包括中国(华北、华东、华南、香港)、新加坡、美国(美东、美西)、欧洲、中东、澳大利亚、日本。目前阿里云的产品涵盖弹性计算、数据库、存储与CDN、分析与搜索、云通信、网络、管理与监控、应用服务、互联网中间件、移动服务、视频服务等。通过本课程,来了解阿里云能够为你的业务带来哪些帮助 &nbsp; &nbsp; 相关的阿里云产品:云服务器ECS 云服务器 ECS(Elastic Compute Service)是一种弹性可伸缩的计算服务,助您降低 IT 成本,提升运维效率,使您更专注于核心业务创新。产品详情: https://www.aliyun.com/product/ecs
相关文章
|
1月前
|
存储 SQL 关系型数据库
Mysql高可用架构方案
本文阐述了Mysql高可用架构方案,介绍了 主从模式,MHA模式,MMM模式,MGR模式 方案的实现方式,没有哪个方案是完美的,开发人员在选择何种方案应用到项目中也没有标准答案,合适的才是最好的。
163 3
Mysql高可用架构方案
|
2月前
|
SQL 关系型数据库 MySQL
mysql主从复制概述和配置
【10月更文挑战第22天】MySQL 主从复制是一种将主服务器的数据复制到一个或多个从服务器的技术,实现读写分离,提高系统性能和可用性。主服务器记录变更日志,从服务器通过 I/O 和 SQL 线程读取并应用这些变更。适用于读写分离、数据备份和恢复、数据分析等场景。配置步骤包括修改配置文件、创建复制用户、配置从服务器连接主服务器并启动复制进程。
129 1
|
4月前
|
存储 SQL 关系型数据库
MySQL体系结构与配置
MySQL体系结构与配置
64 0
|
1月前
|
存储 SQL 关系型数据库
2024Mysql And Redis基础与进阶操作系列(1)作者——LJS[含MySQL的下载、安装、配置详解步骤及报错对应解决方法]
Mysql And Redis基础与进阶操作系列(1)之[MySQL的下载、安装、配置详解步骤及报错对应解决方法]
|
1月前
|
关系型数据库 MySQL Linux
在 CentOS 7 中通过编译源码方式安装 MySQL 数据库的详细步骤,包括准备工作、下载源码、编译安装、配置 MySQL 服务、登录设置等。
本文介绍了在 CentOS 7 中通过编译源码方式安装 MySQL 数据库的详细步骤,包括准备工作、下载源码、编译安装、配置 MySQL 服务、登录设置等。同时,文章还对比了编译源码安装与使用 RPM 包安装的优缺点,帮助读者根据需求选择最合适的方法。通过具体案例,展示了编译源码安装的灵活性和定制性。
166 2
|
2月前
|
SQL 关系型数据库 MySQL
Mysql中搭建主从复制原理和配置
主从复制在数据库管理中广泛应用,主要优点包括提高性能、实现高可用性、数据备份及灾难恢复。通过读写分离、从服务器接管、实时备份和地理分布等机制,有效增强系统的稳定性和数据安全性。主从复制涉及I/O线程和SQL线程,前者负责日志传输,后者负责日志应用,确保数据同步。配置过程中需开启二进制日志、设置唯一服务器ID,并创建复制用户,通过CHANGE MASTER TO命令配置从服务器连接主服务器,实现数据同步。实验部分展示了如何在两台CentOS 7服务器上配置MySQL 5.7主从复制,包括关闭防火墙、配置静态IP、设置域名解析、配置主从服务器、启动复制及验证同步效果。
Mysql中搭建主从复制原理和配置
|
3月前
|
关系型数据库 MySQL 数据安全/隐私保护
docker应用部署---MySQL的部署配置
这篇文章介绍了如何使用Docker部署MySQL数据库,包括搜索和拉取MySQL镜像、创建容器并设置端口映射和目录映射、进入容器操作MySQL,以及如何使用外部机器连接容器中的MySQL。
docker应用部署---MySQL的部署配置
|
2月前
|
关系型数据库 MySQL Java
Django学习二:配置mysql,创建model实例,自动创建数据库表,对mysql数据库表已经创建好的进行直接操作和实验。
这篇文章是关于如何使用Django框架配置MySQL数据库,创建模型实例,并自动或手动创建数据库表,以及对这些表进行操作的详细教程。
95 0
Django学习二:配置mysql,创建model实例,自动创建数据库表,对mysql数据库表已经创建好的进行直接操作和实验。
|
3月前
|
关系型数据库 MySQL Go
go抽取mysql配置到yaml配置文件
go抽取mysql配置到yaml配置文件
|
4月前
|
弹性计算 关系型数据库 MySQL
centos7 mysql安装及配置
本文详细介绍了在阿里云服务器ECS上通过yum源安装MySQL 8.0.12的过程,包括更新yum源、下载并安装MySQL源、解决安装过程中可能遇到的问题等步骤。此外,还介绍了如何启动MySQL服务、设置开机自启、配置登录密码、添加远程登录用户以及处理远程连接异常等问题。适合初学者参考,帮助快速搭建MySQL环境。
564 8
centos7 mysql安装及配置