博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
基于YUM安装与源码编译或二进制多实例安装Mariadb,mysql
阅读量:5974 次
发布时间:2019-06-20

本文共 4368 字,大约阅读时间需要 14 分钟。

基于YUM

  • 1 安装

    yum install mariadb
  • 2 创建多实例对应的目录结构
    mkdir /mysql/{3306,3307,3308}/{data,etc,socket,log,bin,pid} -pvchown -R mysql.mysql /mysql
  • 3 创建多实例的数据库文件
    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
  • 4 创建对应配置文件
    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 修改
  • 5 准备各实例的启动脚本
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
  • 6 启动和关闭实例
    /mysql/{3306,3307,3308}/bin/mysqld start /mysql/{3306,3307,3308}/bin/mysqld stop
  • 7 测试连接
    mysql -S /mysql/{3306,3307,3308}/socket/mysql.sock
  • 8 安全加固
    mysqladmin  -S /mysql/{3306,3307,3308}/socket/mysql.sock   password 'centos'vi /mysql/{3306,3307,3308}/bin/mysqld  加上对应centos口令

二进制的安装

  • 1 准备用户和组
groupadd -r -g 336 mysqluseradd -r -g mysql -u 336 -s /sbin/nologin -d /data/mysql mysql
  • 2 准备二进制程序文件和相关文件属性
    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/
  • 3 PATH变量
cat /etc/profile.d/mysql.sh PATH=/usr/local/mysql/bin:$PATH
  • 4 准备数据库数据目录和数据--改成逻辑卷
mkdir /data/mysql -pvchown mysql.mysql /data/mysql/cd /usr/local/mysql./scripts/mysql_install_db --datadir=/data/mysql --user=mysql
  • 5 准备Mysql的服务器端的配置文件
mkdir /etc/mysqlcp /usr/local/mysql/support-files/my-huge.cnf /etc/mysql/my.cnfvim /etc/mysql/my.cnf[mysqld]datadir=/data/mysql 加一行
  • 6 准备服务启动脚本
cp /usr/local/mysql/support-files/mysql.server  /etc/init.d/mysqldchkconfig --add mysqldservice mysqld start
  • 7 安全加固
mysql_secure_installation
  • 8 测试连接
mysql -uroot -ppassword

源码编译安装MySQL

  • 准备编译环境

×××:

  • 创建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

你可能感兴趣的文章
文件传输软件汇总
查看>>
iosttableViewCell右侧的箭头,圆形等
查看>>
PUTTY工具的使用
查看>>
arcgis for js开发之路径分析
查看>>
验收测试 4
查看>>
ng-repeat 的重复问题
查看>>
PHP与SQL数据库交互中文乱码怎么办
查看>>
转载 C++实现的委托机制
查看>>
struts2(三) 输入校验和拦截器
查看>>
ASP.NET MVC 5 實作 GridView 分頁
查看>>
Linux之时钟中断
查看>>
Oracle 11g R2 RAC 高可用连接特性
查看>>
struts2的DevMode(开发模式)模式
查看>>
【教程】HTML5+JavaScript编写flappy bird
查看>>
YARN Architecture
查看>>
chrome 常用快捷键(可以摆脱鼠标哦)
查看>>
hdu 4786 Fibonacci Tree(最小生成树)
查看>>
C#集合--Dictionary
查看>>
JavaScript提高:005:ASP.NET使用easyUI TABS标签显示问题
查看>>
Semi-Supervised Classification with Graph Convolutional Networks
查看>>