Centos-7yum installation (MAIRADB) implements MySQL multi-instance

Source: Internet
Author: User
Tags chmod

Steps:
1. Install Mariadb-server Package
Yum Mariadb-server
2, build a master folder three sub-folders, three sub-folders for each of the three strength note: Try to put this multi-instance in the logical volume is better
A, Mkdir/mysqldb/{3306,3307,3308}/{etc,data,pid,socket,log}

B. Modify Directory Permissions
Chown-r mysql:mysql/mysqldb/
3. Build the Database
mysql_install_db--datadir=/mysql/3306/data--user=mysql
mysql_install_db--datadir=/mysql/3307/data--user=mysql
mysql_install_db--datadir=/mysql/3308/data--user=mysql
4, copy/etc/my.cnf to each instance of the ETC directory
Cp-a/etc/my.cnf/mysql/3306/etc/
Cp-a/etc/my.cnf/mysql/3307/etc/
Cp-a/etc/my.cnf/mysql/3308/etc/
5, modify the directory to copy over the MY.CNF

6. Prepare the service scripts and copy them to the first-level directory of each instance, and modify the permissions to 700, plus execute permissions
Copying files
CP mysqld mysql/{3306,3307,3308}
Modify Permissions
chmod 700/mysql/3306/mysqld
chmod 700/mysql/3307/mysqld
chmod 700/mysql/3308/mysqld
7. Service Script
Cat Mysqld
#!/bin/bash
port=3306 "Note this to be modified according to the appropriate port"
mysql_user= "root" "User"
mysql_pwd= "CentOS" "This is the password"
Cmd_path= "/usr/bin" "This is the path to the top mariadb command"
Mysql_basedir= "/mysqldb"
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 $ 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
8. Start the service
A. Note that the start-up service needs to be tapped on the full path to start
/mysqldb/3306/mysqld Start|stop|restart

9. How to connect to a database
A. Mysql-s/mysqldb/3306/socket/mysql.sock
B. Mysql-s/mysqldb/3307/socket/mysql.sock
C. mysql-s/mysqldb/3308/socket/mysql.sock
10. Add mysql,root Password
A. Mysqladmin-uroot-s/mysqldb/3306/socket/mysql.sock password ' CentOS '
B. mysqladmin-uroot-s/mysqldb/3307/socket/mysql.sock password ' CentOS '
C. mysqladmin-uroot-s/mysqldb/3308/socket/mysql.sock password ' CentOS '
11. You can also enter MySQL to change the password
1. Log in to MySQL
A.mysql-s/mysqldb/3306/socket/mysql.sock
I. View user's password table
Select User,password,host from Mysql.user;
II. Modify the Add root password
Update Mysql.user Set Password=password ("CentOS") where user= ' root ';
III. Delete Empty account users
Drop user ' @localhost;
Iv. permission to take effect
1.flush privileges;

Centos-7yum installation (MAIRADB) implements MySQL multi-instance

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.