database/mysql

[mysql] Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)

labj 2017. 8. 27. 13:10

[mysql] Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)


1. root 암호 설정

 - 먼저 mysqld_safe로 접속 가능하게 한다.

/usr/bin/mysqld_safe --skip-grant-tables &


 - mysql에 접속한다.

mysql -u root mysql


 - 암호 설정한다.

mysql> update mysql.user SET authentication_string=PASSWORD('password!') WHERE user='root';

Query OK, 1 row affected, 1 warning (0.00 sec)

Rows matched: 1  Changed: 1  Warnings: 1


mysql> flush privileges;

Query OK, 0 rows affected (0.00 sec)


mysql> exit

Bye


 - mysqld 서비스를 다시 시작한다. 

service mysqld restart


 - 서버 재시작

shutdown -r now



- 다시 재접속

mysql -u root -p


 - 유저 추가시에 오류 발생

ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.


 - 암호 대소문자,특수문자,숫자 넣어 복잡하게 만들어야 함 

ERROR 1819 (HY000): Your password does not satisfy the current policy requirements


mysql> SET PASSWORD = PASSWORD('***********');


mysql> use mysql

Reading table information for completion of table and column names

You can turn off this feature to get a quicker startup with -A


Database changed

mysql> create user 'jobtoy'@'%' identified by '********';

Query OK, 0 rows affected (0.00 sec)


mysql> grant all privileges on *.* to 'jobtoy'@'%';

Query OK, 0 rows affected (0.00 sec)


mysql> create user 'jobtoy'@'localhost' identified by '********';

Query OK, 0 rows affected (0.00 sec)


mysql> grant all privileges on *.* to 'jobtoy'@'localhost';

Query OK, 0 rows affected (0.00 sec)


mysql> create user 'jobtoy'@'127.0.0.1' identified by '********';

Query OK, 0 rows affected (0.00 sec)


mysql> grant all privileges on *.* to 'jobtoy'@'127.0.0.1';

Query OK, 0 rows affected (0.00 sec)