mysql 5 7 編譯安裝

2022-06-20 15:51:11 字數 4197 閱讀 9102

系統 centos 7.9 

userdel -r mysql

yum -y remove mariadb mariadb-libs mariadb-server mariadb-devel

rm -rf /etc/my*

rm -rf /var/lib/mysql

rm -rf /var/log/mysql*

新增使用者

useradd -s /sbin/nologin mysql

安裝包 yum install -y cmake bison bison-devel libaio-devel gcc gcc-c++ git ncurses-devel

mysql 手冊:

cmake \

-dcmake_install_prefix=/usr/local/mysql \

-dmysql_unix_addr=/tmp/mysql.sock \

-dsysconfdir=/etc \

-ddefault_charset=utf8mb4 \

-ddefault_collation=utf8mb4_general_ci \

-dwith_innobase_storage_engine=1 \

-dwith_archive_storage_engine=1 \

-dwith_blackhole_storage_engine=1 \

-dwith_myisam_storage_engine=1 \

-dmysql_datadir=/usr/local/mysql/data \

-dextra_charsets=all \

-dwith_extra_charsets=all \

-dwith_innodb_memcached=1 \

-dmysql_tcp_port=3306 \

-dwith_debug=1 \

-dwith_embedded_server=1 \

-dwith_zlib=system \

-dwith_boost=boost \

-denabled_local_infile=1 \

-denabled_profiling=on \

-dwith_systemd=1

/********************** 不完整,待完善 ************************************/

-dcmake_install_prefix=/usr/local/mysql \ mysql安裝目錄

-dmysql_unix_addr=/tmp/mysql.sock \ mysql.sock路徑

-dsysconfdir=/etc \ mysql配置檔案目錄

-ddefault_charset=utf8 \ 預設的字符集為utf8

-ddefault_collation=utf8_general_ci \ 預設排序規則

-dwith_innobase_storage_engine=1 \ 儲存引擎

-dwith_archive_storage_engine=1 \ 儲存引擎

-dwith_blackhole_storage_engine=1 \ 儲存引擎

-denable_local_infile=1 \

-dwith_myisam_storage_engine=1 \

-dmysql_datadir=/usr/local/mysql/data \ 資料庫檔案存放位置

-dextra_charsets=all \ 啟用額外的字符集型別

-dmysql_tcp_port=3306 \ tcp埠

-dwith_debug=off \ 禁用debug

-dwith_readline=1 \ 啟用readline庫支援(提供可編輯的命令列)

-dwith_embedded_server=1 \ 編譯嵌入式伺服器支援

-dwith_zlib=system \ 啟用libz庫支援(zib、gzib相關)

-denable_dtrace=off \

-dwith_boost=boost \ 指定boost

-dwith_systemd=1 支援systemctl

make

make install

cd /usr/local/mysql/

chown -r mysql:mysql .

初始化資料庫

初始化:

./bin/mysqld --initialize-insecure --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data

* --datadir目錄比較為空,--basedir --datadir 必須和/etc/my.cnf 配置的目錄一致

*** 提示 my.cnf (參考底部)中所配置檔案提前建立好,並將使用者設定為mysql,可以避免很多坑。。。

建立my.cnf中pid-file檔案,例:

mkdir -r /var/run/mysqld/

chown -r mysql /var/run/mysqld/

複製啟動指令碼

#cp ./support-files/mysql.server /etc/init.d/mysqld

更改 mysqld.service 檔案中的pid項;

cp /usr/local/mysql/usr/lib/systemd/system/mysqld.service /usr/lib/systemd/system/

重新整理識別啟動指令碼檔案 systemctl daemon-reload

啟動資料庫 systemctl start mysqld

如無法啟動檢視mysqld.service設定項 /usr/lib/systemd/system/mysqld.service

檢視埠服務 netstat -anpt | grep 3306

新增開機啟動 systemctl enable mysqld

設定登陸密碼 ./bin/mysqladmin -u root -p password "123456"

寫入環境變數

echo "export path=$path:/usr/local/mysql/bin">>/etc/profile

或 vim /etc/profile

path=/usr/local/mysql/bin:$path

my.cnf

[client]

port = 3306

socket = /tmp/mysql.sock

[mysqld]

user = mysql

port = 3306

socket = /tmp/mysql.sock

pid-file = /var/run/mysqld/mysqld.pid

basedir = /usr/local/mysql

datadir = /usr/local/mysql/data

log-error = /usr/local/mysql/log/mysql-error.log # 錯誤檔案

slow_query_log = 1

long_query_time = 1

slow_query_log_file = /usr/local/mysql/log/mysql-slow.log

key_buffer_size = 16m

max_allowed_packet = 1m

table_open_cache = 64

sort_buffer_size = 512k

net_buffer_length = 8k

read_buffer_size = 256k

read_rnd_buffer_size = 512k

myisam_sort_buffer_size = 8m

[mysqldump]

quick

max_allowed_packet = 16m

[mysql]

no-auto-rehash

safe-updates

[myisamchk]

key_buffer_size = 20m

sort_buffer_size = 20m

read_buffer = 2m

write_buffer = 2m

[mysqlhotcopy]

interactive-timeout

mysql5 7編譯安裝

一 準備工作 mysql 並解壓 root 001 mysql檔案 root 001 tar xf mysql 5.7.19.tar.gz c usr local src root 001 cd 上次使用的目錄 root 001 src cd mysql 5.7.19 2.安裝依賴包 yum ins...

mysql5 7 編譯安裝

安裝mysql 依賴 yum y install gcc cmake make gcc c ncurses devel openssl devel bison ncurses chkconfig lsof wget tar zxvf boost 1 59 0.tar.gz mv boost 1 59...

Mysql5 7編譯安裝

關閉防火牆和selinux yum erase mariadb mariadb server mariadb libs mariadb devel y userdel r mysql rm rf etc my rm rf var lib mysql useradd r mysql m s bin f...