CentOS7 編譯安裝MySQL5.6.38

1. 下載MySQL5.6.38安裝包mysql

下載地址:https://www.mysql.com/downloads/  打開網站以後選擇Archiveslinux

而後再選擇開源版本c++

選擇咱們要下載的版本sql

2. 編譯安裝MySQL5.6.38數據庫

# cat /etc/redhat-release 
CentOS Linux release 7.2.1511 (Core)

# 建立系統賬號
# groupadd -r mysql
# useradd -r -g mysql -s /sbin/nologin mysql

# 關閉SELinux
# setenforce 0
# sed -i 's#SELINUX=enforcing#SELINUX=disabled#g' /etc/selinux/config

# 安裝依賴包
# yum install ncurses-devel libaio-devel -y
# yum install cmake gcc gcc-c++ make autoconf -y

# 上面若是沒有下載安裝包,可直接wget下載
# wget https://cdn.mysql.com/archives/mysql-5.6/mysql-5.6.38.tar.gz

# tar xf mysql-5.6.38.tar.gz 
# cd mysql-5.6.38/

# 進行編譯安裝
 [ ~/mysql-5.6.38]# cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql-5.6.38 \         # 指定安裝目錄
-DMYSQL_DATADIR=/usr/local/mysql-5.6.38/data \                                       # 指定數據目錄
-DMYSQL_UNIX_ADDR=/usr/local/mysql-5.6.38/mysql.sock \                               # 指定sock文件位置
-DDEFAULT_CHARSET=utf8 \                                                             # 默認字符集
-DDEFAULT_COLLATION=utf8_general_ci \                                                # 默認編碼
-DWITH_EXTRA_CHARSETS=all \                                                          # 其它額外字符集
-DWITH_INNOBASE_STORAGE_ENGINE=1 \                                                   # 支持的存儲引擎
-DWITH_FEDERATED_STORAGE_ENGINE=1 \
-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
-DWITHOUT_EXAMPLE_STORAGE_ENGINE=1 \
-DWITH_SSL=bundled \                                                                 # 編譯其它功能SSL、ZLIB等
-DWITH_ZLIB=bundled \
-DENABLED_LOCAL_INFILE=1 \
-DWITH_EMBEDDED_SERVER=1 \
-DENABLE_DOWNLOADS=1 \
-DWITH_DEBUG=0 -DSYSCONFDIR=/etc
[ ~/mysql-5.6.38]# make && make install                                              # 編譯並安裝數據庫

# 作軟連接並給MySQL目錄受權
# ln -s /usr/local/mysql-5.6.38/ /usr/local/mysql
# chown -R mysql.mysql /usr/local/mysql

3. 初始化數據目錄vim

# MySQL 5.6初始化數據庫的命令:
# /usr/local/mysql/scripts/mysql_install_db --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data -user=mysql

# MySQL 5.7初始化數據庫的命令:
# /usr/local/mysql/bin/mysqld --initialize-insecure --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data -user=mysql

4. 拷貝啓動服務的腳本安全

# cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
# chmod 700 /etc/init.d/mysqld

5. 修改環境變量socket

# echo 'PATH=/usr/local/mysql/bin:$PATH' >>/etc/profile
# source /etc/profile

6. 修改配置文件,並啓動數據庫網站

# vim /etc/my.cnf
[mysqld]
server_id=1
port=3306
basedir=/usr/local/mysql
datadir=/usr/local/mysql/data
socket=/usr/local/mysql/mysql.sock 
log_bin=/usr/local/mysql/mysql-bin
log_error=/var/log/mysql.log
character-set-server=utf8

[client]
socket=/tmp/mysql.sock

# /etc/init.d/mysqld start

7. 設置數據庫密碼並清空MySQL不安全賬號編碼

# mysqladmin -u root password 123456
# mysql -uroot -p123456

# 清除不安全的用戶,先查詢用戶名爲空和沒有密碼的
> select user,password,host from mysql.user;
> drop user root@'127.0.0.1';
> drop user ''@'localhost';
相關文章
相關標籤/搜索