centos 에서 mysql설치

  • systemddc
  • Linux
  • 1959
  • 0

centos 최신버전으로 업데이트 하기

1
$ yum update -y

 

mysql wget을 이용하여 다운로드하기

mysql 홈페에지에서 MySQL Community Server를 rpm 번들을 다운로드 할 수 있는 url을 얻어낸다.

참고로, yum을 이용하여 mysql을 설치 할 수 있지만, 최신버전이 아니다.

 

1
2
3
$ yum -y install wget
$ wget http://dev.mysql.com/get/Downloads/MySQL-5.6/MySQL-5.6.16-1.linux_glibc2.5.x86_64.rpm-bundle.tar
$ tar -xvf MySQL-5.6.16-1.linux_glibc2.5.x86_64.rpm-bundle.tar

 

mysql 설치

압축을 풀었다면, 그 안에는 여러개의 rpm이 존재하며, 

1
2
3
4
$ rpm -i MySQL-shared-5.6.16-1.linux_glibc2.5.x86_64.rpm
$ rpm -Uvh MySQL-shared-compat-5.6.16-1.linux_glibc2.5.x86_64.rpm
$ rpm -i MySQL-server-5.6.16-1.linux_glibc2.5.x86_64.rpm
$ rpm -i MySQL-client-5.6.16-1.linux_glibc2.5.x86_64.rpm

dependency error 인 경우 다음 모듈을 설치

1
2
3
4
5
6
7
8
9
error: Failed dependencies:
perl(DBI) is needed by MySQL-client
$ yum -y install perl
 
error: Failed dependencies:
        libaio.so.1()(64bit) is needed by MySQL-server-5.6.16-1.linux_glibc2.5.x86_64
        libaio.so.1(LIBAIO_0.1)(64bit) is needed by MySQL-server-5.6.16-1.linux_glibc2.5.x86_64
        libaio.so.1(LIBAIO_0.4)(64bit) is needed by MySQL-server-5.6.16-1.linux_glibc2.5.x86_64
$ yum -y install libaio

 

임시 비번 생성

1
2
$ cat /root/.mysql_secret
# The random password set for the root user at Tue Jul  1 12:05:13 2014 (local time): H1JVqRuc

 

mysql 실행

1
$ service mysql start

 

임시비번으로 mysql 로컬 연결

1
2
$ mysql -uroot -p
Enter password:H1JVqRuc

 

비번 변경

1
mysql> SET PASSWORD FOR 'root'@'localhost' = PASSWORD('12121212');

 

사용자 추가

 

1
2
3
mysql> CREATE USER 'your user name'@'%' IDENTIFIED BY 'your password';
mysql> GRANT ALL ON *.* TO 'your user name'@'%' WITH GRANT OPTION;
mysql> FLUSH PRIVILEGES;

 

utf-8설정

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
$ vi /etc/my.cnf
# 해당 내용을 추가한다.
 
[client]
default-character-set = utf8
 
[mysqld]
collation-server = utf8_unicode_ci
init-connect='SET NAMES utf8'
character-set-server = utf8
 
[mysqldump]
default-character-set = utf8
 
[mysql]
default-character-set = utf8

utf-8 설정되었는지 확인

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
$ service mysql restart
$ mysql -u root -p
mysql> show variables like '%char%';
+--------------------------+-----------------------------------------------+
| Variable_name            | Value                                         |
+--------------------------+-----------------------------------------------+
| character_set_client     | utf8                                          |
| character_set_connection | utf8                                          |
| character_set_database   | utf8                                          |
| character_set_filesystem | binary                                        |
| character_set_results    | utf8                                          |
| character_set_server     | utf8                                          |
| character_set_system     | utf8                                          |
| character_sets_dir       | /usr/share/mysql/charsets/                    |
+--------------------------+-----------------------------------------------+

방화벽 오픈

1
2
3
$ iptables -I INPUT 1 -p tcp --dport 3306 -j ACCEPT
$ service iptables save
$ service iptables restart