mysqld_safe Directory ‘/var/run/mysqld’ for UNIX socket file don’t exists.

Published on  Author JFLeave a comment

This is about resetting the MySQL 5.7 root password in Ubuntu 16.04 LTS

You probably tried something like this:

sudo service mysql stop
mysqld_safe --skip-grant-tables &

And then got something like this (stangely, exists is misspelled in the output):

[1] 5599
2018-03-02T21:36:41.292413Z mysqld_safe Logging to syslog.
2018-03-02T21:36:41.294798Z mysqld_safe Logging to '/var/log/mysql/error.log'.
2018-03-02T21:36:41.296902Z mysqld_safe Directory '/var/run/mysqld' for UNIX socket file don't exists.

Then you tried to find the socket (takes a while):

sudo find / -type s

And /var/run/mysqld does not exist.

So you start mysql again and search and now it does exist!

sudo service mysql start
sudo find / -type s

[output:]
/run/mysqld/mysqld.sock
/run/dbus/system_bus_socket
/run/acpid.socket
/run/snapd-snap.socket
...

My guess is that mysql_safe can’t create the directory (which appears to be dynamically created when mysql starts). Solution:

sudo mkdir /var/run/mysqld 
sudo chown mysql:mysql /var/run/mysqld

Now run:

sudo service mysql stop
mysqld_safe --skip-grant-tables &
mysql -uroot mysql

--해결,

혹 아래와같은 문제가생긴다면 


When you get to the mysql prompt (don’t forget to change your pw before copy/pasting!!!):

UPDATE mysql.user SET authentication_string=PASSWORD('YOURNEWPASSWORD'), plugin='mysql_native_password' WHERE User='root' AND Host='%';

exit;

then

sudo mysqladmin -S /var/run/mysqld/mysqld.sock shutdown
sudo service mysql start

OTHER SOLUTION (means restarting MySQL a couple times!):

Note: in MySQL 5.7 you may find that my.cnf actually references config files elsewhere:

!includedir /etc/mysql/conf.d/
!includedir /etc/mysql/mysql.conf.d/

So in my case:

sudo nano /etc/mysql/mysql.conf.d/mysqld.cnf

Under [mysqld] add:

skip-grant-tables

Close the file and restart mysql, then…

sudo service mysql restart
sudo mysql -uroot mysql
(use query above...)

Edit mysqld.conf again, remove the line, then restart MySQL

sudo service mysql restart

Good luck!



백업
MySQL 데이터를 백업하는 방법은 크게 물리적 백업과 논리적 백업이 있다. 

1. 물리적 백업
 - 물리적 백업은 MySQL DB의 물리 파일을 백업하는 것이다. 
 - 장점 
  + 물리적 백업은 속도가 빠르며 작업이 단순하다.
 - 단점
  + InnoDB의 물리적 파일은 상응하는 논리 백업에 비해 상당히 크다.
  + 데이터 복구시에 문제가 발생할 소지가 있으면 문제발생시 원인파악 및 해결이 어렵다.

2. 논리적 백업
 - 논리적 백업은 mysqldump 혹은 기타 툴을 이용해서 SQL문을 갖는 텍스트 파일을 생성하는 것이다. 
 - 장점 
  + 논리적 백업은 데이터를 검토할 수 있다.
  + 복원작업이 수월하며, 물리적 백업에 비해 복원시 데이터 손상을 막아주며, 문제 발생시 원인 파악및 해결하기가 수월하다. 
 - 단점
  + 백업/복원시 시스템 리소스를 더 많이 소모한다. (물리적 백업은 파일 copy만 하면 되니까!!!)
  + 부동 소수점 데이터의 백업&복원시 데이터 정확성을 잃게 될 수 있다.

3. mysqldump 사용법
 $ mysqldump -u[userId] -p[password] --all-databases > dump.sql  // 서버에 있는 모든 것의 논리 백업 생성
 $ mysqldump -u[userId] -p[password] --databases [DB명] > dump.sql // 특정 데이터베이스만의 논리 백업 생성
 $ mysqldump -u[userId] -p[password] [DB명] [테이블명]

 
- 기타 옵션
   -A, --all-databases : 모든 DB 덤프
   -B, --databases : 특정 DB를 덤프

   --opt : 버퍼링을 비확성화 하고, 많은 데이터를 덤프에 있는 소량의 SQL구문에 기록해 더효율적으로 동작하다록 한다.
   --allow-keywords, --quote-names : 예약어를 사용하는 테이블을 덤프하고 복원할 수 있게 한다.
   --lock-alltables : 전역적으로 일관된 백업을 만들도록 "FLUSH TABLES WITH READ LOCK"을 사용한다. 
   --tab : "SELECT INTO OUTFILE"로 파일을 덤프하여, 덤프 및 복원 속도가 매우 빠르다.
   -d, --no-data :  데이터는 제외하고 스키마만 덤프
   -t, --no-create-info : 스키마는 제외하고 

