标签:mariadb
用mariadb官方源下载mariadb。
[root@business-backup ~]# vim /etc/yum.repos.d/mariadb.repo [mariadb] name = MariaDB baseurl = http://yum.mariadb.org/10.2/centos7-amd64 gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB gpgcheck=1
然是用yum下载mariadb:
yum install MariaDB-server MariaDB-client -y
2.创建需要使用的data目录。我在这边创建了两个,一个用于3306端口,一个用于3307.
mkdir /data/newoa/data -pv mkdir /data/travel/data/ -pv chown -R mysql:mysql /data/
3.初始化两个数据库:
mysqld --initialize-insecure --datadir=/data/newoa/data --user=mysql mysqld --initialize-insecure --datadir=/data/travel/data/ --user=mysql
4.初始化后再启动,启动成功后连接数据库并修改root@localhost用户的密码,然后退出。
ALTER USER ‘root‘@‘localhost‘ IDENTIFIED BY ‘123456‘;
5.修改两个配置文件,处理的newoa以及travel目录是自己创建:
[root@business-backup ~]# vim /etc/my.cnf.d/newoa/my.cnf [mysqld] port=3306 datadir=/data/newoa/data socket=/data/newoa/data/mysql.sock server_id=201 log-bin=mysql-bin binlog_format=mixed relay-log = relay-bin user=mysql [mysqld_safe] log-error=/data/newoa/data/mysqld.log pid-file=/data/newoa/data/mysqld.pid [root@business-backup ~]# vim /etc/my.cnf.d/travel/my.cnf [mysqld] port=3307 datadir=/data/travel/data socket=/data/travel/data/mysql.sock server_id=207 log-bin=mysql-bin binlog_format=mixed relay-log = relay-bin user=mysql [mysqld_safe] log-error=/data/travel/data/mysqld.log pid-file=/data/travel/data/mysqld.pid
6.创建启动脚本。
以下是3306实例的管理脚本/etc/init.d/mysqld3306,内容修改自原有管理脚本/etc/init.d/mysqld。由于我是yum安装的,所以mysql的basedir为/usr,如果是编译安装或通用二进制安装,则对应修改下面脚本中的basedir变量。将此管理脚本复制为/etc/init.d/mysqld3307,再修改下port=3307即可作为3307实例的服务管理脚本。$datadir以及cnf的路径做修改。
[root@business-backup ~]# vim /etc/init.d/mysqld3306 #!/bin/sh # # mysqld This shell script takes care of starting and stopping # the MySQL subsystem (mysqld). # # chkconfig: 345 64 36 # description: MySQL database server. # processname: mysqld # Source function library. . /etc/rc.d/init.d/functions # Source networking configuration. . /etc/sysconfig/network basedir=/usr exec="$basedir/bin/mysqld_safe" prog="mysqld" port=3306 datadir="/data/newoa/data" socketfile="$datadir/mysql.sock" errlogfile="$datadir/mysqld.log" mypidfile="$datadir/mysqld.pid" cnf="/etc/my.cnf.d/newoa/my.cnf" # Set timeouts here so they can be overridden from /etc/sysconfig/mysqld STARTTIMEOUT=120 STOPTIMEOUT=60 # Set in /etc/sysconfig/mysqld, will be passed to mysqld_safe MYSQLD_OPTS= [ -e /etc/sysconfig/$prog ] && . /etc/sysconfig/$prog lockfile=/var/lock/subsys/$prog case $socketfile in /*) adminsocket="$socketfile" ;; *) adminsocket="$datadir/$socketfile" ;; esac start(){ [ -x $exec ] || exit 5 # check to see if it‘s already running RESPONSE=$(/usr/bin/mysqladmin --no-defaults --socket="$adminsocket" --user=UNKNOWN_MYSQL_USER ping 2>&1) if [ $? = 0 ]; then # already running, do nothing action $"Starting $prog: " /bin/true ret=0 elif echo "$RESPONSE" | grep -q "Access denied for user" then # already running, do nothing action $"Starting $prog: " /bin/true ret=0 else # Now start service $exec $MYSQLD_OPTS --defaults-file="$cnf" --datadir="$datadir" --socket="$socketfile" --pid-file="$mypidfile" --basedir="$basedir" --user=mysql >/dev/null & safe_pid=$! # Spin for a maximum of N seconds waiting for the server to come up; # exit the loop immediately if mysqld_safe process disappears. # Rather than assuming we know a valid username, accept an "access # denied" response as meaning the server is functioning. ret=0 TIMEOUT="$STARTTIMEOUT" while [ $TIMEOUT -gt 0 ]; do RESPONSE=$(/usr/bin/mysqladmin --no-defaults --socket="$adminsocket" --user=UNKNOWN_MYSQL_USER ping 2>&1) && break echo "$RESPONSE" | grep -q "Access denied for user" && break if ! /bin/kill -0 $safe_pid 2>/dev/null; then echo "MySQL Daemon failed to start." ret=1 break fi sleep 1 let TIMEOUT=${TIMEOUT}-1 done if [ $TIMEOUT -eq 0 ]; then echo "Timeout error occurred trying to start MySQL Daemon." ret=1 fi if [ $ret -eq 0 ]; then action $"Starting $prog: " /bin/true touch $lockfile else action $"Starting $prog: " /bin/false fi fi return $ret } stop(){ if [ ! -f "$mypidfile" ]; then # not running; per LSB standards this is "ok" action $"Stopping $prog: " /bin/true return 0 fi MYSQLPID=`cat "$mypidfile"` if [ -n "$MYSQLPID" ]; then /bin/kill "$MYSQLPID" >/dev/null 2>&1 ret=$? if [ $ret -eq 0 ]; then TIMEOUT="$STOPTIMEOUT" while [ $TIMEOUT -gt 0 ]; do /bin/kill -0 "$MYSQLPID" >/dev/null 2>&1 || break sleep 1 let TIMEOUT=${TIMEOUT}-1 done if [ $TIMEOUT -eq 0 ]; then echo "Timeout error occurred trying to stop MySQL Daemon." ret=1 action $"Stopping $prog: " /bin/false else rm -f $lockfile rm -f "$socketfile" action $"Stopping $prog: " /bin/true fi else action $"Stopping $prog: " /bin/false fi else # failed to read pidfile, probably insufficient permissions action $"Stopping $prog: " /bin/false ret=4 fi return $ret } restart(){ stop start } condrestart(){ [ -e $lockfile ] && restart || : } # See how we were called. case "$1" in start) start ;; stop) stop ;; status) status -p "$mypidfile" $prog ;; restart) restart ;; condrestart|try-restart) condrestart ;; reload) exit 3 ;; force-reload) restart ;; *) echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload}" exit 2 esac exit $?
使用以下命令管理实例:
service mysqld3306 {start|stop|status|restart} service mysqld3307 {start|stop|status|restart}
本文出自 “LinuxNew” 博客,请务必保留此出处http://jimchen.blog.51cto.com/10026955/1969770
标签:mariadb
原文地址:http://jimchen.blog.51cto.com/10026955/1969770