My Drive

[CentOS] CentOS7 MariaDB 5.5 설치 본문

linux

[CentOS] CentOS7 MariaDB 5.5 설치

sunnyeo.park 2016. 2. 18. 15:24

MariaDB 5.5 설치

>> yum -y install mariadb-server mariadb

>> systemctl start mariadb

>> systemctl enable mariadb


* mysql –u root –p 로 접속 안될시

- mysql –u root로 접속 후, use mysql;

- update user set password=password('**********') where user='root';

- flush privileges;



python connector 설치

>> yum install mysql-connector-python

---------------------------------------------------------------------------------------------------------------------------------

# import

import mysql.connector as mariadb


# 계정 연결 및 DB, TABLE 생성

con = mariadb.connect(user='root', password='*****')

cur = con.cursor()

cur.execute('CREATE DATABASE IF NOT EXISTS [DBNAME]') 

cur.execute('use [DBNAME]')

cur.execute('CREATE TABLE IF NOT EXISTS [TABLENAME] (IP_ADDR varchar(20) NOT NULL PRIMARY KEY, MAC_ADDR varchar(20) NOT NULL, DATE datetime NOT NULL)')


# select문 예시

query = "SELECT IP_ADDR from [TABLENAME] where MAC_ADDR=\"[MAC]\""

cur.execute(query)

if cur.fetchone() != None :

ip = cur.fetchone()[0]


# insert문 예시

query = "INSERT INTO [TABLENAME] VALUES (\"" + [IP] + "\", \"" + [MAC] + "\", \"" + [TIME] + "\")"

cur.execute(query)


# 종료

con.commit()

con.close()

---------------------------------------------------------------------------------------------------------------------------------



C connector 설치

>> http://dev.mysql.com/downloads/connector/c/ 에서 development libraries rpm 다운 (mysql-connector-c-devel-6.1.6-1.el7.x86_64.rpm)

>> rpm –i PACKAGE.rpm

>> yum install mysql-devel


* conflict 발생하면

- rpm -ev mysql-connector-c-devel


* 컴파일 옵션

- gcc -o [OUTPUT] [SOURCE] -I/usr/include/mysql -L/usr/lib64/mysql -lmysqlclient

---------------------------------------------------------------------------------------------------------------------------------

// include

# include <mysql.h>


// 계정 연결

con = mysql_init(NULL);

if (mysql_real_connect(con, HOSTNAME, USERNAME, PASSWORD, DBNAME, PORTNUM, SOCKNAME, 0) == NULL)

printf("[Err] connect to database : %s\n", mysql_error(con));


# select문 예시

int i, cnt;

char *query = "select IP_ADDR from [TABLENAME] where MAC_ADDR=\"[MAC]\""

if(mysql_query(con, query))

printf("[error]check ip %s\n", mysql_error(con));

result = mysql_store_result(con);

cnt = mysql_num_fields(result);

for(i=0; i<cnt; i++)

printf("%s ", row[i]);

---------------------------------------------------------------------------------------------------------------------------------


'linux' 카테고리의 다른 글

[CentOS] NFQUEUE 설치 및 설정  (0) 2016.02.18
[CentOS] CentOS7 웹서버 (http, https)  (0) 2016.02.18
[CentOS] CentOS7 Minimal 기본 설정  (0) 2016.02.18
시스템 문제 만들때  (0) 2014.09.29
[Ubuntu] 리눅스 설치 후  (0) 2014.09.29
Comments