Mysql 8.0 源碼編譯 多實例安裝

https://blog.csdn.net/cuilouyi9469/article/details/100438142mysql

1、準備工做c++

  1. 下載安裝包

路徑:https://dev.mysql.com/downloads/mysql/sql

這裏選擇 mysq-8.0.16.tar.gz 數據庫

  1. 清理已有版本

##查詢vim

rpm -qa | grep mysql
rpm -qa | grep maria
##清理(若是存在的話)socket

yum remove mysql
##或者 ide

yum remove mariadbui

  1. 安裝依賴包

(1)常規依賴spa

yum -y install gcc gcc-c++ ncurses ncurses-devel libaio-devel openssl openssl-devel.net

(2)特殊版本的依賴

編譯的時候,分別錯誤提示:

CMake 3.4.3 or higher is required.

                    GCC 5.3 or newer is required

因此須要安裝Cmake和GCC的相關版本

請參考: http://blog.itpub.net/69915315/viewspace-2648182

2、編譯安裝(軟件)

  1. 解壓安裝包

tar -zxvf tar -zxvf mysql-8.0.16.tar.gz

  1. cmake配置

    (1) 進入目錄 mysql-8.0.16 ,創建一個目錄,用於存放編譯好的軟件

    cd mysql-8.0.16
    mkdir xiaochong
    (2) 進入子目錄xiaochong,進行編譯前的配置。 主要cmake後是 . . , 執行其父目錄。

    cd xiaochong
    配置參數:

cmake .. -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DENABLED_LOCAL_INFILE=ON \
-DWITH_INNODB_MEMCACHED=ON \
-DWITH_SSL=system \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_FEDERATED_STORAGE_ENGINE=1 \
-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
-DWITH_ARCHIVE_STORAGE_ENGINE=1 \
-DWITHOUT_EXAMPLE_STORAGE_ENGINE=1 \
-DWITH_PERFSCHEMA_STORAGE_ENGINE=1 \
-DCOMPILATION_COMMENT="xiaochong edition" \
-DDOWNLOAD_BOOST=1 \
-DWITH_BOOST=/usr/local/boost \
-DCMAKE_CXX_COMPILER=/usr/bin/g++ \
-DWITH_BOOST=/tmp

  1. 編譯

make -j 10
4 . 安裝

make install
末尾以下提示,表示成功。

-- Configuring done

-- Generating done

-- Build files have been written to: /software/mysql-8.0.16/xiaochong


錯誤1 c++: error: unrecognized command line option ‘-std=c++14’

解決方式: 添加: -DCMAKE_CXX_COMPILER=/usr/bin/g++

3、建立數據庫

一、建立用戶

groupadd mysql
useradd -g mysql mysql

  1. 建立相關目錄

mkdir -p /data/mysql/{3306,3307}/{data,log,tmp,innodb,innodb_log}
這裏是兩個實例的目錄,分別是3306和3307.

建立後,目錄結構以下:

[root@mysql80 /]# cd data

[mysql@mysql80 data]$ tree .

.

└── mysql

├── 3306

│ ├── data

│ ├── innodb

│ ├── innodb_log

│ ├── log

│ └── tmp

└── 3307

├── data

├── innodb

├── innodb_log

├── log

└── tmp

  1. 修改目錄權限

chown -R mysql:mysql /data/mysql/
chown -R mysql:mysql /usr/local/mysql/

  1. 添加環境變量

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

  2. 添加配置文件

(1)3306

vim /data/mysql/3306/my3306.cnf
內容以下:

