Wednesday, May 22, 2013

Useful MySQL commands

This is not MySQL tutorial. It's just list of useful SQL statements that I don't remember and I don't want to google them anymore. SQL commanda are also in basic form. For more detail see original MySQL documentation.

Create new user with login name 'userName' with password 'passwd'. Created use have access to all tables in database 'testDb'.

GRANT ALL PRIVILEGES ON testDb.* TO 'userName'@'host' IDENTIFIED BY 'passwd';

Create new database with default text columns encoding.

CREATE SCHEMA `testDb` DEFAULT CHARACTER SET utf8 ;

Set password for user 'sa' accessing from localhost to 'be'.

SET PASSWORD FOR sa@localhost = PASSWORD('be');

Create SQL file containing all data form database. It's useful for creating backups and for copying data from one db into another one.

mysqldump --add-drop-table -u sa -psa bl > bl.sql

No comments:

Post a Comment