@@ -74,12 +74,80 @@ install_zabbix_server() {
7474 apt-get update -qq
7575 print_success " Zabbix repository added"
7676
77- # Install MySQL
78- print_info " Installing MySQL server..."
79- apt-get install -y mysql-server
80- systemctl start mysql
81- systemctl enable mysql
82- print_success " MySQL installed and started"
77+ # Check for existing database installations
78+ print_info " Checking for existing database installations..."
79+ DB_INSTALLED=false
80+ DB_TYPE=" "
81+
82+ if dpkg -l | grep -q " ^ii.*mariadb-server" ; then
83+ DB_INSTALLED=true
84+ DB_TYPE=" MariaDB"
85+ elif dpkg -l | grep -q " ^ii.*mysql-server" ; then
86+ DB_INSTALLED=true
87+ DB_TYPE=" MySQL"
88+ fi
89+
90+ if [ " $DB_INSTALLED " = true ]; then
91+ print_info " ${DB_TYPE} is already installed"
92+ echo " "
93+ echo " Choose an option:"
94+ echo " 1) Use existing ${DB_TYPE} (recommended if working)"
95+ echo " 2) Remove ${DB_TYPE} and install fresh MySQL 8.0"
96+ echo " 3) Cancel installation"
97+ read -p " Enter choice [1-3]: " db_choice
98+
99+ case " $db_choice " in
100+ 1)
101+ print_info " Using existing ${DB_TYPE} "
102+ # Check if database is running
103+ if ! systemctl is-active --quiet mysql && ! systemctl is-active --quiet mariadb; then
104+ print_info " Starting database service..."
105+ systemctl start mysql 2> /dev/null || systemctl start mariadb 2> /dev/null || true
106+ fi
107+ ;;
108+ 2)
109+ print_info " Removing existing ${DB_TYPE} ..."
110+ # Stop services
111+ systemctl stop mysql 2> /dev/null || true
112+ systemctl stop mariadb 2> /dev/null || true
113+
114+ # Remove frozen file if exists
115+ rm -f /etc/mysql/FROZEN
116+
117+ # Purge old installations
118+ apt-get remove --purge -y mariadb-server mariadb-client mysql-server mysql-client 2> /dev/null || true
119+ apt-get autoremove -y
120+
121+ # Clean up config files
122+ rm -rf /etc/mysql
123+ rm -rf /var/lib/mysql
124+
125+ print_success " Old database removed"
126+
127+ # Install MySQL
128+ print_info " Installing MySQL server..."
129+ apt-get install -y mysql-server
130+ systemctl start mysql
131+ systemctl enable mysql
132+ print_success " MySQL installed and started"
133+ ;;
134+ 3)
135+ print_error " Installation cancelled"
136+ exit 1
137+ ;;
138+ * )
139+ print_error " Invalid choice"
140+ exit 1
141+ ;;
142+ esac
143+ else
144+ # Install MySQL - no existing database
145+ print_info " Installing MySQL server..."
146+ apt-get install -y mysql-server
147+ systemctl start mysql
148+ systemctl enable mysql
149+ print_success " MySQL installed and started"
150+ fi
83151
84152 # Detect or choose web server
85153 print_info " Detecting web server..."
0 commit comments