Recently I was asked if there is a way to update the MySQL version using the command line and which is the best way to do this.
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.
There a few ways to update MySQL or MariaDB and one of them is doing this via the command line / terminal and I would like to share the process with you.
Introduction
cPanel is one of the most popular Linux-based control panels for web hosting accounts. It’s been available for a long time and the installed software can often be outdated or become deprecated. cPanel is really picky when it comes to updating software and you will always be aware that issues may occur if you update any part of the software in a manner that cPanel will not acknowledge and you might end up corrupting the cPanel’s core files.
Requirements
If you’re running an outdated MySQL version or just want to run the latest MySQL version you will need a root access in order to update MySQL or MariaDB via the GUI - WHM or using the command line.
If you have root level access to your server / droplet than you’re good to go with the update process.
Updating MySQL / MariaDB
cPanel/WHM have a lot of available tools that you can use in order to update parts of your software. The build-in
whmapi
offers a lot of functionality and you can use in order to update software or change settings of the server or individual accounts hosted on the server.You can use the following command in order to see the available versions to which you can update your current MySQL / MariaDB installation:
An example output of the command will be:
You can find more info about this option of the whmapi using this link - https://documentation.cpanel.net/display/DD/WHM+API+1+Functions+-+installable_mysql_versions
Now if you want to update MariaDB to 10.2 you can use the following command:
You can find more info about this option of the whmapi using this link - https://documentation.cpanel.net/display/DD/WHM+API+1+Functions+-+start_background_mysql_upgrade
The command output will look like this:
Note that there is an upgrade_id in the output, we will use it in order to track down the progress on the update.
In order to see the progress on the task you can do many things like using
strace
and monitor the process id of the upgrade process, but cPanel has another really useful api tool in order to monitor the upgrade.Note: You must replace
mysql_upgrade.20200202-172923
with the actual ID provided from thestart_background_mysql_upgrade
command.You can find more info about this option of the whmapi using this link - https://documentation.cpanel.net/display/DD/WHM+API+1+Functions+-+background_mysql_upgrade_status
The out put will look like this:
However I will recommend you to keep the progress by making the output more pretty and track the status until it’s done.
This will print the most valuable part of the process which is the state. For the time the process is running the state will be
inprogress
and once it’s done it will besucsess
If there are any errors it will finish with an
failed
state and then you can again check the status without using thegrep
command in order to see the exact issue with the update process.Conclusion
This is pretty much it. The process might take up some time depending on the MySQL / MariaDB configuration and the size of the databases on the server the configuration and etc.
Note: If you’ve made any custom changes to your
/etc/my.cnf
file you might end up with issues when doing the update process. I will highly recommend you to take a backup of your databases before doing the process in case something goes wrong. Also you need to make sure your websites and applications are compatible with the newer MySQL / MariaDB version, because your code might be using functions and methods which are deprecated in the newer version and this might cause issues and downtime for your sitesOther than that the process is really simply and it the worst case it should take 30-40 minutes for a busy server to complete (keep in mind that the process length will also depend form the version update as well, the 5.5 to 5.6 update will take more time than 5.6 to 5.7 for example)
Hope this helps!
If you have any questions or ideas please feel free to share them down in the answers/comments section.
Regards, Alex