Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

linux

mysql

login

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

like image 614
Param-Ganak Avatar asked Jun 01 '11 11:06

Param-Ganak


People also ask

How do I log into MySQL database?

Enter mysql.exe -uroot -p , and MySQL will launch using the root user. MySQL will prompt you for your password. Enter the password from the user account you specified with the –u tag, and you'll connect to the MySQL server.

How do I log into a database in terminal?

To access a specific database, type the following command at the mysql> prompt, replacing dbname with the name of the database that you want to access: Copy use dbname; Make sure you do not forget the semicolon at the end of the statement. After you access a database, you can run SQL queries, list tables, and so on.


2 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.

like image 114
Álvaro González Avatar answered Sep 25 '22 11:09

Álvaro González


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.

like image 45
flindeberg Avatar answered Sep 24 '22 11:09

flindeberg