How to repair permissions on /usr/local after accidentally changed? I accidentally run command chown -R paulie /usr/local (I needed to add some subfolders).

How can I get it back? 

Now I already resolved problem with mysql data, but still have problems with gcc, for example.
Assuming you only changed the owner (as your command states), you can return everything back to root ownership by

chown -R root /usr/local


If you think you may need to fix the group ownership too, then this is better

chown -R root:wheel /usr/local