Ubuntu 20.04下编译mysql

# 安装编译所需依赖包
sudo apt install cmake gcc g++ libaio-dev openssl libssl-dev
libncurses5-dev libreadline-dev libreadline-dev libpam0g-dev zlib1g-dev libcurl-ocaml-dev

# 将boost_1_59_0.tar.gz文件放到DWITH_BOOST指定的目录


cmake -DCMAKE_INSTALL_PREFIX=/mysql/mysql57/ -DMYSQL_DATADIR=/mysql/mysql-data/ -DSYSCONFDIR=/mysql/ -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_ARCHIVE_STORAGE_ENGINE=1 -DWITH_BLACKHOLE_STORAGE_ENGINE=1 -DWITH_FEDERATED_STORAGE_ENGINE=1 -DWITH_PARTITION_STORAGE_ENGINE=1 -DMYSQL_UNIX_ADDR=/mysql/mysql-data/mysql.sock -DMYSQL_TCP_PORT=3306 -DENABLED_LOCAL_INFILE=1 -DEXTRA_CHARSETS=all -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DMYSQL_USER=mysql -DWITH_BINLOG_PREALLOC=ON -DWITH_ZLIB=system -DWITH_DEBUG=1
-DWITH_BOOST=/root/sf/mysql-5.7.26/boost/boost_1_59_0

# 生成build tree
cmake /home/acc/percona-server/percona-server-5.7.31-34 -DBUILD_CONFIG=mysql_release \
        -DCMAKE_BUILD_TYPE=Debug \
        -DWITH_EMBEDDED_SERVER=OFF \
        -DFEATURE_SET=community \
        -DENABLE_DTRACE=OFF \
        -DWITH_SSL=system -DWITH_ZLIB=system \
        -DCMAKE_INSTALL_PREFIX="/usr/local/mysql" \
        -DMYSQL_DATADIR="/mysql-files" \
        -DINSTALL_PLUGINDIR="lib/plugin" \
        -DSYSCONFDIR="/etc" \
        -DWITH_UNIT_TESTS=0 \
        -DWITH_READLINE=system \
        -DWITHOUT_TOKUDB=ON \
        -DWITHOUT_ROCKSDB=ON \
        -DWITH_PAM=ON \
        -DWITH_INNODB_MEMCACHED=ON \
        -DWITH_BOOST="/home/acc/percona-server" \
        -DWITH_SCALABILITY_METRICS=ON \
        -DWITH_KEYRING_VAULT=OFF \
        -DINSTALL_MYSQLTESTDIR="" \
        -DWITH_COREDUMPER=OFF

# 简化步骤
cd mysql-5.7.34
mkdir bld
cd bld
cmake .. -DBUILD_CONFIG=mysql_release -DCMAKE_BUILD_TYPE=Debug -DWITH_BOOST="../boost"

# 如果需要调试加上
-DWITH_DEBUG=1

# 编译
make -j8

# 安装
make install
没有指定默认路径的情况下,默认安装在/usr/local/mysql目录下。

创建mysql用户

useradd -M -U -s /bin/false mysql

生成数据库副本

mkdir /mysql-files
chown mysql:mysql /mysql-files
chmod 750 /mysql-files
/usr/local/mysql/bin/mysqld-debug --initialize --datadir=/mysql-files/ --user=mysql

创建一个没有数据库密码的副本
/usr/local/mysql/bin/mysqld-debug --initialize-insecure --datadir=/mysql-files/ --user=mysql

/usr/local/mysql/bin/mysqld-debug --defaults-file=/home/mysql/my-1.cnf --daemonize

创建mysqld的配置文件

# cat /etc/mysql/conf.d/mysqld.cnf
[mysqld]
[mysqld]
basedir=/usr/local/mysql
datadir=/mysql-test/mysql-files-master

user=mysql

port=3306

log_error=mysqld.log
pid_file=mysqld.pid

log-bin=mysql-bin
server-id=1
binlog_format=ROW

gtid_mode=ON
enforce_gtid_consistency=ON

plugin_dir=/usr/local/mysql/lib/plugin

plugin-load-add=rpl_semi_sync_master=semisync_master.so
plugin-load-add=rpl_semi_sync_slave=semisync_slave.so

rpl_semi_sync_master_enabled=ON
rpl_semi_sync_master_timeout=10000000000

启动mysqld

/usr/local/mysql/bin/mysqld_safe --user=mysql --mysqld=mysqld-debug &

安装半同步复制插件

配置方法:
在主库安装semisync_master插件:
mysql> INSTALL PLUGIN rpl_semi_sync_master SONAME 'semisync_master.so';

在备库安装semisync_slave插件
mysql> INSTALL PLUGIN rpl_semi_sync_slave SONAME 'semisync_slave.so';

[mysqld]
plugin-load-add=rpl_semi_sync_master=semisync_master.so
plugin-load-add=rpl_semi_sync_slave=semisync_slave.so

rpl_semi_sync_master_enabled=1
rpl_semi_sync_master_timeout=1000
rpl_semi_sync_slave_enabled=1

配置主从复制

全量备份

参考:https://dev.mysql.com/doc/refman/5.7/en/replication-snapshot-method.html

  1. 使用mysqldump
    导出完整的数据库:
    mysqldump -h127.0.0.1 -P3306 -padmin123 --all-databases --triggers --routines --events --master-data > dbdump.db
    参考:https://dev.mysql.com/doc/refman/5.7/en/mysqldump.html
  2. 冷备方案,直接拷贝数据库副本
1. 对source端数据库,加全局读锁,并获取位点
    mysql> FLUSH TABLES WITH READ LOCK;
    SHOW MASTER STATUS;
2. slow shutdown(SET GLOBAL innodb_fast_shutdown=0)
    mysql> mysqladmin shutdown
3. 拷贝数据库副本到备库
4. 对source端数据库解锁
    mysql> UNLOCK TABLES;
  1. 采用热备工具xtrabackup

建立主从复制

CHANGE MASTER TO MASTER_HOST='127.0.0.1',MASTER_USER='root',MASTER_PASSWORD='admin123',MASTER_PORT=3306,MASTER_AUTO_POSITION=1;
start slave;

登陆修改root密码

SET PASSWORD = PASSWORD('admin123');
GRANT ALL PRIVILEGES ON . TO 'root'@'%' IDENTIFIED BY 'admin123' WITH GRANT OPTION;

mysql -S /mysql-files-1/mysql.sock -uroot -padmin123

mysql -h127.0.0.1 -P3306 -uroot -p

参考资料:
基于源码编译:
https://dev.mysql.com/doc/refman/5.7/en/installing-source-distribution.html
编译选项说明:
https://dev.mysql.com/doc/refman/5.7/en/source-configuration-options.html

你可能感兴趣的:(Ubuntu 20.04下编译mysql)