码迷,mamicode.com
首页 > 数据库 > 详细

MARIADB安装

时间:2019-04-30 10:42:48      阅读:175      评论:0      收藏:0      [点我收藏+]

标签:ml2   end   starting   zlib   shu   localhost   other   tls   app   

二进制安装MARIADB

1、解压到/usr/local/
[root@localhost ~]# tar xvf mariadb-10.2.23-linux-x86_64.tar.gz -C /usr/local/

2、软连接
[root@localhost local]# ln -s mariadb-10.2.23-linux-x86_64/ mysql

3、更改所有者,所属组
[root@localhost local]# chown -R root:root mysql/

4、创建系统用户,用户组
[root@localhost local]# groupadd -r -g 66 mysql
[root@localhost local]# useradd -r -g mysql -u 66 -s /sbin/nologin -d /data/mysql mysql

5、运行脚本,指定数据存放位置
/usr/local/mysql/scripts/mysql_install_db
[root@localhost mysql]# scripts/mysql_install_db --user=mysql --datadir=/data/mysql

6、创建配置文件
[root@localhost mysql]# mkdir /etc/mysql/
[root@localhost mysql]# pwd
/usr/local/mysql
[root@localhost mysql]# cp support-files/my-huge.cnf /etc/mysql/my.cnf
[root@localhost mysql]# vim /etc/mysql/my.cnf
[mysqld]        #在mysqld加入数据路径
datadir=/data/mysql

7、制作启动脚本
[root@localhost mysql]# pwd
/usr/local/mysql
[root@localhost mysql]# cp support-files/mysql.server /etc/init.d/mysqld

8、加入chkconfig
[root@localhost mysql]# chkconfig --add mysqld

9、启动服务
[root@localhost mysql]# service mysqld start
[root@localhost mysql]# ss -nlt
State      Recv-Q Send-Q Local Address:Port                Peer Address:Port              
LISTEN     0      128                *:22                             *:*                  
LISTEN     0      100        127.0.0.1:25                             *:*                  
LISTEN     0      80                :::3306                          :::*                  
LISTEN     0      128               :::22                            :::*                  
LISTEN     0      100              ::1:25                            :::*      

10、加入PATH环境变量
[root@localhost mysql]# echo PATH=‘/usr/local/mysql/bin:$PATH‘ > /etc/profile.d/mysql.sh
[root@localhost mysql]# . /etc/profile.d/mysql.sh
[root@localhost mysql]# mysql
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 10
Server version: 10.2.23-MariaDB-log MariaDB Server

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type ‘help;‘ or ‘\h‘ for help. Type ‘\c‘ to clear the current input statement.

MariaDB [(none)]> 

11、跑加固脚本
[root@localhost mysql]# mysql_secure_installation

源码编译安装MARIADB
1、准备编译软件

yum -y install bison bison-devel zlib-devel libcurl-devel libarchive-devel boostdevel gcc gcc-c++ cmake ncurses-devel gnutls-devel libxml2-devel openssl-devel libevent-devel libaio-devel 

2、创建用户

[root@centos6 ~]# useradd -r -s /sbin/nologin -d /data/mysql -m mysql       
[root@centos6 ~]# ll -d /data/mysql/
drwx------. 2 mysql mysql 4096 Apr  2 19:36 /data/mysql/

3、解压,cmake编译

