Why you do not use GRANT ALL ON *.*?
I was with a client today, and after rebooting a MySQL 5.0.22 instance cleanly with /etc/init.d/mysqld service, I observed the following error, because you always check the log file after starting MySQL.
080923 16:16:24 InnoDB: Started; log sequence number 0 406173600 080923 16:16:24 [Note] /usr/libexec/mysqld: ready for connections. Version: '5.0.22-log' socket: '/var/lib/mysql/mysql.sock' port: 3306 Source distribution 080923 16:16:24 [ERROR] /usr/libexec/mysqld: Table './schema_name/table_name' is marked as crashed and should be repaired 080923 16:16:24 [Warning] Checking table: './schema_name/table_name'
Now, I’d just added to the /etc/my.cnf a number of settings including:
myisam_recovery=FORCE,BACKUP
which explains the last line of the log file. When attempting to connect to the server via the mysql client I got the error:
“To many connections”
So now, I’m in a world of hurt, I can’t connect to the database as the ‘root’ user to observe what’s going on. I know that table it’s decided to repair is 1.4G in size, and the server is madly reading from disk. Shutting down the apache server that was connecting to the database is not expected to solve the problem, and does not, because connections must wait to timeout.
MySQL reserves a single super privileged connection, i.e. ‘root’ to the mysql server specifically for this reason, unless all the connections have this privilege. The problem, as often experienced with clients, is the permissions of the application user is simply unwarranted.
mysql> select host,user,password from mysql.user; +-----------+-------------+------------------+ | host | user | password | +-----------+-------------+------------------+ | localhost | root | 76bec9cc7dd32bc0 | | xxxxxx | root | | | xxxxxx | | | | localhost | | | | % | xxxxxxxxxxx | 0716d6776318d605 | | localhost | xxxxxxxxxxx | 0716d6776318d605 | | localhost | xxxxxxx | 6885269c4a550a03 | +-----------+-------------+------------------+ 7 rows in set (0.00 sec) mysql> show grants for xxxxxxx@localhost; +---------------------------------------------------------------------------------------+ | Grants for xxxxxxx@localhost | +---------------------------------------------------------------------------------------+ | GRANT USAGE ON *.* TO xxxxxxx'@'localhost' IDENTIFIED BY PASSWORD '6885269c4a550a03' | | GRANT ALL PRIVILEGES ON `xxxxxxx`.* TO 'xxxxxxx'@'localhost' WITH GRANT OPTION | +---------------------------------------------------------------------------------------+ 2 rows in set (0.00 sec)
So the problem is ALL PRIVILEGES is granted to an application user. Never do this!
The solution is to remove all unused users, anonymous users, and create the application user with just the privileges needed.
DROP USER xxxxxxxxxxx@localhost; DROP USER xxxxxxxxxxx@'%'; DELETE FROM mysql.user WHERE user=''; FLUSH PRIVILEGES; DROP USER xxxxxxx@localhost; CREATE USER xxxxxxx@localhost IDENTIFIED BY 'xxxxxxx'; GRANT SELECT,INSERT,UPDATE,DELETE ON xxxxxxx.* TOxxxxxxx@localhost;
Eric Lemoine says
According to the documentation (http://dev.mysql.com/doc/refman/5.0/en/grant.html) :
The FILE, PROCESS, RELOAD, REPLICATION CLIENT, REPLICATION SLAVE, SHOW DATABASES, SHUTDOWN, SUPER, and CREATE USER privileges are administrative privileges that can only be granted globally (using ON *.* syntax).
So if you grant ALL a user on specific objects (my_db.* or my_db.my_table), this user won’t have the SUPER privilege.
Eric