4. dump 파일 복원 방법
 - mysql -u [userId] -p [password] [DB명] < dump.sql
 - mysql 접속한 후 아래의 명령 실행
     mysql> source dump.sql

출처 : http://dimdim.tistory.com/entry/MySQL-%EB%B0%B1%EC%97%85-%EB%B0%8F-%EB%B3%B5%EA%B5%AC


사용자를 추가하기 위해서는 반드시 루트 계정이 있어야 한다.

1. grant all privileges on *.* to 'testuser'@'localhost'

   identified by '설정패스워스' with grant option;

2. grant all privileges on *.* to 'testuser'@'%'

   identified by '설정패스워스' with grant option;

3. grant reload,process on *.* to 'testuser'@'locahost';

4. grant usage on *.* to 'testuser'@'locahost';

1번과 2번의 경우는 슈퍼 계정!! root와 같은 모든 권한을 가지는 계정을 가지게 된다.

1번 계정은 로컬호스트에서 접속을 할 경우에만 사용되는것이고,

2번 계정은 다른 호스트에서 접속을 하기 위해 사용된다.

testuser란 계정으로 어디에서든지 접속을 하려면 testuser이름으로 1,2번 계정을 모두 가지고 있는 것이 필요하다.

3번 계정은 패스워드가 정의되어있지 않다.

이것은 로컬호스트에서 reload와 process관리 권한을 가지고있다.

mysqladmin reload,mysqladmin refresh, mysqladmin flush-xxx, mysqladmin processlist 도 실행할수 있다고 한다. 하지만 어떤 데이터 베이스에도 접급할수있는 권한은 없다!

나중에 grant명령문을 입력하새ㅓ 권한을 추가할수도 있다.

4번 계정은 3번가 마찬가지 이지만 아무런 권한이 없는 계정을 만든것이다.

USAGE가 그런 뜻을 의미하는데, 이것은 모든 글로번 권한을  'N'으로 설정한 것이라고 한다.

이계정에 특정 권한을 나중에 승인할 것이라는 가정을 한다.

계정을 생성하는 또 한가지 방법은 INSERT 문을 사용하는 것이다.

1. insert into user values('locahost','계정명',password('패스워드'),

   'y','y','y','y','y','y','y','y','y','y','y','y','y','y','y','y');

2. insert into user values('%','계정명',password('패스워드'),

   'y','y','y','y','y','y','y','y','y','y','y','y','y','y','y','y');

3. insert into user set Host='locahost',User='계정명',Reload_priv='y',Process_priv='y';

4. insert into user(Host,User,Password) values('locahost','계정명','');

5. flush privileges;

1,2,3,4번 계정의 의미는 위에서 grant를 이용하여 만든 계정과 의미가 같다.

5번의 flush privileges; 는 서버가 grant 테이블을 다시 읽어 오도록 만들기 위해서 이다.

그렇지 않으면 서버를 재 구동 시키기 전에는 변경 사항이 적용되지 않는다.

하지만 grant를 사용하는 경우는 flush pricileges가 필요 없다.

1,2번의 insert문의 패스워드 입력에서 password('패스워드')라고 사용한것은 패스워드를 암호화 하기 위해서 이다. grant명령문은 알아서 암호화가 된다!

이번에는 데이터베이스 접근 권한을 설정해보자.

1. grant select, insert, update, delete, create, drop

   on bankaccount.*

   to 'custom'@'localhost'

   identified by 'obscure';

2. grant select, insert, update, delete, create, drop

   on expenses.*

   to 'custom'@'whitehouse.gov'

   identified by 'obscure';

3. grant select, insert, update, delete, create, drop

   on customer.*

   to 'custom'@'server.domain'

   identified by 'obscure';

1번 계정은 bankaccount 데이터 베이스에 접근할 수는 있으나, 로컬 호스트에서만 가능하다.

2번 계정은 expenses 데이터 베이스에 접근할 수 있으나, 호스트 whitehouse.gov에서만 가능하다.

3번 계정은 customer 데이터 베이스에 접근할 수 있으나, server.domain에서만 가능하다.

insert를 사용한 방법.

1-1. insert into user(Host,User,Password) values('locahost','custom',password('obscure'));

1-2. insert into user(Host,User,Password) values('whitehouse.gov','custom',password('obscure'));

1-3. insert into user(Host,User,Password) values('server.domain','custom',password('obscure'));

2-1. insert into db

     (Host,Db,User,Select_priv,Insert_priv,Update_priv,Delete_pric,Create_pric,Drop_pric)

     values('localhost','bankaccount','custom','y','y','y','y','y','y');

2-2. insert into db

     (Host,Db,User,Select_priv,Insert_priv,Update_priv,Delete_pric,Create_pric,Drop_pric)

     values('whitehouse.goc','expenses','custom','y','y','y','y','y','y');

