> MARIADB Installation
Yum Install Mariadb-server
> Create related directories, and set permissions
MKDIR/MYSQLDB; Mkdir/mysqldb/{3306,3307,3308}/{etc,socket,pid,log,data}-PV
Chown-r Mysql:mysql/mysqldb
#目录结构如下
/mysqldb
├──3306
│├──data
│├──etc
│├──log
│├──pid
│└──socket
├──3307
│├──data
│├──etc
│├──log
│├──pid
│└──socket
└──3308
├──data
├──etc
├──log
├──pid
└──socket
> Initializing Database
Systemctl start mariadb; Show variables like ' basedir% '; #查看mariadb安装路径
mysql_install_db--datadir=/mysqldb/3306/data--user=mysql--basedir=/usr/
mysql_install_db--datadir=/mysqldb/3307/data--user=mysql--basedir=/usr/
mysql_install_db--datadir=/mysqldb/3308/data--user=mysql--basedir=/usr/
> Copy and modify configuration files
cp/etc/my.cnf/mysqldb/3306/etc/
cp/etc/my.cnf/mysqldb/3307/etc/
cp/etc/my.cnf/mysqldb/3308/etc/
Vi/etc/my.cnf/mysqldb/3306/etc/my.cnf
[Mysqld]
port=3306
Datadir=/mysqldb/3306/data
Socket=/mysqldb/3306/socket/mysql.sock
# Disabling Symbolic-links is recommended to prevent assorted security risks
Symbolic-links=0
# Settings user and group was ignored when Systemd was 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=/mysqldb/3306/log/mariadb.log
Pid-file=/mysqldb/3306/pid/mariadb.pid
#
# include all files from the Config directory
#
#!includedir/etc/my.cnf.d
#其它2个实例的配置文件参考第1个实例的配置文件
Cp-a./3306/etc/my.cnf./3307/etc/my.cnf; Cp-a./3306/etc/my.cnf./3308/etc/my.cnf
> Prepare startup scripts, set permissions
CP mysqld/mysqldb/3306/; CP mysqld/mysqldb/3307/; CP mysqld/mysqldb/3308/
chmod 700/mysqldb/3306/mysqld; chmod 700/mysqldb/3307/mysqld; chmod 700/mysqldb/3308/mysqld
#!/bin/Bash # port=3306 #注意端口Mysql_user="Root"mysql_pwd="CentOS" #口令Cmd_path="/usr/bin"#2进制程序目录Mysql_basedir="/mysqldb"Mysql_sock="${mysql_basedir}/${port}/socket/mysql.sock"Function_start_mysql () {if[!-E"$mysql _sock"]; Thenprintf"starting mysql...\n"${cmd_path}/mysqld_safe--defaults-file=${MYSQL_BASEDIR}/${PORT}/ETC/MY.CNF &>/dev/NULL&Elseprintf"MySQL is running...\n"Exitfi }
Function_stop_mysql () {if[!-E"$mysql _sock"]; Thenprintf"MySQL is stopped...\n"ExitElseprintf"stoping mysql...\n"${cmd_path}/mysqladmin-u ${mysql_user}-p${mysql_pwd}-S ${mysql_sock} shutdownfi} function_restart_mysql () {printf"restarting mysql...\n"Function_stop_mysqlSleep 2Function_start_mysql} Case$1 inchstart) function_start_mysql;; stop) Function_stop_mysql;; restart) Function_restart_mysql;; *) printf"Usage: ${mysql_basedir}/${port}/bin/mysqld {start|stop|restart}\n" Esac
> Start a single instance, note that if the MARIADB service is started, stop the service first
Systemctl Stop MARIADB
/mysqldb/3306/mysqld start; /mysqldb/3307/mysqld start; /mysqldb/3308/mysqld start
> View port Information
Ss-nutl
> Connection test, set password
Mysql-s/mysqldb/3308/socket/mysql.sock
Show variables like '%port% ';
MariaDB[(None)]>Show variables like '%port%'; +-------------------------------------+-------+ |Variable_name|Value| +-------------------------------------+-------+ |Extra_port| 0 | |Innodb_import_table_from_xtrabackup| 0 | |Innodb_support_xa| on | |Large_files_support| on | |Port| 3306 | |Progress_report_time| 5 | |Report_host| | |Report_password| | |Report_port| 3306 | |Report_user| | +-------------------------------------+-------+ TenRowsinch Set(0.00sec) MariaDB[(None)]> Select User, Host,password fromMysql.User; +------+------------+----------+ | User |Host|Password| +------+------------+----------+ |Root|localhost| | |Root|Snowyts-Ts| | |Root| 127.0.0.1 | | |Root|::1 | | | |localhost| | | |Snowyts-Ts| | +------+------------+----------+ 6Rowsinch Set(0.00sec) MariaDB[(None)]> UpdateMysql.User SetPassword=Password'CentOS')where User='Root'; Query OK,4Rows Affected (0.00sec) Rows matched:4Changed:4Warnings:0MariaDB[(None)]> Select User, Host,password fromMysql.User; +------+------------+-------------------------------------------+ | User |Host|Password| +------+------------+-------------------------------------------+ |Root|localhost| *128977e278358ff80a246b5046f51043a2b1fced| |Root|Snowyts-Ts| *128977e278358ff80a246b5046f51043a2b1fced| |Root| 127.0.0.1 | *128977e278358ff80a246b5046f51043a2b1fced| |Root|::1 | *128977e278358ff80a246b5046f51043a2b1fced| | |localhost| | | |Snowyts-Ts| | +------+------------+-------------------------------------------+ 6Rowsinch Set(0.00sec) MariaDB[(None)]>FlushPrivileges; Query OK,0Rows Affected (0.01Sec
> Connection requires password entry
/mysqldb/3306/mysqld start
Mysql-s/mysqldb/3306/socket/mysql.sock-p
MySQL implements multiple instances