Category Covered

shell script mysql important command

Make sure you logged in mysql using the following command
[root@WAP ~]# mysql -u root
mysql> create database [databasename];

//WHICH DATABASE YOU ARE GOING TO USE OR CHANGE DATABASE use the following command
mysql> use dbname;


//HOW TO SET PRIVILEGES ON DATABASE USING SHELL SCRIPT ON LINUX
mysql> grant all privileges on tera_wurfl_demo.* to root;
mysql> flush privileges;

//IMPORT DATABASE SHELL COMMAND ON LINUX
mysql -u root -p nextnet < /nextnet.sql;
mysql -u root -p tera_wurfl_demo < /tera.sql;

//SHOW DATABASE TABLES FIELD FORMAT
mysql> show tables;
To see database's field formats.

//DELETE DATABASE SHELL COMMAND
mysql> drop database [database name];

//DELETE MYSQL DATABASE TABLE
drop table content_downloads; 
mysql> drop table [table name];

//SHOW ALL DATA OF A TABLE.
mysql> SELECT * FROM [table name];



//SOME OTHER DATABASE QUERY THAT MAY HELP YOU WHEN YOU ARE ON SHELL SCRIPT

mysql> SELECT * FROM [table name] WHERE [field name] = "whatever";
Show all records containing the name "Bob" AND the phone number '3444444'.

mysql> SELECT * FROM [table name] WHERE name = "Bob" AND phone_number = '3444444';
Show all records not containing the name "Bob" AND the phone number '3444444' order by

the phone_number field.

mysql> SELECT * FROM [table name] WHERE name != "Bob" AND phone_number = '3444444'

order by phone_number;
Show all records starting with the letters 'bob' AND the phone number '3444444'.

mysql> SELECT * FROM [table name] WHERE name like "Bob%" AND phone_number = '3444444';
Show all records starting with the letters 'bob' AND the phone number '3444444' limit

to records 1 through 5.

mysql> SELECT * FROM [table name] WHERE name like "Bob%" AND phone_number = '3444444'

limit 1,5;
Use a regular expression to find records. Use "REGEXP BINARY" to force case-

sensitivity. This finds any record beginning with a.

mysql> SELECT * FROM [table name] WHERE rec RLIKE "^a";
Show unique records.

mysql> SELECT DISTINCT [column name] FROM [table name];
Show selected records sorted in an ascending (asc) or descending (desc).

mysql> SELECT [col1],[col2] FROM [table name] ORDER BY [col2] DESC;
Return number of rows.

mysql> SELECT COUNT(*) FROM [table name];
Sum column.

mysql> SELECT SUM(*) FROM [table name];
Join tables on common columns.