비밀번호 없이 Linux 루트 사용자 mysql 루트 액세스 허용

비밀번호 없이 Linux 루트 사용자 mysql 루트 액세스 허용

cPanel에서 루트로 로그인하고 호스트 이름과 비밀번호 없이 "mysql"을 입력하면 mysql 루트 사용자에 직접 액세스할 수 있습니다.

Linux 루트 사용자가 cPanel에서와 동일한 방식으로 mysql 루트 사용자에 대한 암호 없이 로그온하는 비 cpanel 서버 중 하나에 대해 이 작업을 수행하고 싶습니다.

이것이 가능한가 ?

답변1

이를 수행하는 가장 쉬운 방법은 ~/.my.cnf 파일의 클라이언트 섹션을 사용하고 거기에 자격 증명을 추가하는 것입니다.

[client]
user=root
password=somepassword
...

해당 파일을 루트만 읽을 수 있도록 만드는 것도 좋은 생각입니다.

답변2

mysql 5.7+의 경우 초기 설정 시 빈 비밀번호를 설정하면 mysql이 자동 auth_socket으로 전략으로 사용됩니다. 전략을 변경하지 않고 비밀번호를 업데이트하려고 시도하면 결과가 없습니다. 귀하의 사용자가 인 경우 언제든지 비밀번호를 사용하지 않고 로그인할 수 있습니다 root.

해결책 다음 명령을 실행하여 인증 전략을 변경하고 비밀번호를 설정하세요.

ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY ''

참조:https://www.percona.com/blog/2016/03/16/change-user-password-in-mysql-5-7-with-plugin-auth_socket/

답변3

MySQL 5.6.6부터는 mysql_config_editor를 사용하여 자동으로 로그인할 암호화된 파일을 생성할 수 있습니다.

mysql_config_editor set --login-path=client --host=localhost --user=root --password

그런 다음 메시지가 나타나면 비밀번호를 입력하세요.

참고: 비밀번호에 '#'이 포함되어 있고 다른 문자도 있을 수 있으면 비밀번호를 입력할 때 작은따옴표를 사용하세요.

답변4

mysql 루트 비밀번호만 포함하고 루트만 읽을 수 있는 파일을 만듭니다.

# ls -l /root/.mysqlpw 
-rw------- 1 root root 7 2013-08-19 13:24 /root/.mysqlpw

다음을 사용하여 데이터베이스를 가져올 수 있습니다.

# mysql -u root -p`cat /root/.mysqlpw ` yourdatabase < databasedump.sql

또는 데이터베이스에 연결하고 mysql 명령을 실행하십시오.

# mysql -u root -p`cat /root/.mysqlpw ` yourdatabase
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 20460
Server version: 5.1.63-0ubuntu0.10.04.1 (Ubuntu)

Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| yourdatabase       |
+--------------------+
3 rows in set (0.00 sec)

mysql> show tables;
...

관련 정보