Centos6.7 編譯安裝 MySQL資料庫

# 安裝依賴包
[root@localhost ~]# yum -y install gcc gcc-c++  autoconf* automake* zlib* libxml* ncurses-devel ncurses libgcrypt* libtool* cmake openssl openssl-devel bison bison-devel unzip wget

# 進入指定目錄下載
[root@localhost ~]# cd /usr/local/src
[root@localhost ~]# wget https://cdn.mysql.com//Downloads/MySQL-5.6/mysql-5.6.27.tar.gz

# 添加mysql運行賬戶
[root@localhost ~]# /usr/sbin/groupadd mysql
[root@localhost ~]# /usr/sbin/useradd mysql -g mysql -s /sbin/nologin -M

# 解壓下載源碼包
[root@localhost src]# tar zxvf mysql-5.6.27.tar.gz
[root@localhost src]# cd mysql-5.6.27

# 編譯三步曲
[root@localhost mysql-5.6.27]# cmake \
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DMYSQL_DATADIR=/data/mysql \
-DSYSCONFDIR=/etc \
-DWITH_MYISAM_STORAGE_ENGINE=1 \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_MEMORY_STORAGE_ENGINE=1 \
-DWITH_READLINE=1 \
-DMYSQL_UNIX_ADDR=/var/lib/mysql/mysql.sock \
-DMYSQL_TCP_PORT=3306 \
-DENABLED_LOCAL_INFILE=1 \
-DWITH_PARTITION_STORAGE_ENGINE=1 \
-DEXTRA_CHARSETS=all \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci

[root@localhost mysql-5.6.27]# make && make install

# 復制mysql配置文件
[root@localhost mysql-5.6.27]# cp -rf support-files/my-default.cnf /etc/my.cnf

# 復制myssql啟動管理文件
[root@localhost mysql-5.6.27]# cp support-files/mysql.server /etc/init.d/mysqld

# 賦權限
[root@localhost ~]# chmod 755 /etc/init.d/mysqld

# 添加開機啟動
[root@localhost ~]# chkconfig --level 345 mysqld on

# 創建資料庫存放目錄
[root@localhost ~]# mkdir -p /data/mysql

# 給資料庫目錄權限賦給mysql用戶
[root@localhost ~]# chown -R mysql:mysql /usr/local/mysql
[root@localhost ~]# chown -R mysql:mysql /data/mysql

[root@localhost ~]# cd /usr/local/mysql
[root@localhost ~]# ln -s /usr/local/mysql/bin/* /usr/sbin/

# 資料庫初始化
[root@localhost ~]# /usr/local/mysql/scripts/mysql_install_db --basedir=/usr/local/mysql --user=mysql --datadir=/data/mysql

# 啟動資料庫
[root@localhost ~]# /etc/init.d/mysqld start、

# 對數據賬戶進行基本安全設置
[root@localhost ~]# mysql_secure_installation

You May Also Like