code

mysql에 로그인하고 Linux 터미널에서 데이터베이스를 쿼리하는 방법

codestyles 2020. 8. 28. 07:31
반응형

mysql에 로그인하고 Linux 터미널에서 데이터베이스를 쿼리하는 방법


데비안 리눅스를 사용하고 있습니다. mysql이 설치된 Linux 시스템이 있습니다. 다른 사용자뿐만 아니라 루트 사용자를 사용하여 내 Linux 시스템에 로그인 할 수 있습니다. sqlyog를 사용하여 Windows 시스템에서 Linux 시스템의 mysql 데이터베이스에 연결할 수 있습니다. 이제 Linux 터미널 만 사용하여 Linux 컴퓨터에서 쿼리를 실행하고 싶습니다.

나는 터미널에서 다음과 같은 것들을 시도했습니다.

루트 디렉토리로 이동 한 다음 / var / lib 디렉토리로 이동했습니다.

터미널에서 다음 명령을 실행합니다.

mysqladmin -u root -p
mysqladmin -u root -ppassword

다음과 같은 오류 메시지가 나타날 때마다

오류 1045 (28000) 'root'@ 'localhost'사용자에 대한 액세스가 거부되었습니다 (암호 NO 사용).

다음을 안내 해주세요

  1. Linux 터미널에서 mysql 프롬프트를 어떻게 얻습니까?
  2. Linux 터미널에서 mysql 서버를 어떻게 중지합니까?
  3. Linux 터미널에서 mysql 서버를 시작하려면 어떻게해야합니까?
  4. Linux 터미널에서 mysql 프롬프트를 어떻게 얻습니까?
  5. Linux 터미널에서 mysql 서버에 어떻게 로그인합니까?
  6. 다음 오류를 어떻게 해결합니까?

오류 1045 (28000) 'root'@ 'localhost'사용자에 대한 액세스가 거부되었습니다 (암호 NO 사용).

위의 질문에 대한 해결책을 알려주십시오. 감사합니다


1.- Linux 터미널에서 mysql 프롬프트를 어떻게 얻습니까?

mysql -u root -p

상기 Enter password:프롬프트 아니라, 루트 암호를 입력 :

입력 mysql --help하거나 온라인 설명서 에서 추가 참조를 찾을 수 있습니다 .

2. Linux 터미널에서 mysql 서버를 중지하려면 어떻게해야합니까?

때에 따라 다르지. Red Hat 기반 배포판에는 다음 service명령이 있습니다.

service mysqld stop

다른 배포판은 init 스크립트를 직접 호출해야합니다.

/etc/init.d/mysqld stop

3. Linux 터미널에서 mysql 서버를 시작하려면 어떻게해야합니까?

# 2와 같지만 start.

4. 리눅스 터미널에서 mysql 프롬프트를 어떻게 얻습니까?

# 1과 동일합니다.

5. Linux 터미널에서 mysql 서버에 어떻게 로그인합니까?

# 1과 동일합니다.

6. 다음 오류는 어떻게 해결합니까?

# 1과 동일합니다.


첫 번째 질문에 :

mysql -u root -p

또는

mysqladmin -u root -p "your_command"

무엇을하고 싶은지에 따라. Enter 키를 누르면 비밀번호가 입력됩니다! 나는 당신이 정말로 mysqladmin이 아닌 mysql 을 사용하고 싶다고 생각합니다 .

Linux에서 MySQL 서버를 다시 시작하거나 중지하려면 설치에 따라 다르지만 일반적인 데비안 파생 제품에서는 서비스를 시작, 중지 및 다시 시작하는 데 작동합니다.

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

일부 최신 배포판에서는 MySQL이 데몬 / 서비스로 설정된 경우에도 작동 할 수 있습니다.

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

그러나 특정 설정을 알지 못하면 질문에 답하기가 정말 불가능합니다.


나는 당신이 mysql 클라이언트를 사용하려고한다고 가정한다. 이것은 좋은 일이고 어떤 phpMyAdmin 대안보다 훨씬 더 효율적이다.

명령 줄 클라이언트로 로그인하는 올바른 방법은 다음을 입력하는 것입니다.

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.


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.


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!


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


if you're already logged in as root just

mysql -u root

prompting the password will otherwise return as error


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


use this "mysql -uroot -pPassword"

참고URL : https://stackoverflow.com/questions/6200215/how-to-log-in-to-mysql-and-query-the-database-from-linux-terminal

반응형