Running mysql queries in command line is possible with a option
to execute the SQL statement and quit.
Follow the syntax below :
mysql -u user -p -e ‘SQL Query’ Database_Name
Where,
-u : Specify mysql database user name
-p : Prompt for password
-e : Execute sql query
SQL Query : Specify your SQL query
Database_Name : Specify database name
eg :
verman@desktop:~$ mysql -u verman -p -e ‘select * from user;’ student
Enter password:

verman@verman-desktop:~$
Note : This will be more useful for running sql queries from a shell script.

when we use mysql -u root -p
then we have to given the password , its time what password we can apply
By default there is ‘NO’ password for root.
You can change the root password using mysqladmin
# mysqladmin -u root password ‘new-password’
If you forgot the root password for mysql, follow this link
http://dev.mysql.com/doc/refman/5.0/en/resetting-permissions.html#resetting-permissions-unix
But is it possible to grab output into a variable….!!!
If you have any idea please write me at razonklnbd [at] yahoo [dot] com
thanks for the tip i’m looking for this.
how can i solve ?
ERROR 2002 (HY000): Can’t connect to local MySQL server through socket ‘/var/lib/mysql/mysql.sock’ (2)
** file located at /etc/my.cnf
Try by adding this to my.cnf:
[client]
socket = /tmp/mysql.sock