#!/bin/sh
port=3306
mysql_user="root"
mysql_pwd=""
CmdPath="/application/mariamysql/bin"
mysql_sock="/data/${port}/mysql.sock"
#startup function
function_start_mysql()
{
if [ ! -e "$mysql_sock" ];then
printf "Starting MariaMySQL...\n"
/bin/sh ${CmdPath}/mysqld_safe --defaults-file=/data/${port}/my.cnf 2>&1 > /dev/null &
else
printf "MariaMySQL is running...\n"
exit
fi
}
#stop function
function_stop_mysql()
{
if [ ! -e "$mysql_sock" ];then
printf "MariaMySQL is stopped...\n"
exit
else
printf "Stoping MariaMySQL...\n"
${CmdPath}/mysqladmin -u ${mysql_user} -p${mysql_pwd} -S /data/${port}/mysql.sock shutdown
fi
}
#restart function
function_restart_mysql()
{
printf "Restarting MariaMySQL...\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: /data/${port}/mysql {start|stop|restart}\n"
esac
#启动脚本更改为700权限
[root@mariadb 3306]# chmod 700 mariadb #初始化数据库(注意这里的datadir)
[root@mariadb 3306]#/application/mariamysql/scripts/mysql_install_db --basedir=/application/mariamysql/ --datadir=/data/3306/data/ --user=mysql #启动数据库
[root@mariadb 3306]# /data/3306/mariadb start
Starting MariaMySQL... #检查
[root@mariadb 3306]# lsof -i :3306
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
mysqld 29380 mysql 15u IPv4 116393 0t0 TCP *:mysql (LISTEN) #登录数据库(注意登录写法)
[root@mariadb 3306]# /application/mariamysql/bin/mysql -S /data/3306/mysql.sock
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 1
Server version: 5.5.25-MariaDB-log MariaDB Server
This software comes with ABSOLUTELY NO WARRANTY. This is free software,
and you are welcome to modify and redistribute it under the GPL v2 license
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| test |
+--------------------+
4 rows in set (0.00 sec)
MariaDB [(none)]>