July 14, 2015

Restoring Database Privileges

I’ve seen several cases in the last few months where database users seemingly “disappear” or privileges appear to become invalid when restoring MySQL data or an entire server from raw backups. This may commonly be attributed to a MySQL version mismatch, for example, when a server is running MySQL 5.0 and then is suddenly running MySQL 5.1 or higher (or data is directly restored to a server running such), without having the database tables updated.
First things first, make sure to resolve the database version discrepancy, if one exists. Back up your data, then upgrade or downgrade MySQL to the version that your server should be running. Note that you should typically avoid downgrading MySQL to a previous version in order to prevent corrupting data. After you upgrade, run the command “mysql_upgrade” to fix the tables if the procedure in the referenced article doesn’t already do this for you.
To restore privileges:
Run the following command to dump the privilege table into a MySQL syntax that can be easily imported:
/scripts/grabmysqlprivs > /root/privileges.sql
*If you only need a certain user’s privileges, simply use grep to pull out that data:
/scripts/grabmysqlprivs | grep $user > /root/privileges.sql
On the server you need to restore to, simply import then SQL file:
mysql < /root/privileges.sql
This should be sufficient, however, if you see that the database users are not populated in cPanel, you can try remapping them:
/usr/local/cpanel/bin/setupdbmap

Related Posts:

  • Backup và Restore MySQL Database bằng lệnh Nếu bạn đang sử dụng MySQL database, chắc chắn bạn sẽ không mong muốn dữ liệu của bạn bị mât. Do vậy việc backup MySQL database thường xuyên là cần thiết. Bạn có thể đơn giản hóa bằng cách sử dụng lệnh tr… Read More
  • MySQL Basics Install MySQL Server Debian/Ubuntu [mitesh@Matrix ~]$ sudo apt-get update && sudo apt-get install -y mysql-server Redhat/CentOS [mitesh@Matrix ~]$ sudo yum install -y mysql-server Important Files Configuratio… Read More
  • Disk Space for MySQL Databases in cPanel Show as 0MB When you upgrade from cPanel 11.24 to 11.25, your users may notice that in cPanel, their MySQL databases show 0MB of disk space used, when they know their databases are much larger. This is due to an option in cPanel that yo… Read More
  • How to Change the Location of MySQL on cPanel There may be some situations where you have to move the location of MySQL, for example, if you’re out of disk space or perhaps looking to host it on another device to increase performance. Whatever the reason, moving MySQL i… Read More
  • Restoring Database Privileges I’ve seen several cases in the last few months where database users seemingly “disappear” or privileges appear to become invalid when restoring MySQL data or an entire server from raw backups. This may commonly be attributed… Read More

0 comments:

Post a Comment