I am working on a project using the Laravel 4.2 framework. I want to execute the command php artisan migrate but when I run this command it shows an error:
[PDOException]
SQLSTATE[42000]: Syntax error or access violation: 1142 CREATE command denied to user 'abc'#'10.1.1.27' for table 'migrations'
I think I have placed the project files and the database on different servers, so that's why am I getting this error.
Database server: 10.1.1.56
Project server: 10.1.1.27 (localhost)
This error indicates that the remote MySQL database isn't configured to allow certain operations executed by the user abc from the IP address 10.1.1.27. In many cases, MySQL users are set up to allow access from the the same host as the database server, but we need to explicitly GRANT access for clients connecting to the database from a remote host.
We can use the following commands to grant the user abc access from remote hosts. We must run these commands as a user that has the ability to grant privileges to other users (such as the database's root user):
GRANT ALL PRIVILEGES ON database.* TO 'abc'#'%';
FLUSH PRIVILEGES;
Replace database with the name of the application's database configured in .env or config/database.php. The wildcard '%' in 'username'#'%' indicates that we want to give permissions to that user from any IP address. If we don't want to allow the user access from any IP address, we can limit access to specific 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 give a user all privileges to a database. See the documentation for a list of available privileges that we can assign.
1142 CREATE command denied to user 'abc'#'10.1.1.27' for table 'migrations'
The above command simply means that the user don't have CREATE permission on the connected database. So first of all you have to grant the privileges to that user on the database and after that run the migration.
Explanation: When you run migrate, a table is created on with the name migration in the database that maintains the status of migration ion it, and you don'r have the CREATE permission that's why it is showing error.
Related
Im trying to access an sql database on c panel through a web hosting server. I have a user that has been created for the database and it has been granted all privileges. When I try to access the database through my domain+file path I get an error: Access denied for user "#localhost" using password yes on c panel.
I have tried command
SHOW GRANTS;on the database, and it get the following:
GRANT USAGE ON *.* TO 'cpses_hagmkcyksn'#'localhos...
GRANT ALL PRIVILEGES ON****_testdata.* TO ...
Any suggestions?
When trying to access my Laravel website I'm getting an SQL connection refused error when trying to execute $candidate = App\Models\Candidate::find(400);
SQLSTATE[HY000] [1698] Access denied for user 'root'#'localhost' (SQL: select * from `candidates` where `candidates`.`candid` = 400 limit 1)
However, I can connect fine using php artisan tinker from the command line:
root#454ab4403b8f:/app# php artisan tinker
Psy Shell v0.9.6 (PHP 7.2.7-1+ubuntu18.04.1+deb.sury.org+1 — cli) by Justin Hileman
>>> App\Models\Candidate::find(400)
=> App\Models\Candidate {#2865
candid: 400,
firstname: "",
...
}
Is there a different configuration for artisan than web? Why would one be working but not the other?
The ROOT account on a MySQL database is usually blocked for login that is not console. Artisan is console and your user is recognised.
Just make in your database a dedicated database and database user for your development purposes.
And never use root for web applications. Always make a dedicated user for databases and such. Root has too much power, and some errors that would possibly pop up on a normal user won't pop up under root which could lead to unexpected bugs when moving to production. In your local environment you wish to mimic production as close as possible, with all the same limitations.
Also if your website would end up with a weakness and on production you also use ROOT as database user, then if a hacker found the weakness the hacker could read/modify/wipe all the data in all your databases and possibly have access to your filesystem and gather other files that way. Just never use root except to configure the database.
I am creating an API REST aplication with Symfony3, and I have this problem. When I execute the methods in localhost it works fine, but I have uploaded the project to a server administered with Plesk, and when I try to execute the methods with postman, it shows this:
An exception occurred while executing 'SELECT t0.random_id AS ...'
with params [\"a\", \"a\"]:\n\nSQLSTATE[42000]: Syntax error or access
violation: 1142 SELECT command denied to user 'app'#'localhost' for
table 'table_name'
It seems to be a permissions problem, but if I try to access to the database with MysQL Workbech, with the same credentials, I can do it and execute querys without problems. And in the Plesk panel, the user has all the permissions and privileges.
I have also tried changing "localhost" for the host address in the parameters file of Symfony.
Looks like app user doesn't have permissions to execute SELECT query.
Run following MySQL query to fix it:
GRANT SELECT on database_name.* to 'app'#'localhost' identified by 'your-pass';
FLUSH PRIVILEGES;
I work on a personal website. I just put it on the production server. When I am in the development environment I connect to MySQL with root but now I just created a user specific for this website. So I wrote this command line in MySQL:
GRANT USAGE ON portefolio.* TO 'userPortefolio'#'localhost' IDENTIFIED BY PASSWORD 'myPasswordCrypted'
The query is ok, but on my website, when I try to access a page with a query, Symfony gives me that error:
SQLSTATE[42000] [1044] Access denied for user 'userPortefolio'#'localhost' to database 'portefolio'
I tried to restart the server to be sure everything is ok but nothing.
I encrypted the password with the MySQL function
password('my password not encrypt')
and in Symfony I wrote the password in non-encrypted format. Is that ok?
GRANT USAGE ON portefolio.* TO 'userPortefolio'#'localhost' IDENTIFIED BY PASSWORD 'myPasswordCrypted'
Your password should not be encrypted in this statement. MySQL crypts it automatically.
Assuming no quirks in connecting etc were made you should do a
flush privileges;
after running the grant query.
quoting from the manual: The USAGE privilege specifier stands for “no privileges.”
so everything seems to be working as designed.
I'm using MySQL given from A2Hosting. There I can create users and add them to databases. And i hosted my php codes inside web folder in symfony php structure. I dont want to use any symfony commands or functions. I have my own php calls to DB. But my Php codes gives the following error. But the user names and passwords are correct.
Query failed : Access denied for user 'games_user'#'localhost' to database 'games'
Granting privileges to user 'games_user' could not be enough. You must grant privileges to 'games_user'#'localhost', specifiying the host, even for localhost.
Granting all privileges for instance should look like this:
GRANT ALL PRIVILEGES ON database.* TO 'games_user'#'localhost' IDENTIFIED BY 'password';
Check permissions for user "games_user" in your "games" database. Access is denied to database "games"