Archive | Commands RSS feed for this section

MySQL: Add User

28 Oct

To create a database and give a user privilege to that database:

mysql> CREATE DATABASE temp;
mysql> GRANT ALL PRIVILEGES ON temp.* TO 'bob'@'EEEPC'
    -> IDENTIFIED BY 'alice'
    -> WITH GRANT OPTION;

The privilege is full for Bob for all tables contained in the database called temp. Here, I explicitly defined the user’s host. That means Bob can only access the server if he used my Eee-PC. Even local access for Bob is not allowed because I did not add ‘bob’@'localhost’ in the GRANT command.

MySQL: Execute Source

28 Oct

Given you have no GUI client for MySQL, executing multiple CREATE/INSERT/UPDATE queries using the CLI would be troublesome. So preparing a valid SQL script file is advisable.  This command also works for dump files run for recovery or duplication.

mysql> source /path/to/source.sql;

MySQL: Outfile Logging

24 Oct

To log command executions & results from MySQL CLI to an output file:

mysql > \T output.txt
mysql > DESCRIBE table;
mysql > \t