Laravel migrate command not working for remote database

I am working on a project using the Laravel 4.2 framework. I want to execute the php artisan migrate command, but when I run this command, it shows an error:

[PDOException]
SQLSTATE [42000]: syntax error or access violation: 1142 CREATE command denied for user 'abc'@'10.1.1.27' for table "migrations"

I think I put the project and database files on different servers, so why am I getting this error.

Database Server: 10.1.1.56

Project Server: 10.1.1.27 (localhost)

+8
php mysql
source share
2 answers

This error indicates that the remote MySQL database is not configured so that certain operations performed by user abc from IP address 10.1.1.27 . In many cases, MySQL users are configured to allow access from the same host as the database server, but we need explicitly GRANT access for clients connecting to the database from a remote host.

We can use the following commands to give the abc user access from remote hosts. We must run these commands as a user who has the ability to grant privileges to other users (for example, the root user):

 GRANT ALL PRIVILEGES ON database.* TO 'abc'@'%'; FLUSH PRIVILEGES; 

Replace database name of the application database configured in .env or config / database.php . The wildcard character '%' in 'username'@'%' indicates that we want to grant permissions to this user from any IP address. If we do not want to allow the user access from any IP address, we can restrict access to certain IP addresses by replacing the wildcard with the address to allow ( 10.1.1.27 in this case).

Depending on the needs of the project, we may not need to grant the user all privileges for the database. See the documentation for a list of available privileges that we can assign.

+5
source share

1142 CREATE command denied to user 'abc'@'10.1.1.27' for table 'migrations'

The above command simply means that the user does not have CREATE permission for the connected database. Therefore, first of all, you must grant privileges to this user in the database and then perform the migration.

Explanation: When migrate starts, a table is created with the name migration in the database that maintains the migration status and does not have CREATE to resolve why it shows an error.

0
source share

All Articles