系统环境
Ubuntu 20.04.3 LTS
MySQL 版本
MySQL 5.7.43
机器环境规划
MySQL-Master-5.7 10.2.0.47
安装依赖
apt install -y libaio-dev libncurses5
下载二进制软件包并解压至/usr/local/
官方下载地址:https://downloads.mysql.com/archives/community/
wget https://cdn.mysql.com/archives/mysql-5.7/mysql-5.7.43-linux-glibc2.12-x86_64.tar.gz
tar zxvf mysql-5.7.43-linux-glibc2.12-x86_64.tar.gz -C /usr/local/ && ln -sf /usr/local/mysql-5.7.43-linux-glibc2.12-x86_64 /usr/local/mysql-5.7.43
创建 mysql 用户和数据目录
useradd mysql -s /usr/sbin/nologin && mkdir -p /apps/mysql/ && touch /apps/mysql/mysql-error.log && chown -R mysql:mysql /apps/mysql
添加环境变量
echo "export PATH=/usr/local/mysql-5.7.43/bin:$PATH" > /etc/profile.d/mysql.sh && source /etc/profile.d/mysql.sh
初始化MySQL数据库
mysqld --initialize-insecure --basedir=/usr/local/mysql-5.7.43 --datadir=/apps/mysql/ --user=mysql
--initialize-insecure:以不安全的方式初始化数据目录,为root用户设置一个空密码。
--basedir=/usr/local/mysql-5.7.43 :MySQL的二进制文件、库文件等组件所在的根目录。MySQL的安装目录。
--datadir=/apps/mysql/ :存储数据库文件(如表定义、数据文件等)的地方。
--user=mysql : 指定用户运行MySQL服务
创建主节点配置文件
cat >> /etc/my.cnf <<EOF
[client]
socket = /tmp/mysql.sock
default-character-set = utf8
[mysqld]
user = mysql
basedir = /usr/local/mysql-5.7.43
datadir = /apps/mysql/
port = 3306
socket = /tmp/mysql.sock
skip-external-locking
key_buffer_size = 16M
max_allowed_packet = 32M
table_open_cache = 64
sort_buffer_size = 512K
net_buffer_length = 8K
read_buffer_size = 512K
read_rnd_buffer_size = 512K
myisam_sort_buffer_size = 8M
wait_timeout = 10
interactive_timeout = 10
innodb_data_home_dir = /apps/mysql/
innodb_data_file_path = ibdata1:10M:autoextend
innodb_log_group_home_dir = /apps/mysql/
innodb_buffer_pool_size = 64M
innodb_log_file_size = 2G
innodb_log_buffer_size = 8M
innodb_flush_log_at_trx_commit = 1
innodb_lock_wait_timeout = 50
character-set-server = utf8
collation-server = utf8_bin
default-storage-engine = INNODB
general_log_file=/apps/mysql/general.log
general_log=1
log_bin_trust_function_creators = 1
log-error = /apps/mysql/mysql-error.log
slow-query-log = 1
slow-query-log-file = /apps/mysql/mysql-slow.log
long_query_time = 1
slave-parallel-type = LOGICAL_CLOCK
slave-parallel-workers = 16
slave_preserve_commit_order = 1
[mysql]
socket = /tmp/mysql.sock
no-auto-rehash
default-character-set = utf8
EOF
查看mysqld 启动时加载配置文件的顺序
mysqld --help --verbose | grep my.cnf
/etc/my.cnf /etc/mysql/my.cnf /usr/local/mysql/etc/my.cnf ~/.my.cnf
拷贝启动脚本
cp /usr/local/mysql-5.7.43/support-files/mysql.server /etc/init.d/mysqld
第一次启动:
/etc/init.d/mysqld start
后续管理
systemctl stop mysql
systemctl start mysql
systemctl status mysql
设置MySQL root 密码
mysqladmin -uroot password
仅登录用户可评论,点击 登录