MySQL

From ◜◝◟◞◜◝◟◞◜◝◟◞◜◝◟◞◜◝◟◞◜◝◟◞◜◝◟◞
Jump to: navigation, search

Logging into MySQL DB:

mysql -u root -p --database=wiki_brandon_db

If you log in MySQL using -sN, it will print results without table formatting.

mysql -sN -u root -p --database=wiki_brandon_db

This command lists all MySQL databases on you server.

show databases;

This command lists all tables in particular database;

show tables;

This command shows table schema. In place of 'user', use any table name.

explain user;

This command will display all usernames from table 'user'

SELECT user_name FROM user;

--Writing to Outfile-- Change permissions to allow write, if necessary. -sN isn't necessary to print results without table formatting in this case.

SELECT user_name FROM user INTO OUTFILE '/tmp/user_name.csv' FIELDS TERMINATED BY ',' LINES TERMINATED BY '\n';



http://www.elated.com/articles/mysql-for-absolute-beginners/