Upgrading MYSQL 5.0 or 5.1 to5.5 or 5.6 on Freebsd

Hi there!

I just completed our upgrade of mysql so I thought I’d let people know how to do it the correct way as I can see alot of people missing some vital steps to have everything running smoothly afterwards. I managed to do the upgrade with 15 seconds of downtime (when you install 5.5 it will shutdown mysql-server so while installing mysql will be offline).

1. The first thing you have to do is check what ports depends on your current version of mysql-client, this can be done by issuing

(root@)~#  portupgrade -frn mysql-client

Se não souber ou caso não retorne a versão do mysql verificar com o comando:


(root@)~# mysql --version
mysql  Ver 14.14 Distrib 5.6.24, for FreeBSD9.1 (amd64) using  EditLine wrapper

Obs: Esse print foi feito após minha atualização. Provavelmente verás uma versão inferior a esta.

if you’re using portmaster you obvisously have to change the flags to whatever the portmaster equivalent is, but as im a portupgrade kind of guy I wont get into that. What this command does is that it tries to force rebuild all ports that depends on mysql-client, but as we also used the ”n” flag, it wont start doing anything (only a test). So you should now have a huuuuge list of ports that requires the mysql-client port to work correctly, save this list to a safe location because you will need it later (you can remove mysql-client and mysql-server from this list as your going to reinstall those anyway)

2. Now before you start doing anything stupid, after issuing the below stated commands, do NOT restart apache/php-fpm afterwards until you have rebuilt apache/php because you will then get downtime due to that because those softwares will stop working until rebuilt. If you’re using postfix for mail, it will stop working at the moment you deinstall mysql51-server, so if you’re using postfix for your mailaccounts, you want to rebuild that port the first thing you do in step 3 and then restart postfix.

Dependendo da versão visualizada, entrar no ports para realizar a remoção:


#Realizar um stop na servidor mysql:
(root@)~# /usr/local/etc/rc.d/mysql-server stop

(root@)~# cd /usr/ports/databases/mysql51-client  # caso seja 5.0 -- > cd /usr/ports/databases/mysql51-client
(root@)~# make deinstall
(root@)~# cd /usr/ports/databases/mysql51-server # caso seja 5.0 -- > cd /usr/ports/databases/mysql50-server
(root@)~# make deinstall

Now install mysql 5.5 server (will install mysql 5.5 client automatically)

Realizar a instalação do Mysql mais atual:

(root@)~#  cd /usr/ports/databases/mysql56-client
(root@)~#  make install clean

(root@)~# cd /usr/ports/databases/mysql56-server
(root@)~# make install clean

# Restart do servidor

(root@)~#  shutdown -r now

No meu caso o mysql não subiu corretamente após restart.
Precisei editar o arquivo /etc/rc.conf

(root@)~#  vim /etc/rc.conf
mysql_enable="YES"
mysql_args="--skip-grant-tables"


(root@)~#  /usr/local/etc/rc.d/mysql-server restart

# Verificar se subiu com:

(root@)~# /usr/local/etc/rc.d/mysql-server status
mysql is running as pid 2049.

#Conectei no mysql com qualquer senha uma vez que no rc.conf fizemos um skip grant tables:

(root@orion)~# mysql -uroot -p123
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 602
Server version: 5.6.24 Source distribution

Copyright (c) 2000, 2015, 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>

Now that you’ve got the new shit installed, fire it up and also run mysql_upgrade afterwards

# Realizei o update

(root@)~#  mysql_upgrade -u root -p

Comentei no rc.conf a linha abaixo:
(root@)~#  vim /etc/rc.conf
mysql_enable="YES"
#mysql_args="--skip-grant-tables"

Realizei um novo restart 
(root@)~#  /usr/local/etc/rc.d/mysql-server restart

O modulo alarmou que já estava sendo usado. 
Rebootar o servidor:
 
(root@)~#  shutdown -r now


After mysql_upgrade is done I usually restart mysql again (just in case)

3. You now have mysql 5.5 installed and running, however, all your software are still using the 5.1 client, so at this point, DO NOT RESTART ANY SOFTWARE. As most software keeps a copy of it’s libraries in memory so everything should be working just fine until restart.

If you’re running postfix, the first thing you want to do is this

portupgrade -fO postfix
# If your using mysql as userdatabase
portupgrade -fO p5-DBD-mysql
# If your using spamassassin
portupgrade -fO p5-Mail-SpamAssassin
There is probably more p5- ports that you have in your list, rebuild all those and then restart postfix and you should be good to go.

Now, take the list of ports you saved in step 1 and rebuild every single one of them. You probably have alot of php ports in it if you’re using php, heres an easy way of getting that stuff rebuilt without problems

portupgrade -fO php5*
# If your also using pecl modules and eaccelerator
# issue the below command
portupgrade -fO pecl* eaccelerator
If you’re using apache you probably have apache22, mod_perl and apr1 in the list

portupgrade -fO www/apache22 www/mod_perl2 devel/apr1
The most basic webstuff is now done and it’s safe to restart apache, however, you will have to rebuild all ports you have in your list for them to work correctly. So before restarting a software, make sure you have rebuilt that port and those ports that it depends on. When you think your done, meaning you have rebuilt all ports in your list, you can run pkgdb -F to remove all the dependencies to the old mysql-client. After that you can run portversion just to check that there is no dependency warning, if there is no warning, well done!

Thats all from me this time, hope this helped someone out.

Deixe uma resposta