MariaDB에서 ERROR 2002 (HY000): Can't connect to local MySQL server 발생 시 해결책
# mysql
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)
OS는 CentOS 7, MariaDB 버전은 OS에 표준으로 번들 되어 있는 5.5.x 라고 전제로 합니다.
원래 mysqld가 시작되지 않았습니다.
ps -ef | grep -i mysqld
에서 mysqld가 실행 중인지 확인하십시오. 시작하지 않으면,
systemctl enable mariadb
systemctl start mariadb
를 실행해보십시오. 정상적으로 기동하고 있는 경우의 ps -ef | grep mysqld
의 출력은 이하와 같습니다.
# ps -ef|grep mysqld
mysql 2941 1 0 12:09 ? 00:00:00 /bin/sh /usr/bin/mysqld_safe --basedir=/usr
mysql 3103 2941 0 12:09 ? 00:00:00 /usr/libexec/mysqld --basedir=/usr --datadir=/var/lib/mysql --plugin-dir=/usr/lib64/mysql/plugin --log-error=/var/log/mariadb/mariadb.log --pid-file=/var/run/mariadb/mariadb.pid --socket=/var/lib/mysql/mysql.sock
root 3411 2449 0 12:27 pts/1 00:00:00 grep --color=auto mysqld
/var/lib/mysql 아래의 파일 소유자가 mysqld 실행 사용자 (mysql)가 아닙니다.
drwx------. 2 root root 6 May 20 12:07 test
drwx------. 2 root root 4096 May 20 12:07 mysql
drwx------. 2 root root 4096 May 20 12:07 performance_schema
-rw-rw----. 1 root root 52 May 20 12:07 aria_log_control
-rw-rw----. 1 root root 16384 May 20 12:07 aria_log.00000001
drwxr-xr-x. 5 mysql mysql 159 May 20 12:07 .
-rw-rw----. 1 mysql mysql 5242880 May 20 12:07 ib_logfile1
-rw-rw----. 1 mysql mysql 5242880 May 20 12:07 ib_logfile0
-rw-rw----. 1 mysql mysql 18874368 May 20 12:07 ibdata1
다음 명령을 실행해 보십시오.
chown -R mysql:mysql /var/lib/mysql
systemctl start mariadb
이것으로 mysql 커멘드로 접속할 수 있게 된다고 생각합니다.
# mysql
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 2
Server version: 5.5.56-MariaDB MariaDB Server
Copyright (c) 2000, 2017, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]>
firewall 설정에서 port 3306이 열리지 않음

