Following command will install MySQL on a CentOS server / VPS.
Login to your server as root via SSH, and run following command.
yum install mysql-server service mysqld start
Set MySQL server root password.
MySQL server will ask MySQL server root password. Since you just installed mysql, there is no MySQL root password. So, just press enter.
Enter current password for root (enter for none): OK, successfully used password, moving on...
MySQL will prompt you to set a root password. Press Y to set mySQL server root password.
Set root password? [Y/n]
Enter and re-enter root password for MySQL server. Please use a strong password and do not use your server root password.
Set root password? [Y/n] y New password: Re-enter new password: Password updated successfully! Reloading privilege tables.. ... Success!
Now MySQL will ask a series of questions. Press Y for all.
Remove anonymous users? [Y/n] Disallow root login remotely? [Y/n] Remove test database and access to it? [Y/n] Reload privilege tables now? [Y/n]
At the end MySQL will show success message.
All done! If you've completed all of the above steps, your MySQL installation should now be secure. Thanks for using MySQL!