[client]
port=3306
socket=/data/mysql/3306/mysql.sock
[mysqld]
port=3306
user=mysql
socket=/data/mysql/3306/mysql.sock
pid-file=/data/mysql/3306/mysql.pid
basedir=/usr/local/mysql
datadir=/data/mysql/3306/data
tmpdir=/data/mysql/3306/tmp
open_files_limit=60000
#explicit_defaults_for_timestamp
server-id=3306
lower_case_table_names=1
character-set-server=utf8
#federated
#sql_mode=STRICT_TRANS_TABLES
max_connections=1000
max_connect_errors=100000
interactive_timeout=86400
wait_timeout=86400
sync_binlog=0
back_log=100
default-storage-engine=InnoDB
log_slave_updates=1
# Logs related settings
log-bin=/data/mysql/3306/log/mysql3306-bin
binlog_format=mixed
binlog_cache_size=32m
max_binlog_cache_size=64m
max_binlog_size=512m
long_query_time=1
log_output=FILE
log-error=/data/mysql/3306/log/mysql-error.log
slow_query_log=1
slow_query_log_file=/data/mysql/3306/log/slow_statement.log
#log_queries_not_using_indexes
general_log=0
general_log_file=/data/mysql/3306/log/general_statement.log
#expire-logs-days = 14
binlog_expire_logs_seconds=1728000
relay-log=/data/mysql/3306/log/relay-bin
relay-log-index=/data/mysql/3306/log/relay-bin.index
#** MySQL Replication New Feature*
master-info-repository=TABLE
relay-log-info-repository=TABLE
#relay-log-recovery
#***
INNODB Specific options ***
innodb_buffer_pool_size=2048M
transaction-isolation=REPEATABLE-READ
innodb_buffer_pool_instances=8
innodb_file_per_table=1
innodb_data_home_dir=/data/mysql/3306/innodb
innodb_data_file_path=ibdata1:2048M:autoextend
innodb_thread_concurrency=8
innodb_log_buffer_size=16M
innodb_log_file_size=128M
innodb_log_files_in_group=3
innodb_log_group_home_dir=/data/mysql/3306/innodb_log
innodb_flush_log_at_trx_commit=2
innodb_max_dirty_pages_pct=70
innodb_flush_method=ODIRECT
[mysql]
no-auto-rehash
default-character-set=gbk
prompt = (\u@\h) [\d]>\

(1)3307

vim /data/mysql/3307/my3307.cnf
內容以下:

[client]
port=3307
socket=/data/mysql/3307/mysql.sock
[mysqld]
port=3307
user=mysql
socket=/data/mysql/3307/mysql.sock
pid-file=/data/mysql/3307/mysql.pid
basedir=/usr/local/mysql
datadir=/data/mysql/3307/data
tmpdir=/data/mysql/3307/tmp
open_files_limit=60000
#explicit_defaults_for_timestamp
server-id=3307
lower_case_table_names=1
character-set-server=utf8
#federated
#sql_mode=STRICT_TRANS_TABLES
max_connections=1000
max_connect_errors=100000
interactive_timeout=86400
wait_timeout=86400
sync_binlog=0
back_log=100
default-storage-engine=InnoDB
log_slave_updates=1
# Logs related settings
log-bin=/data/mysql/3307/log/mysql3306-bin
binlog_format=mixed
binlog_cache_size=32m
max_binlog_cache_size=64m
max_binlog_size=512m
long_query_time=1
log_output=FILE
log-error=/data/mysql/3307/log/mysql-error.log
slow_query_log=1
slow_query_log_file=/data/mysql/3307/log/slow_statement.log
#log_queries_not_using_indexes
general_log=0
general_log_file=/data/mysql/3307/log/general_statement.log
#expire-logs-days = 14
binlog_expire_logs_seconds=1728000
relay-log=/data/mysql/3307/log/relay-bin
relay-log-index=/data/mysql/3307/log/relay-bin.index
#** MySQL Replication New Feature*
master-info-repository=TABLE
relay-log-info-repository=TABLE
#relay-log-recovery
#***
INNODB Specific options ***
innodb_buffer_pool_size=2048M
transaction-isolation=REPEATABLE-READ
innodb_buffer_pool_instances=8
innodb_file_per_table=1
innodb_data_home_dir=/data/mysql/3307/innodb
innodb_data_file_path=ibdata1:2048M:autoextend
innodb_thread_concurrency=8
innodb_log_buffer_size=16M
innodb_log_file_size=128M
innodb_log_files_in_group=3
innodb_log_group_home_dir=/data/mysql/3307/innodb_log
innodb_flush_log_at_trx_commit=2
innodb_max_dirty_pages_pct=70
innodb_flush_method=ODIRECT
[mysql]
no-auto-rehash
default-character-set=gbk
prompt = (\u@\h) [\d]>\

六、初始化數據庫

(1) 3306

mysqld --defaults-file=/data/mysql/3306/my3306.cnf --initialize --user=mysql
(2) 3307

