Clear database from tables

SET FOREIGN_KEY_CHECKS = 0; SET GROUP_CONCAT_MAX_LEN=32768; SET @tables = NULL; SELECT GROUP_CONCAT(table_name) INTO @tables FROM information_schema.tables WHERE table_schema = (SELECT DATABASE()); SELECT IFNULL(@tables,’dummy’) INTO @tables; SET @tables = CONCAT(‘DROP TABLE IF EXISTS ‘, @tables); PREPARE stmt FROM @tables; EXECUTE stmt; DEALLOCATE PREPARE stmt; SET FOREIGN_KEY_CHECKS = 1;

Read more

MySQL create, update and delete user

Create database mysql> CREATE DATABASE databasename; Query OK, 1 row affected (0,02 sec) Create user mysql> CREATE USER ‘abadowski’@’localhost’ IDENTIFIED BY ‘passwordname’; mysql> GRANT ALL PRIVILEGES ON abadowski.* TO ‘abadowski’@’localhost’ -> WITH GRANT OPTION; Update user mysql> UPDATE mysql.user SET Password=PASSWORD(‘newpasswordname’) WHERE User=’abadowski’; mysql> FLUSH PRIVILEGES; Delete mysql> DROP USER ‘abadowski’@’localhost’; mysql> DROP DATABASE databasename;

Read more