[root@centos6 ~]# tar xvf mariadb-10.2.23.tar.gz
[root@centos6 ~]# cd mariadb-10.2.23
[root@centos6 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 && make install
[root@centos6 mariadb-10.2.23]# make && make install
如果出错,执行rm -f CMakeCache.txt

4、加入环境变量

[root@centos6 mariadb-10.2.23]# echo PATH=‘/app/mysql/bin:$PATH‘ > /etc/profile.d/mysql.sh
[root@centos6 mariadb-10.2.23]# . /etc/profile.d/mysql.sh

5、生成数据库

[root@centos6 mysql]# cd /app/mysql/
[root@centos6 mysql]# scripts/mysql_install_db --datadir=/data/mysql/ --user=mysql

6、准备配置文件

[root@centos6 mysql]# mkdir /etc/mysql/
[root@centos6 mysql]# cp /app/mysql/support-files/my-huge.cnf /etc/mysql/mysql.cnf

7、准备启动脚本

[root@centos6 mysql]# cp /app/mysql/support-files/mysql.server /etc/init.d/mysqld

8、启动服务

[root@centos6 ~]# cp /etc/mysql/mysql.cnf /etc/my.cnf --backup
[root@centos6 mysql]# service mysqld start

yum多实例安装mariadb

1、规划目录

[root@localhost ~]# mkdir /mysql/{3306,3307,3308}/{data,etc,socket,bin,log,pid} -p
[root@localhost ~]# tree /mysql/
/mysql/
├── 3306
│?? ├── bin
│?? ├── data
│?? ├── etc
│?? ├── log
│?? ├── pid
│?? └── socket
├── 3307
│?? ├── bin
│?? ├── data
│?? ├── etc
│?? ├── log
│?? ├── pid
│?? └── socket
└── 3308
    ├── bin
    ├── data
    ├── etc
    ├── log
    ├── pid
    └── socket

2、修改文件属性

[root@localhost ~]# chown -R mysql:mysql /mysql/

3、生成数据库

[root@localhost ~]# ls /var/lib/mysql/
aria_log.00000001  ibdata1      ib_logfile1  mysql.sock          test
aria_log_control   ib_logfile0  mysql        performance_schema
[root@localhost ~]# mysql_install_db --user=mysql --datadir=/mysql/3306/data
[root@localhost ~]# mysql_install_db --user=mysql --datadir=/mysql/3307/data
[root@localhost ~]# mysql_install_db --user=mysql --datadir=/mysql/3308/data

4、创建配置文件

[root@localhost ~]# cp /etc/my.cnf /mysql/3306/etc/
[root@localhost ~]# vim /mysql/3306/etc/my.cnf
[mysqld]
port=3306
datadir=/mysql/3306/data
socket=/mysql/3306/socket/mysql.sock
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
# Settings user and group are ignored when systemd is used.
# If you need to run mysqld under a different user or group,
# customize your systemd unit file for mariadb according to the
# instructions in http://fedoraproject.org/wiki/Systemd

[mysqld_safe]
log-error=/mysql/3306/log/mariadb.log
pid-file=/mysql/3306/pid/mariadb.pid

#
# include all files from the config directory

[root@localhost ~]# cp /mysql/3306/etc/my.cnf /mysql/3307/etc/my.cnf
[root@localhost bin]# sed -i ‘s/3306/3307/‘ /mysql/3307/etc/my.cnf

[root@localhost ~]# cp /mysql/3306/etc/my.cnf /mysql/3308/etc/my.cnf
[root@localhost bin]# sed -i ‘s/3306/3308/‘ /mysql/3308/etc/my.cnf

5、准备服务脚本

[root@localhost ~]# cd /mysql/3306/bin/
[root@localhost bin]# vim mysqld
#!/bin/bash

port=3306
mysql_user="root"
mysql_pwd=""
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 in
start)
    function_start_mysql
;;
stop)
    function_stop_mysql
;;
restart)
    function_restart_mysql
;;
*)
    printf "Usage: ${mysql_basedir}/${port}/bin/mysqld {start|stop|restart}\n"
esac

...
...
[root@localhost bin]# chmod +x mysqld 
[root@localhost bin]# cp mysqld /mysql/3307/bin/
[root@localhost bin]# cp mysqld /mysql/3308/bin/
[root@localhost bin]# vim /mysql/3307/bin/mysqld
[root@localhost bin]# vim /mysql/3308/bin/mysqld
#!/bin/bash
port=3307
#!/bin/bash
port=3308

6、启动服务

[root@localhost bin]# /mysql/3306/bin/mysqld start
Starting MySQL...
[root@localhost bin]# /mysql/3307/bin/mysqld start
Starting MySQL...
[root@localhost bin]# /mysql/3308/bin/mysqld start
Starting MySQL...

[root@localhost bin]# ss -nlt
State      Recv-Q Send-Q    Local Address:Port                   Peer Address:Port              
LISTEN     0      50                    *:3306                              *:*                  
LISTEN     0      50                    *:3307                              *:*                  
LISTEN     0      50                    *:3308                              *:*         

7、连接

[root@localhost bin]# mysql -P3306 -S /mysql/3306/socket/mysql.sock

8、关闭服务

[root@localhost bin]# /mysql/3308/bin/mysqld stop
Stoping MySQL...

9、用mysqladmin设置密码

[root@localhost bin]# mysqladmin -S /mysql/3307/socket/mysql.sock -uroot password 123456

[root@localhost bin]# mysql -P3307 -S /mysql/3307/socket/mysql.sock 

10、避免关闭服务需要输入密码,需要在文件中将密码输入

[root@localhost bin]# vim /mysql/3307/bin/mysqld
mysql_pwd="123456"      

MARIADB安装

标签:ml2   end   starting   zlib   shu   localhost   other   tls   app   

原文地址:https://blog.51cto.com/14230743/2386958

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!