Thursday, 8 November 2018

How to log in to mysql and query the database from linux terminal

I am using debian linux. I have a linux machine on which mysql is install. I can log in to my linux machine using root user as well as other user. I can connect to mysql database on linux machine from windows machine using sqlyog. Now I want to execute queries on linux machine only using linux terminal
I tried some following things on terminal
I went to root directory then I went to /var/lib directory
I run following commands on terminal
mysqladmin -u root -p
mysqladmin -u root -ppassword
everytime I have get following error message
ERROR 1045 (28000) Access denied for user 'root'@'localhost' (Using password NO)
please guide me for following
  1. How do I get mysql prompt in linux terminal?
  2. How I stop the mysql server from linux terminal?
  3. How I start the mysql server from linux terminal?
  4. How do I get mysql prompt in linux terminal?
  5. How do I login to mysql server from linux terminal?
  6. How do I solve following error?
ERROR 1045 (28000) Access denied for user 'root'@'localhost' (Using password NO)
Please give me solutions for above question. Thank You

 Answers


1.- How do I get mysql prompt in linux terminal?
mysql -u root -p
At the Enter password: prompt, well, enter root's password :)
You can find further reference by typing mysql --help or at the online manual.
2. How I stop the mysql server from linux terminal?
It depends. Red Hat based distros have the service command:
service mysqld stop
Other distros require to call the init script directly:
/etc/init.d/mysqld stop
3. How I start the mysql server from linux terminal?
Same as #2, but with start.
4. How do I get mysql prompt in linux terminal?
Same as #1.
5. How do I login to mysql server from linux terminal?
Same as #1.
6. How do I solve following error?
Same as #1.



I assume you are looking to use mysql client, which is a good thing and much more efficient to use than any phpMyAdmin alternatives.
The proper way to log in with the commandline client is by typing:
mysql -u username -p
Notice I did not type the password. Doing so would of made the password visible on screen, that is not good in multi-user environnment!
After typing this hit enter key, mysql will ask you for your password.
Once logged in, of course you will need:
use databaseName;
to do anything.
Good-luck.



At the command prompt try:
mysql -u root -p
give the password when prompted.



  1. you should use mysql command. It's a command line client for mysql RDBMS, and comes with most mysql installations: http://dev.mysql.com/doc/refman/5.1/en/mysql.html
  2. To stop or start mysql database (you rarely should need doing that 'by hand'), use proper init script with stop or start parameter, usually /etc/init.d/mysql stop. This, however depends on your linux distribution. Some new distributions encourage service mysql start style.
  3. You're logging in by using mysql sql shell.
  4. The error comes probably because double '-p' parameter. You can provide -ppassword or just -p and you'll be asked for password interactively. Also note, that some instalations might use mysql (not root) user as an administrative user. Check your sqlyog configuration to obtain working connection parameters.



if you're already logged in as root just
mysql -u root
prompting the password will otherwise return as error

0 comments:

Post a Comment