mysqld --defaults-file=/data/mysql/3307/my3307.cnf --initialize --user=mysql
錯誤以下:

[mysql@mysql80 ~]$ mysqld --defaults-file=/data/mysql/3306/my.cnf --initialize --user=mysql

mysqld: /lib64/libstdc++.so.6: version `CXXABI_1.3.9' not found (required by mysqld)

mysqld: /lib64/libstdc++.so.6: version `GLIBCXX_3.4.21' not found (required by mysqld)

mysqld: /lib64/libstdc++.so.6: version `CXXABI_1.3.8' not found (required by mysqld)

mysqld: /lib64/libstdc++.so.6: version `GLIBCXX_3.4.20' not found (required by mysqld)

解析辦法:

緣由: 因爲咱們以前升級了gcc,也就是gcc-5.3.0. 但目錄 /lib64/ 下的庫文件連接的是 libstdc++.so.6 依然軟連接是低版本 libstdc++.so.6.0.19

[root@mysql80 /]# cd /lib64/

[root@mysql80 lib64]# ls -l | grep libstdc++.so.6

lrwxrwxrwx. 1 root root 19 Jun 19 14:36 libstdc++.so.6 -> libstdc++.so.6.0.19

-rwxr-xr-x. 1 root root 991616 Apr 24 22:24 libstdc++.so.6.0.19

進入到新安裝的gcc-5.3.0的目錄,進入lib64,查看 libstdc++.so.6,軟連接的是 libstdc++.so.6.0.21

[root@mysql80 gcc-5.3.0]# cd lib64/

[root@mysql80 lib64]# ls -l | grep libstdc++.so.6

lrwxrwxrwx. 1 root root 19 Jun 25 15:54 libstdc++.so -> libstdc++.so.6.0.21

lrwxrwxrwx. 1 root root 19 Jun 25 15:54 libstdc++.so.6 -> libstdc++.so.6.0.21

-rwxr-xr-x. 1 root root 11089328 Jun 25 15:54 libstdc++.so.6.0.21

處理: 刪除原來的軟連接,創建新的軟連接:

[root@mysql80 lib64]# rm -rf libstdc++.so.6

[root@mysql80 lib64]# ln -s /usr/local/gcc-5.3.0/lib64/libstdc++.so.6 libstdc++.so.6

[root@mysql80 lib64]# ls -l | grep libstdc++.so.6

lrwxrwxrwx. 1 root root 41 Jun 26 14:48 libstdc++.so.6 -> /usr/local/gcc-5.3.0/lib64/libstdc++.so.6

7.啓動服務

(1) 3306

/mysqld_safe --defaults-file=/data/mysql/3306/my.cnf --user=mysql &

(2)3307

/mysqld_safe --defaults-file=/data/mysql/3307/my.cnf --user=mysql &

8.登陸數據庫

這裏以3306實例爲例,3307步驟相同,只須要注意端口號便可,即大寫的 -P

(1)查找root@localhost的初始密碼,

查看當前錯誤日誌

more /data/mysql/3306/log/mysql-error.log

找到以下行,標紅的便是密碼:

[MY-010454] [Server] A temporary password is generated for root@localhost: ?/ihz.ew8SIy

mysql -uroot -p'?/ihz.ew8SIy' -P3306 -S /data/mysql/3306/mysql.sock

(2)登陸

mysql -uroot -p' ?/ihz.ew8SIy ' -P3306 -S /data/mysql/3306/mysql.sock

(3)修改密碼

ALTER USER 'root'@'localhost' IDENTIFIED WITH sha256_password BY 'Yxc@3306' PASSWORD EXPIRE INTERVAL 360 DAY;

(4) 查詢數據庫

ysql> show databases;

+--------------------+

| Database |

+--------------------+

| information_schema |

| mysql |

| performance_schema |

| sys |

+--------------------+

4 rows in set (0.00 sec)

  1. 校驗後臺進程

來自 「 ITPUB博客 」 ,連接:http://blog.itpub.net/69915315/viewspace-2648090/,如需轉載,請註明出處,不然將追究法律責任

轉載於:http://blog.itpub.net/69915315/viewspace-2648090/

相關文章
相關標籤/搜索