MySQL初始化
mysqld --defaults-file=/home/mysql/mysql170200/my.cnf --initialize-insecure --user=mysql
脚本
#!/bin/bash
yum install -y perl perl-Module-Build net-tools autoconf libaio numactl-libs
tar -xvf mysql-8.0.28-linux-glibc2.17-x86_64-minimal.tar.xz -C /usr/local/
cd /usr/local
ln -s mysql-8.0.28-linux-glibc2.17-x86_64-minimal/ mysql
mkdir -p /data/mysql/data
mkdir -p /data/mysql/logs
cat > /data/mysql/my.cnf <<EOF
[mysqld]
basedir=/usr/local/mysql
datadir=/data/mysql/data
socket=/tmp/mysql.sock
user=mysql
log_error=/tmp/mysql.log
skip_name_resolve
log_bin=/data/mysql/logs/mysql-bin
port=3306
server_id=8006
EOF
cat >/etc/systemd/system/mysqld.service<<EOF
[Unit]
Description=MySQL Server
Documentation=man:mysqld(8)
Documentation=http://dev.mysql.com/doc/refman/en/using-systemd.html
After=network.target
After=syslog.target
[Install]
WantedBy=multi-user.target
[Service]
User=mysql
Group=mysql
ExecStart=/usr/local/mysql/bin/mysqld --defaults-file=/data/mysql/my.cnf
LimitNOFILE = 5000
EOF
useradd -s /sbin/nologin mysql
chown -R mysql.mysql /usr/local/mysql
chown -R mysql.mysql /data/mysql
/usr/local/mysql/bin/mysqld --initialize-insecure --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql/data
echo "export PATH=/usr/local/mysql/bin:$PATH" >> ~/.bash_profile
source ~/.bash_profile
systemctl start mysqld
systemctl status mysqld
sleep 3s
/usr/local/mysql/bin/mysql -e "alter user root@'localhost' identified by 'A_dminjs#888'"
create user root@'%' identified by 'A_dminjs#888';
grant all on *.* to root@'%';
grant all on *.* to root@'%' identified by 'A_dminjs#888';;
简单的主从复制
create user repl@'%' identified by 'A_dminjs#888';
grant replication slave on *.* to repl@'%';
show master status\G;
CHANGE MASTER TO
MASTER_HOST='192.168.166.140',
MASTER_USER='repl',
MASTER_PASSWORD='A_dminjs#888',
MASTER_PORT=3306,
MASTER_LOG_FILE='mysql-bin.000002',
MASTER_LOG_POS=1195,
MASTER_CONNECT_RETRY=10;