[mysql] 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

This question is related to mysql linux login

The answer is


I had the same exact issue on my ArchLinux VPS today.

mysql -u root -p just didn't work, whereas mysql -u root -pmypassword did.

It turned out I had a broken /dev/tty device file (most likely after a udev upgrade), so mysql couldn't use it for an interactive login.

I ended up removing /dev/tty and recreating it with mknod /dev/tty c 5 1 and chmod 666 /dev/tty. That solved the mysql problem and some other issues too.


Try "sudo mysql -u root -p" please.


To stop or start mysql on most linux systems the following should work:

/etc/init.d/mysqld stop

/etc/init.d/mysqld start

The other answers look good for accessing the mysql client from the command line.

Good luck!


At the command prompt try:

mysql -u root -p

give the password when prompted.


if you're already logged in as root just

mysql -u root

prompting the password will otherwise return as error


To your first question:

mysql -u root -p

or

mysqladmin -u root -p "your_command"

depending on what you want to do. The password will be asked of you once you hit enter! I'm guessing you really want to use mysql and not mysqladmin.

For restarting or stopping the MySQL-server on linux, it depends on your installation, but in the common debian derivatives this will work for starting, stopping and restarting the service:

sudo /etc/init.d/mysql start
sudo /etc/init.d/mysql stop
sudo /etc/init.d/mysql restart
sudo /etc/init.d/mysql status

In some newer distros this might work as well if MySQL is set up as a deamon/service.

sudo service mysql start
sudo service mysql stop
sudo service mysql restart
sudo service mysql status

But the question is really impossible to answer without knowing your particular setup.


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.


if u got still no access to db, 1. in ur error message is set no password right? then first do mysqlpasswd 'username' after that enter and then give it a password type again as requested and then try to access again with mysql -p if you are root


In Ubuntu, all I have to do ran is sudo mysql in GNOME terminal and that's it. I can start making databases or query a data in table, etc.


use this "mysql -uroot -pPassword"


  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.


Examples related to mysql

Implement specialization in ER diagram How to post query parameters with Axios? PHP with MySQL 8.0+ error: The server requested authentication method unknown to the client Loading class `com.mysql.jdbc.Driver'. This is deprecated. The new driver class is `com.mysql.cj.jdbc.Driver' phpMyAdmin - Error > Incorrect format parameter? Authentication plugin 'caching_sha2_password' is not supported How to resolve Unable to load authentication plugin 'caching_sha2_password' issue Connection Java-MySql : Public Key Retrieval is not allowed How to grant all privileges to root user in MySQL 8.0 MySQL 8.0 - Client does not support authentication protocol requested by server; consider upgrading MySQL client

Examples related to linux

grep's at sign caught as whitespace How to prevent Google Colab from disconnecting? "E: Unable to locate package python-pip" on Ubuntu 18.04 How to upgrade Python version to 3.7? Install Qt on Ubuntu Get first line of a shell command's output Cannot connect to the Docker daemon at unix:/var/run/docker.sock. Is the docker daemon running? Run bash command on jenkins pipeline How to uninstall an older PHP version from centOS7 How to update-alternatives to Python 3 without breaking apt?

Examples related to login

How to center a component in Material-UI and make it responsive? SQLSTATE[HY000] [1698] Access denied for user 'root'@'localhost' Angular redirect to login page Swift add icon/image in UITextField SQL Server : login success but "The database [dbName] is not accessible. (ObjectExplorer)" vagrant login as root by default Node.js https pem error: routines:PEM_read_bio:no start line EditText underline below text property Given URL is not allowed by the Application configuration Facebook application error how to get login option for phpmyadmin in xampp