AWS EC2의 경우 보안 그룹, GCE의 경우 firewall rule 등에서 tcp port 3306이 열려 있는지 확인합니다.
(덤) MariaDB 10.2로 업데이트
현재 최신 버전 10.2로 업데이트해 봅니다.
yum -y remove "mariadb*"
curl -sS https://downloads.mariadb.com/MariaDB/mariadb_repo_setup | sudo bash
yum -y install MariaDB-server
에러 로그가 출력되도록 mysqld 섹션에 log_error 를 설정합니다.
/etc/my.cnf.d/server.cnf[mysqld]
log_error
mariadb 서비스를 시작하면,
systemctl start mariadb
/var/lib/mysql/hostname.err에 오류 로그가 출력됩니다.
2018-05-20 12:37:04 139889543854272 [ERROR] Missing system table mysql.roles_mapping; please run mysql_upgrade to create it
mysql_upgrade를 실행하라는 메시지가 표시되므로 mysql_upgrade를 실행합니다.
# mysql_upgrade
Phase 1/7: Checking and upgrading mysql database
Processing databases
mysql
mysql.columns_priv OK
mysql.db OK
mysql.event OK
mysql.func OK
mysql.help_category OK
mysql.help_keyword OK
mysql.help_relation OK
mysql.help_topic OK
mysql.host OK
mysql.ndb_binlog_index OK
mysql.plugin OK
mysql.proc OK
mysql.procs_priv OK
mysql.proxies_priv OK
mysql.servers OK
mysql.tables_priv OK
mysql.time_zone OK
mysql.time_zone_leap_second OK
mysql.time_zone_name OK
mysql.time_zone_transition OK
mysql.time_zone_transition_type OK
mysql.user OK
Upgrading from a version before MariaDB-10.1
Phase 2/7: Installing used storage engines
Checking for tables with unknown storage engine
Phase 3/7: Fixing views
Phase 4/7: Running 'mysql_fix_privilege_tables'
Phase 5/7: Fixing table and database names
Phase 6/7: Checking and upgrading tables
Processing databases
information_schema
performance_schema
test
test.t1 OK
Phase 7/7: Running 'FLUSH PRIVILEGES'
OK
mariadb 서비스를 다시 시작합니다.
systemctl restart mariadb
/var/lib/mysql/server.error2018-05-20 12:47:05 140365761669312 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2018-05-20 12:47:05 140365761669312 [Note] InnoDB: Uses event mutexes
2018-05-20 12:47:05 140365761669312 [Note] InnoDB: Compressed tables use zlib 1.2.7
2018-05-20 12:47:05 140365761669312 [Note] InnoDB: Using Linux native AIO
2018-05-20 12:47:05 140365761669312 [Note] InnoDB: Number of pools: 1
2018-05-20 12:47:05 140365761669312 [Note] InnoDB: Using SSE2 crc32 instructions
2018-05-20 12:47:05 140365761669312 [Note] InnoDB: Initializing buffer pool, total size = 128M, instances = 1, chunk size = 128M
2018-05-20 12:47:05 140365761669312 [Note] InnoDB: Completed initialization of buffer pool
2018-05-20 12:47:05 140364988831488 [Note] InnoDB: If the mysqld execution user is authorized, page cleaner thread priority can be changed. See the man page of setpriority().
2018-05-20 12:47:05 140365761669312 [Note] InnoDB: Highest supported file format is Barracuda.
2018-05-20 12:47:05 140365761669312 [Note] InnoDB: 128 out of 128 rollback segments are active.
2018-05-20 12:47:05 140365761669312 [Note] InnoDB: Creating shared tablespace for temporary tables
2018-05-20 12:47:05 140365761669312 [Note] InnoDB: Setting file './ibtmp1' size to 12 MB. Physically writing the file full; Please wait ...
2018-05-20 12:47:05 140365761669312 [Note] InnoDB: File './ibtmp1' size is now 12 MB.
2018-05-20 12:47:05 140365761669312 [Note] InnoDB: Waiting for purge to start
2018-05-20 12:47:05 140365761669312 [Note] InnoDB: 5.7.22 started; log sequence number 1624410
2018-05-20 12:47:05 140364748936960 [Note] InnoDB: Loading buffer pool(s) from /var/lib/mysql/ib_buffer_pool
2018-05-20 12:47:05 140364748936960 [Note] InnoDB: Buffer pool(s) load completed at 180520 12:47:05
2018-05-20 12:47:05 140365761669312 [Note] Plugin 'FEEDBACK' is disabled.
2018-05-20 12:47:05 140365761669312 [Note] Server socket created on IP: '::'.
2018-05-20 12:47:05 140365761669312 [Note] Reading of all Master_info entries succeded
2018-05-20 12:47:05 140365761669312 [Note] Added new Master_info '' to hash table
2018-05-20 12:47:05 140365761669312 [Note] /usr/sbin/mysqld: ready for connections.
Version: '10.2.15-MariaDB' socket: '/var/lib/mysql/mysql.sock' port: 3306 MariaDB Server
mysql_upgrade로 각 테이블을 업데이트하여 오류가 발생하지 않습니다.
Reference
이 문제에 관하여(MariaDB에서 ERROR 2002 (HY000): Can't connect to local MySQL server 발생 시 해결책), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다
https://qiita.com/cherubim1111/items/faa6f7106e2d73dd4224
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념
(Collection and Share based on the CC Protocol.)
ps -ef | grep -i mysqld
systemctl enable mariadb
systemctl start mariadb
# ps -ef|grep mysqld
mysql 2941 1 0 12:09 ? 00:00:00 /bin/sh /usr/bin/mysqld_safe --basedir=/usr
mysql 3103 2941 0 12:09 ? 00:00:00 /usr/libexec/mysqld --basedir=/usr --datadir=/var/lib/mysql --plugin-dir=/usr/lib64/mysql/plugin --log-error=/var/log/mariadb/mariadb.log --pid-file=/var/run/mariadb/mariadb.pid --socket=/var/lib/mysql/mysql.sock
root 3411 2449 0 12:27 pts/1 00:00:00 grep --color=auto mysqld
drwx------. 2 root root 6 May 20 12:07 test
drwx------. 2 root root 4096 May 20 12:07 mysql
drwx------. 2 root root 4096 May 20 12:07 performance_schema
-rw-rw----. 1 root root 52 May 20 12:07 aria_log_control
-rw-rw----. 1 root root 16384 May 20 12:07 aria_log.00000001
drwxr-xr-x. 5 mysql mysql 159 May 20 12:07 .
-rw-rw----. 1 mysql mysql 5242880 May 20 12:07 ib_logfile1
-rw-rw----. 1 mysql mysql 5242880 May 20 12:07 ib_logfile0
-rw-rw----. 1 mysql mysql 18874368 May 20 12:07 ibdata1
다음 명령을 실행해 보십시오.
chown -R mysql:mysql /var/lib/mysql
systemctl start mariadb
이것으로 mysql 커멘드로 접속할 수 있게 된다고 생각합니다.
# mysql
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 2
Server version: 5.5.56-MariaDB MariaDB Server
Copyright (c) 2000, 2017, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]>
firewall 설정에서 port 3306이 열리지 않음