2-3. insert into db

     (Host,Db,User,Select_priv,Insert_priv,Update_priv,Delete_pric,Create_pric,Drop_pric)

     values('server.domain','customer','custom','y','y','y','y','y','y');

flush privileges;

이것도 마찬가지로 flush pricileges; 를 반드시 해줘야 적용이 된다~

한가지 팁이라면... % 와일드 카드 문자를 사용하여 grant명령문을 입력하면 모든 곳에서 허용이 된다.

예) grant ... on *.* to 'user'@'%.mydomain.com' identified by 'myboss';

   (이렇게 하면 .mydomain.com앞에  뭐가 붙어서 오든지 허용이 된다는 뜻.)

    grant ... on test_%.* to ... identified by ...;

   (이건 데이터베이스 이름이 test_ 로 시작하는 모든것에 사용권한을 부여한다는 뜻이다.)

 원본 레퍼런스 참조.

 

mysql 실행

>mysql -u 계정명 -p 

>비밀번호


>show databases;

>use 데이터베이스명;

>show tables;

>select 속성1, 속성2, ...., 속성n from 테이블명;

>select * from 테이블명;


사용자 계정 추가

>use mysql;

>insert into user(host,user,password) values('localhost','계정명',password('비밀번호'));로컬접근 허용

>insert into user(host,user,password) values('%','계정명',password('비밀번호'));외부접근 허용

>flush privileges;


db 생성후 db에 계정연결

>grant all privileges on DB명.* to 계정명@localhost identified by '비밀번호' with grant option;

>flush privileges;



- 특정 사용자의 외부접근을 허용 (이미 만들어진 계정에서)

>update user set host='%' where host='localhost' and user='계정명';

>flush privileges;

http://falseisnotnull.wordpress.com/2012/10/31/did-you-lose-your-mariadb-root-password-gnulinux/


Did you lose your MariaDB root password? (GNU/Linux)

Don’t even think to drastical solutions. If you can log into GNU/Linux as root, you can always recover MariaDB root password.

Did you never know the password?

Maybe you installed MariaDB, or you bought a new server, but you don’t know the root password. Don’t panic! It’s ok!

Probably there is no password. Well, this is false; MariaDB asks for a password, and you won’t be able to logon if the password is incorrect; but the password is an empty string. On the CLI, just press enter to access.

Change it: it is insecure. If I had to break into a MariaDB/MySQL installation as root, I would first try an empty password. Don’t let me break into your system so easily!

Ok, you lost the password

Ok, you lost it. This is not the simplest case, but… it’s simple!

1) Log into your GNU/Linux system as the user used by MySQL (usually ‘mysql’) or root.

2) Restart MariaDB with the grant tables disabled:
mysqld_safe --skip-grant-tables --skip-networking

mysqld_safe will shut down mysqld for you.
With --skip-grant-tables, no password is needed to logon.
This is unsafe, so until the password is reset MariaDB should not accept network connections (--skip-networking).

3) Logon with no password:
mysql -u root

4) Set your new password.

Exec these 2 SQL statements and exit the client:

-- change pwd
UPDATE `mysql`.`user`
	SET `Password` = PASSWORD('new_password')
	WHERE `User` = 'root';
-- tell the server to read the grant tables
FLUSH PRIVILEGES;
\quit

(replace ‘new_password’ with the new password)

5) Stop mysqld_safe and restart mysqld:

mysqladmin shutdown
/etc/init.d/mysql start

(depending from your system, you may need to replace ‘/etc/init.d‘ with the correct MySQL path)

6) Logoff from you system (because you are now root or someone very powerful).


Mysql 사용중 한글깨짐 현상이 발생시 해결법 ( Ubuntu 12.10 환경에서 작동됨 )


$cd /etc/mysql/my.cnf

항상 백업필수!, 원본 my.cnf를 백업해둔다.

$sudo cp /etc/mysql/my.cnf /etc/mysql/my.cnf.orig
$sudo vi my.cnf

이후 각 영역마다 아래 코드 추가

[client]
default-character-set = utf8
[mysqld] character-set-server=utf8 collation-server=utf8_general_ci init_connect="set collation_connection=utf8_general_ci" init_connect="set names utf8" character-set-client-handshake=TRUE skip-character-set-client-handshake [mysqldump] default-character-set = utf8

저장 후 Mysql 재시작

$sudo /etc/init.d/mysql restart

설정 후 확인은

$mysql -u root -p 
mysql>status
mysql>show variables like 'char%';

설정 후에도 한글이 여전히 깨지는데, 테이블 설정도 변경해면, 잘된다.ㅋ (''는 빼고 명령어 입력)

mysql>ALTER TABLE '디비명'.'테이블명' MODIFY COLUMN `Column이름` VARCHAR(20) CHARACTER SET utf8 COLLATE utf8_general_ci;

+ Recent posts