“access denied for user” after moving MySQL database to remote server

本小妞迷上赌 提交于 2019-12-02 13:12:28

MySQL permissions are based on the address which they are connecting to as well as the user. So root@localhost and root@10.4.1.163 will have two separate set of permissions. Changing localhost to 127.0.0.1 as num8er mentioned will probably work if your code and the database are on the same server.

If you have terminal access to the box where your php is you could try connecting directly ruling out anything to do with php using this:

mysql -h 10.4.1.163 -u root -p[pass] database -e "SHOW TABLES"

Note there is no space between -p and the password. If successful this will get you a list of tables in database.

To grant access to other users or for another hostname/IP you will want to run something along the lines of this: (though you should really create a separate user with more restricted permissions based on your requirements).

GRANT ALL PRIVILEGES ON `database`.* TO 'root'@'10.4.1.163';

Check the docs on MySQL's GRANT here - http://dev.mysql.com/doc/refman/5.7/en/grant.html

On a side note - please, please, please don't just pump any old data into a query without at least using mysql_real_escape_string (http://php.net/manual/en/function.mysql-real-escape-string.php) on it before hand. You could also look into PDO (http://php.net/manual/en/book.pdo.php) which is generally preferred over the now deprecated mysql_ functions

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!