03: mysql mysql model and multi-instance installation

MySQL simple knowledge
----------------------------------------------- -------------------------------------------------- -------------

A, mysql is the C / S model structure, namely: client (Client) + server (server) 

Second, how the application connects to mysql:

1, TCP / IP connected database
mysql -uadmin -p123 -h 10.0.0.51 -P 3306

It can be shown that:
(1) database was good
(2) the network connection is no problem in
(3) the user is no problem

2, SOCKET connect database
mysql -uroot -p123456 -S /application/mysql/tmp/mysql.sock

 

Thoughts:
MySQL-uroot--p123456 What is the use to log ?????

In fact, the database connection used SOCKET way, but here is the default -S hidden.

Careful you must find a compiler installed in front of us, the compiler parameter which specifies the file sockt

Path /application/mysql-5.6.34/tmp/mysql.sock, because the compiler specified socket, so here is compiled using the default path.

 

Third, the multi-instance install mysql

       That is, a server above, start multiple mysql, each run independently.


Planning:
1, start times the mysqld_safe
2, respectively, by preparing a plurality of my.cnf = File---defaults the mysqld_safe
. 3, a plurality of ports 3307, 3308,3309
4, initialization data sets
5, each socket is defined in the configuration file , log_error, datadir, server_id, port

 

Configure multiple instances:
Create the necessary directory
[root @ mysql181 ~] # mkdir -p /data/330{7..9}/data

创建配置文件:
[root@mysql181 ~]#  cat /data/3307/my.cnf /data/3308/my.cnf /data/3309/my.cnf
[mysqld]
basedir=/application/mysql
datadir=/data/3307/data
socket=/data/3307/mysql.sock
server_id=3307
port=3307
log_error=/data/3307/mysql.log
log_bin=/data/3307/mysql-bin
binlog_format=row
[client]
socket=/data/3307/mysql.sock

[mysqld]
basedir=/application/mysql
datadir=/data/3308/data
socket=/data/3308/mysql.sock
server_id=3308
port=3308
log_error=/data/3308/mysql.log
log_bin=/data/3308/mysql-bin
binlog_format=row
[client]
socket=/data/3308/mysql.sock


[mysqld]
basedir=/application/mysql
datadir=/data/3309/data
socket=/data/3309/mysql.sock
server_id=3309
port=3309
log_error=/data/3309/mysql.log
log_bin=/data/3309/mysql-bin
binlog_format=row
[client]
socket=/data/3309/mysql.sock
[root@db01 data]#


Initialization data:

[root@mysql181 ~]# /application/mysql/scripts/mysql_install_db --user=mysql --basedir=/application/mysql --datadir=/data/3307/data/
[root@mysql181 ~]# /application/mysql/scripts/mysql_install_db --user=mysql --basedir=/application/mysql --datadir=/data/3308/data/
[root@mysql181 ~]# /application/mysql/scripts/mysql_install_db --user=mysql --basedir=/application/mysql --datadir=/data/3309/data/

Modify directory permissions
[the root @ DB01 3307] Touch # /data/330{7..9}/mysql.log
[the root @ DB01 3307] # chown -R & lt mysql.mysql / Data / 330. *

Start multi-instance

[root@mysql181 ~]# mysqld_safe --defaults-file=/data/3307/my.cnf &
[root@mysql181 ~]# mysqld_safe --defaults-file=/data/3308/my.cnf &
[root@mysql181 ~]# mysqld_safe --defaults-file=/data/3309/my.cnf &

Check whether the port to start:

 

 

Were landed 3307-3309:

[root@mysql181 ~]# mysql -S /data/3307/mysql.sock

You should connect to the database using a socket ways: Specify the file location sock

 

Close the database method:

[root@mysql181 ~]# mysqladmin -S /data/3307/mysql.sock shutdown

Because we do not have multi-instance startup script, in fact, we can turn on and off these two orders, write a startup script.

 

 

 

This multi-instance install mysql success!

 

Guess you like

Origin www.cnblogs.com/jim-xu/p/11610078.html