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

MysqlLinuxLogin

Mysql Problem Overview


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

Mysql Solutions


Solution 1 - Mysql

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.

Solution 2 - Mysql

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.

Solution 3 - Mysql

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.

Solution 4 - Mysql

At the command prompt try:

mysql -u root -p

give the password when prompted.

Solution 5 - Mysql

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.

Solution 6 - Mysql

  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.

Solution 7 - Mysql

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

Solution 8 - Mysql

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.

Solution 9 - Mysql

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!

Solution 10 - Mysql

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

Solution 11 - Mysql

if you're already logged in as root just

mysql -u root

prompting the password will otherwise return as error

Solution 12 - Mysql

Firstly Run terminal in root directory

sudo su

hit enter then type your root password then run your mysql using this command

mysql -u root -p

hit enter then enter your mysql password

Good Luck.!

Solution 13 - Mysql

mysql -u username -p password

as admin

sudo mysql -u username - p password

Solution 14 - Mysql

use this "mysql -uroot -pPassword"

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionParam-GanakView Question on Stackoverflow
Solution 1 - MysqlÁlvaro GonzálezView Answer on Stackoverflow
Solution 2 - MysqlflindebergView Answer on Stackoverflow
Solution 3 - MysqlstefgosselinView Answer on Stackoverflow
Solution 4 - MysqlquarkoniumView Answer on Stackoverflow
Solution 5 - Mysqluser789877View Answer on Stackoverflow
Solution 6 - MysqlcezioView Answer on Stackoverflow
Solution 7 - MysqlUdiView Answer on Stackoverflow
Solution 8 - MysqlPranavView Answer on Stackoverflow
Solution 9 - MysqlbaraboomView Answer on Stackoverflow
Solution 10 - Mysqluser2807050View Answer on Stackoverflow
Solution 11 - MysqlmaiomanView Answer on Stackoverflow
Solution 12 - MysqlAbhay TiwariView Answer on Stackoverflow
Solution 13 - MysqlinfomasudView Answer on Stackoverflow
Solution 14 - MysqlVadiraj S JView Answer on Stackoverflow