Useful commands for PostgreSQL

Some useful PostgreSQL commands that I need from time to time. Execute with postgres user.

List all users

psql
\du

Remove a user

dropuser USERNAME

List all databases

psql
\list

Remove a database

dropdb DATABASENAME;

Update password of user

psql
alter user USERNAME with password 'NEWPASSWORD';

Create a database and user, assign user to database

createuser -P USERNAME 
createdb -O USERNAME DATABASENAME

Remove all tables of a schema (if all tables in a single schema)

drop schema public cascade;
create schema public;

Useful commands for MySQL

Some useful MySQL commands that I need from time to time:

List all users

select User, Host from mysql.user;

Remove a user

show grants for 'USERNAME'@'localhost';
revoke all privileges, grant option from 'USERNAME'@'localhost';
drop user 'USERNAME'@'localhost';

List all databases

show databases;

Remove a database

drop database DATABASENAME;

Update password of user

update mysql.user set password=PASSWORD("NEWPASSWORD") where User = 'USERNAME';
flush privileges;

Create a database and user, assign user to database

create database DATABASE default character set utf8 collate utf8_general_ci;
grant all on DATABASE.* to 'USERNAME'@'localhost' identified by 'PASSWORD';
flush privileges;

Dump a database

mysqldump --user="<USERNAME>" --password="<PASSWORD>" <DATABASE> --quick --lock-tables --add-drop-table | gzip > /tmp/<NAME>.sql.gz
Written by Alex on Sun 13 December 2015 in HowTo - Tagged with: mysql

Repository for existing Extbase model class

If you want to use an existing extbase model like Category but want to create a custom repository to implement some custom queries, here is the way to go:

Create typo3conf/ext/your_ext/Classes/Domain/Model/Category.php:

<?php
namespace Dummy\YourExt\Domain\Model;
/**
 * Category
 */
class Category extends \TYPO3\CMS\Extbase\Domain\Model\Category {

}

Create typo3conf/ext/your_ext/Classes/Domain/Repository/CategoryRepository.php:

<?php
namespace Dummy\YourExt\Domain\Repository;
/**
 * The repository for Categories
 */
class CategoryRepository extends \TYPO3\CMS\Extbase\Domain\Repository\CategoryRepository {
    // some custom query methods here
}

Create typo3conf/ext/your_ext/ext_typoscript_setup.txt:

config.tx_extbase{
    persistence{
        classes{
            Dummy\YourExt\Domain\Model\Category {
                mapping {
                    tableName = sys_category
                    recordType = Tx_YourExt_Category
                }
            }
        }
    }
}

Clear the cache and you're ready to go!