AWS EC2의 경우 보안 그룹, GCE의 경우 firewall rule 등에서 tcp port 3306이 열려 있는지 확인합니다.
(덤) MariaDB 10.2로 업데이트
현재 최신 버전 10.2로 업데이트해 봅니다.
yum -y remove "mariadb*"
curl -sS https://downloads.mariadb.com/MariaDB/mariadb_repo_setup | sudo bash
yum -y install MariaDB-server
에러 로그가 출력되도록 mysqld 섹션에 log_error 를 설정합니다.
/etc/my.cnf.d/server.cnf[mysqld]
log_error
mariadb 서비스를 시작하면,
systemctl start mariadb
/var/lib/mysql/hostname.err에 오류 로그가 출력됩니다.
2018-05-20 12:37:04 139889543854272 [ERROR] Missing system table mysql.roles_mapping; please run mysql_upgrade to create it
mysql_upgrade를 실행하라는 메시지가 표시되므로 mysql_upgrade를 실행합니다.
# mysql_upgrade
Phase 1/7: Checking and upgrading mysql database
Processing databases
mysql
mysql.columns_priv OK
mysql.db OK
mysql.event OK
mysql.func OK
mysql.help_category OK
mysql.help_keyword OK
mysql.help_relation OK
mysql.help_topic OK
mysql.host OK
mysql.ndb_binlog_index OK
mysql.plugin OK
mysql.proc OK
mysql.procs_priv OK
mysql.proxies_priv OK
mysql.servers OK
mysql.tables_priv OK
mysql.time_zone OK
mysql.time_zone_leap_second OK
mysql.time_zone_name OK
mysql.time_zone_transition OK
mysql.time_zone_transition_type OK
mysql.user OK
Upgrading from a version before MariaDB-10.1
Phase 2/7: Installing used storage engines
Checking for tables with unknown storage engine
Phase 3/7: Fixing views
Phase 4/7: Running 'mysql_fix_privilege_tables'
Phase 5/7: Fixing table and database names
Phase 6/7: Checking and upgrading tables
Processing databases
information_schema
performance_schema
test
test.t1 OK
Phase 7/7: Running 'FLUSH PRIVILEGES'
OK
mariadb 서비스를 다시 시작합니다.
systemctl restart mariadb
/var/lib/mysql/server.error2018-05-20 12:47:05 140365761669312 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2018-05-20 12:47:05 140365761669312 [Note] InnoDB: Uses event mutexes
2018-05-20 12:47:05 140365761669312 [Note] InnoDB: Compressed tables use zlib 1.2.7
2018-05-20 12:47:05 140365761669312 [Note] InnoDB: Using Linux native AIO
2018-05-20 12:47:05 140365761669312 [Note] InnoDB: Number of pools: 1
2018-05-20 12:47:05 140365761669312 [Note] InnoDB: Using SSE2 crc32 instructions
2018-05-20 12:47:05 140365761669312 [Note] InnoDB: Initializing buffer pool, total size = 128M, instances = 1, chunk size = 128M
2018-05-20 12:47:05 140365761669312 [Note] InnoDB: Completed initialization of buffer pool
2018-05-20 12:47:05 140364988831488 [Note] InnoDB: If the mysqld execution user is authorized, page cleaner thread priority can be changed. See the man page of setpriority().
2018-05-20 12:47:05 140365761669312 [Note] InnoDB: Highest supported file format is Barracuda.
2018-05-20 12:47:05 140365761669312 [Note] InnoDB: 128 out of 128 rollback segments are active.
2018-05-20 12:47:05 140365761669312 [Note] InnoDB: Creating shared tablespace for temporary tables
2018-05-20 12:47:05 140365761669312 [Note] InnoDB: Setting file './ibtmp1' size to 12 MB. Physically writing the file full; Please wait ...
2018-05-20 12:47:05 140365761669312 [Note] InnoDB: File './ibtmp1' size is now 12 MB.
2018-05-20 12:47:05 140365761669312 [Note] InnoDB: Waiting for purge to start
2018-05-20 12:47:05 140365761669312 [Note] InnoDB: 5.7.22 started; log sequence number 1624410
2018-05-20 12:47:05 140364748936960 [Note] InnoDB: Loading buffer pool(s) from /var/lib/mysql/ib_buffer_pool
2018-05-20 12:47:05 140364748936960 [Note] InnoDB: Buffer pool(s) load completed at 180520 12:47:05
2018-05-20 12:47:05 140365761669312 [Note] Plugin 'FEEDBACK' is disabled.
2018-05-20 12:47:05 140365761669312 [Note] Server socket created on IP: '::'.
2018-05-20 12:47:05 140365761669312 [Note] Reading of all Master_info entries succeded
2018-05-20 12:47:05 140365761669312 [Note] Added new Master_info '' to hash table
2018-05-20 12:47:05 140365761669312 [Note] /usr/sbin/mysqld: ready for connections.
Version: '10.2.15-MariaDB' socket: '/var/lib/mysql/mysql.sock' port: 3306 MariaDB Server
mysql_upgrade로 각 테이블을 업데이트하여 오류가 발생하지 않습니다.
Reference
이 문제에 관하여(MariaDB에서 ERROR 2002 (HY000): Can't connect to local MySQL server 발생 시 해결책), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다
https://qiita.com/cherubim1111/items/faa6f7106e2d73dd4224
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념
(Collection and Share based on the CC Protocol.)
현재 최신 버전 10.2로 업데이트해 봅니다.
yum -y remove "mariadb*"
curl -sS https://downloads.mariadb.com/MariaDB/mariadb_repo_setup | sudo bash
yum -y install MariaDB-server
에러 로그가 출력되도록 mysqld 섹션에 log_error 를 설정합니다.
/etc/my.cnf.d/server.cnf
[mysqld]
log_error
mariadb 서비스를 시작하면,
systemctl start mariadb
/var/lib/mysql/hostname.err에 오류 로그가 출력됩니다.
2018-05-20 12:37:04 139889543854272 [ERROR] Missing system table mysql.roles_mapping; please run mysql_upgrade to create it
mysql_upgrade를 실행하라는 메시지가 표시되므로 mysql_upgrade를 실행합니다.
# mysql_upgrade
Phase 1/7: Checking and upgrading mysql database
Processing databases
mysql
mysql.columns_priv OK
mysql.db OK
mysql.event OK
mysql.func OK
mysql.help_category OK
mysql.help_keyword OK
mysql.help_relation OK
mysql.help_topic OK
mysql.host OK
mysql.ndb_binlog_index OK
mysql.plugin OK
mysql.proc OK
mysql.procs_priv OK
mysql.proxies_priv OK
mysql.servers OK
mysql.tables_priv OK
mysql.time_zone OK
mysql.time_zone_leap_second OK
mysql.time_zone_name OK
mysql.time_zone_transition OK
mysql.time_zone_transition_type OK
mysql.user OK
Upgrading from a version before MariaDB-10.1
Phase 2/7: Installing used storage engines
Checking for tables with unknown storage engine
Phase 3/7: Fixing views
Phase 4/7: Running 'mysql_fix_privilege_tables'
Phase 5/7: Fixing table and database names
Phase 6/7: Checking and upgrading tables
Processing databases
information_schema
performance_schema
test
test.t1 OK
Phase 7/7: Running 'FLUSH PRIVILEGES'
OK
mariadb 서비스를 다시 시작합니다.
systemctl restart mariadb
/var/lib/mysql/server.error
2018-05-20 12:47:05 140365761669312 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2018-05-20 12:47:05 140365761669312 [Note] InnoDB: Uses event mutexes
2018-05-20 12:47:05 140365761669312 [Note] InnoDB: Compressed tables use zlib 1.2.7
2018-05-20 12:47:05 140365761669312 [Note] InnoDB: Using Linux native AIO
2018-05-20 12:47:05 140365761669312 [Note] InnoDB: Number of pools: 1
2018-05-20 12:47:05 140365761669312 [Note] InnoDB: Using SSE2 crc32 instructions
2018-05-20 12:47:05 140365761669312 [Note] InnoDB: Initializing buffer pool, total size = 128M, instances = 1, chunk size = 128M
2018-05-20 12:47:05 140365761669312 [Note] InnoDB: Completed initialization of buffer pool
2018-05-20 12:47:05 140364988831488 [Note] InnoDB: If the mysqld execution user is authorized, page cleaner thread priority can be changed. See the man page of setpriority().
2018-05-20 12:47:05 140365761669312 [Note] InnoDB: Highest supported file format is Barracuda.
2018-05-20 12:47:05 140365761669312 [Note] InnoDB: 128 out of 128 rollback segments are active.
2018-05-20 12:47:05 140365761669312 [Note] InnoDB: Creating shared tablespace for temporary tables
2018-05-20 12:47:05 140365761669312 [Note] InnoDB: Setting file './ibtmp1' size to 12 MB. Physically writing the file full; Please wait ...
2018-05-20 12:47:05 140365761669312 [Note] InnoDB: File './ibtmp1' size is now 12 MB.
2018-05-20 12:47:05 140365761669312 [Note] InnoDB: Waiting for purge to start
2018-05-20 12:47:05 140365761669312 [Note] InnoDB: 5.7.22 started; log sequence number 1624410
2018-05-20 12:47:05 140364748936960 [Note] InnoDB: Loading buffer pool(s) from /var/lib/mysql/ib_buffer_pool
2018-05-20 12:47:05 140364748936960 [Note] InnoDB: Buffer pool(s) load completed at 180520 12:47:05
2018-05-20 12:47:05 140365761669312 [Note] Plugin 'FEEDBACK' is disabled.
2018-05-20 12:47:05 140365761669312 [Note] Server socket created on IP: '::'.
2018-05-20 12:47:05 140365761669312 [Note] Reading of all Master_info entries succeded
2018-05-20 12:47:05 140365761669312 [Note] Added new Master_info '' to hash table
2018-05-20 12:47:05 140365761669312 [Note] /usr/sbin/mysqld: ready for connections.
Version: '10.2.15-MariaDB' socket: '/var/lib/mysql/mysql.sock' port: 3306 MariaDB Server
mysql_upgrade로 각 테이블을 업데이트하여 오류가 발생하지 않습니다.
Reference
이 문제에 관하여(MariaDB에서 ERROR 2002 (HY000): Can't connect to local MySQL server 발생 시 해결책), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://qiita.com/cherubim1111/items/faa6f7106e2d73dd4224텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념
(Collection and Share based on the CC Protocol.)