Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MySQL wont let me add column

This should be a really simple process but for whatever reason, I am unable to add a column to an MySQL table. Here's my syntax:

$query = "ALTER TABLE game_licenses ADD lifetime VARCHAR(255) AFTER expire_date";
$result = mysql_query($query);
if (!$result) {
    echo "it failed";
}
else {
    echo "success";
}

I've tried multiple little changes like adding COLUMN to the query after ADD. There are no MySQL errors but finishes the script and echos "it failed".

The error is:

ALTER command denied to user 'webuser'@'localhost'

Is it possible to lock a table from being altered?

like image 292
user1034772 Avatar asked Nov 10 '11 14:11

user1034772


1 Answers

You don't have the privileges to do so.

Make sure you have the alter privilege on that table.

Have the superuser (root) execute the following:

GRANT ALTER ON dbname.game_licences TO `webuser`@`localhost` 

See: http://dev.mysql.com/doc/refman/5.1/en/grant.html.

P.S. Are you sure you want normal users to be able to issue alter statements?
Better option may be to issue the alter statement as root, or even better to make an admin account that has full rights on the database, but not full rights on any other database.

like image 174
Johan Avatar answered Nov 02 '22 05:11

Johan