本文共 4368 字,大约阅读时间需要 14 分钟。
1 安装
yum install mariadb
mkdir /mysql/{3306,3307,3308}/{data,etc,socket,log,bin,pid} -pvchown -R mysql.mysql /mysql
mysql_install_db --datadir=/mysql/3306/data/ --user=mysqlmysql_install_db --datadir=/mysql/3307/data/ --user=mysqlmysql_install_db --datadir=/mysql/3308/data/ --user=mysql
cp /etc/my.cnf /mysql/3306/etc vim /mysql/3306/etc/my.cnf[mysqld]port=3306 加一行 datadir=/mysql/3306/datasocket=/mysql/3306/socket/mysql.sock[mysqld_safe]log-error=/mysql/3306/log/mariadb.logpid-file=/mysql/3306/pid/mariadb.pid
cp /mysql/3306/etc/my.cnf /mysql/3307/etc/my.cnf /mysql/3307/etc/my.cnf 修改cp /mysql/3306/etc/my.cnf /mysql/3308/etc/my.cnf /mysql/3308/etc/my.cnf 修改
vi /mysql/{3306,3307,3308}/bin/mysqld cat /mysq/3306/bin/mysqld #!/bin/bashport=3306mysql_user="root"mysql_pwd="centos"cmd_path="/usr/bin"mysql_basedir="/mysql"mysql_sock="${mysql_basedir}/${port}/socket/mysql.sock"function_start_mysql(){ if [ ! -e "$mysql_sock" ];then printf "Starting MySQL...\n" ${cmd_path}/mysqld_safe --defaults-file=${mysql_basedir}/${port}/etc/my.cnf &> /dev/null & else printf "MySQL is running...\n" exit fi}function_stop_mysql(){ if [ ! -e "$mysql_sock" ];then printf "MySQL is stopped...\n" exit else printf "Stoping MySQL...\n" ${cmd_path}/mysqladmin -u ${mysql_user} -p${mysql_pwd} -S ${mysql_sock} shutdown fi}function_restart_mysql(){ printf "Restarting MySQL...\n" function_stop_mysql sleep 2 function_start_mysql}case $1 instart) function_start_mysql;;stop) function_stop_mysql;;restart) function_restart_mysql;;*) printf "Usage: ${mysql_basedir}/${port}/bin/mysqld {start|stop|restart}\n"esac
chmod +x /mysql/{3306,3307,3308}/bin/mysqld
/mysql/{3306,3307,3308}/bin/mysqld start /mysql/{3306,3307,3308}/bin/mysqld stop
mysql -S /mysql/{3306,3307,3308}/socket/mysql.sock
mysqladmin -S /mysql/{3306,3307,3308}/socket/mysql.sock password 'centos'vi /mysql/{3306,3307,3308}/bin/mysqld 加上对应centos口令
groupadd -r -g 336 mysqluseradd -r -g mysql -u 336 -s /sbin/nologin -d /data/mysql mysql
tar xvf mariadb-10.2.23-linux-x86_64.tar.gz -C /usr/local/cd /usr/local/ln -s mariadb-10.2.23-linux-x86_64/ mysqlchown -R root.root /usr/local/mysql/
cat /etc/profile.d/mysql.sh PATH=/usr/local/mysql/bin:$PATH
mkdir /data/mysql -pvchown mysql.mysql /data/mysql/cd /usr/local/mysql./scripts/mysql_install_db --datadir=/data/mysql --user=mysql
mkdir /etc/mysqlcp /usr/local/mysql/support-files/my-huge.cnf /etc/mysql/my.cnfvim /etc/mysql/my.cnf[mysqld]datadir=/data/mysql 加一行
cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqldchkconfig --add mysqldservice mysqld start
mysql_secure_installation
mysql -uroot -ppassword
×××:
mysql
组与用户/usr/sbin/groupadd -g 366 -r mysql/usr/sbin/useradd -c "MySQL" -u 366 -g mysql -s /sbin/nologin -r -d /data/mysql mysql
mkdir /data/mysql -pv chown mysql.mysql /data/mysql
tar xf mariadb-10.2.23.tar.gzcd mariadb-10.2.23
cmake . \-DCMAKE_INSTALL_PREFIX=/app/mysql \-DMYSQL_DATADIR=/data/mysql/ \-DSYSCONFDIR=/etc/mysql \-DMYSQL_USER=mysql \-DWITH_INNOBASE_STORAGE_ENGINE=1 \-DWITH_ARCHIVE_STORAGE_ENGINE=1 \-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \-DWITH_PARTITION_STORAGE_ENGINE=1 \-DWITHOUT_MROONGA_STORAGE_ENGINE=1 \-DWITH_DEBUG=0 \-DWITH_READLINE=1 \-DWITH_SSL=system \-DWITH_ZLIB=system \-DWITH_LIBWRAP=0 \-DENABLED_LOCAL_INFILE=1 \-DMYSQL_UNIX_ADDR=/data/mysql/mysql.sock \-DDEFAULT_CHARSET=utf8 \-DDEFAULT_COLLATION=utf8_general_ci
make -j 8make install
echo 'PATH=/usr/local/mysql/bin:$PATH' > /etc/profile.d/mysql.shsource /etc/profile.d/mysql.sh
cd /usr/local/mysqlscripts/mysql_install_db --user=mysql --datadir=/data/mysql
cp support-files/my-innodb-heavy-4G.cnf /etc/my.cnf.d/my.cnfvim /etc/my.cnf.d/my.cnf #[mysqld] 配置段中中加入如下内容datadir = /data/mysqlinnodb_file_per_table = onskip_name_resolve = on
cp support-files/mysql.server /etc/rc.d/init.d/mysqldchkconfig --add mysqld
systemctl start mysqld
mysql_secure_installation
转载于:https://blog.51cto.com/9019400/2386288