mysql5.6.7多實例安裝、配置的詳細講解分析及shell啓動腳本的編寫

一、mysql安裝

1、下載mysql數據庫源碼包:

wget http://cdn.mysql.com/Downloads/MySQL-5.6/mysql-5.6.27.tar.gz


2、安裝mysql環境安裝和運行所依賴的庫文件:

[root@mysqldb1 ~]# yum install gcc gcc-c++  ncurses ncurses-devel  bison cmake -y


2.1、添加mysql系統用戶:

[root@mysqldb1 ~]# useradd mysql -M -r -s /sbin/nologin


3、解壓mysql源碼包:

[root@mysqldb1 ~]# tar xf mysql-5.6.27.tar.gz 

[root@mysqldb1 ~]# ls

anaconda-ks.cfg  install.log  install.log.syslog  mysql-5.6.27  mysql-5.6.27.tar.gz

[root@mysqldb1 ~]# cd mysql-5.6.27

[root@mysqldb1 mysql-5.6.27]# ls

BUILD           configure.cmake      INSTALL-SOURCE      mysql-test  scripts        tests

BUILD-CMAKE     COPYING              INSTALL-WIN-SOURCE  mysys       sql            unittest

client          dbug                 libevent            mysys_ssl   sql-bench      VERSION

cmake           Docs                 libmysql            packaging   sql-common     vio

CMakeLists.txt  Doxyfile-perfschema  libmysqld           plugin      storage        win

cmd-line-utils  extra                libservices         README      strings        zlib

config.h.cmake  include              man                 regex       support-files


4、配置mysql安裝參數,並生成MakeFile及cmake編譯時所需要配置文件文件:

[root@mysqldb1 mysql-5.6.27]# cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql5.6.27 \

-DMYSQL_DATADIR=/usr/local/mysql5.6.27/data \

-DMYSQL_UNIX_ADDR=/usr/local/mysql5.6.27/tmp/mysql.sock \

-DDEFAULT_CHARSET=utf8 \

-DDEFAULT_COLLATION=utf8_general_ci \

-DEXTRA_CHARSETS=gbk,gb2312,utf8,ascii \

-DENABLED_LOCAL_INFILE=ON \

-DWITH_INNOBASE_STORAGE_ENGINE=1 \

-DWITH_FEDERATED_STORAGE_ENGINE=1 \

-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \

-DWITHOUT_EXAMPLE_STORAGE_ENGINE=1 \

-DWITH_FAST_MUTEXES=1 \

-DWITH_ZLIB=bundled \

-DENABLED_LOCAL_INFILE=1 \

-DWITH_READLINE=1 \

-DWITH_EMBEDDED_SERVER=1 \

-DWITH_DEBUG=0  


4.1執行cmake後新增或修改過的文件如下所示:

[root@mysqldb1 mysql-5.6.27]# ll | grep root

-rw-r--r--.  1 root root   55401 Oct 18 20:57 CMakeCache.txt

drwxr-xr-x. 12 root root    4096 Oct 18 20:58 CMakeFiles

-rw-r--r--.  1 root root    7421 Oct 18 20:57 cmake_install.cmake

-rw-r--r--.  1 root root    4767 Oct 18 20:57 CPackConfig.cmake

-rw-r--r--.  1 root root    5662 Oct 18 20:57 CPackSourceConfig.cmake

-rw-r--r--.  1 root root    1607 Oct 18 20:57 CTestTestfile.cmake

-rw-r--r--.  1 root root    6628 Oct 18 20:57 info_macros.cmake

-rw-r--r--.  1 root root    6375 Oct 18 20:57 make_dist.cmake

-rw-r--r--.  1 root root   69001 Oct 18 20:57 Makefile

drwxr-xr-x.  2 root root    4096 Oct 18 20:57 source_downloads

-rw-r--r--.  1 root root      88 Oct 18 20:56 VERSION.dep

 

5、根據cmake生成的配置文件編譯及安裝mysql數據庫

[root@mysqldb1 mysql-5.6.27]# make && make install

…… ……


5.1、除了 CMAKE_INSTALL_PREFIX 之外,CMake 所產生出來的 Makefile 也支援 DESTDIR。有下面兩種使用方式:

cmake .

make install DESTDIR="/usr/local/mysql5.6.27"

export DESTDIR="/usr/local/mysql5.6.27"

make install

[root@mysqldb1 mysql-5.6.27]# echo $?

0


6、修改mysql配置文件:

[root@mysqldb1 mysql-5.6.27]# cd /usr/local/mysql5.6.27/

[root@mysqldb1 mysql5.6.27]# ls

bin  COPYING  data  docs  include  INSTALL-BINARY  lib  man  mysql-test  README  scripts  share  sql-bench  support-files

[root@mysqldb1 mysql5.6.27]# cd support-files/

[root@mysqldb1 support-files]# ls

binary-configure  magic  my-default.cnf  mysqld_multi.server  mysql-log-rotate  mysql.server

[root@mysqldb1 support-files]# cp my-default.cnf ../my.cnf

[root@mysqldb1 support-files]# cd ..

[root@mysqldb1 mysql5.6.27]# ls

bin  COPYING  data  docs  include  INSTALL-BINARY  lib  man  my.cnf  mysql-test  README  scripts  share  sql-bench  support-files

[root@mysqldb1 mysql5.6.27]# vim my.cnf


  1 # For advice on how to change settings please see

  2 # http://dev.mysql.com/doc/refman/5.6/en/server-configuration-defaults.html

  3 # *** DO NOT EDIT THIS FILE. It's a template which will be copied to the

  4 # *** default location during install, and will be replaced if you

  5 # *** upgrade to a newer version of MySQL.

  6 

  7 [mysqld]

  8 

  9 # Remove leading # and set to the amount of RAM for the most important data

 10 # cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.

 11 # innodb_buffer_pool_size = 128M

 12 

 13 # Remove leading # to turn on a very important data integrity option: logging

 14 # changes to the binary log between backups.

 15 # log_bin

 16 

 17 # These are commonly set, remove the # and set as required.

 18 # basedir = .....

 19 # datadir = .....

 20 # port = .....

 21 # server_id = .....

 22 # socket = .....

 23 

 24 # Remove leading # to set options mainly useful for reporting servers.

 25 # The server defaults are faster for transactions and fast SELECTs.

 26 # Adjust sizes as needed, experiment to find the optimal values.

 27 # join_buffer_size = 128M

 28 # sort_buffer_size = 2M

 29 # read_rnd_buffer_size = 2M 

 30 

 31 sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES


把my.cnf中的 18、19、20 改成以下內容:


 18 basedir = /usr/local/mysql5.6.27

 19 datadir = /usr/local/mysql5.6.27/data

 20 port = 3306


7、修改mysql數據目錄的用戶使用權限:

[root@mysqldb1 mysql5.6.27]# chown mysql.mysql -R data/


8、執行mysql數據庫數據字典安裝文件腳本:

[root@mysqldb1 mysql5.6.27]# scripts/mysql_install_db --user=mysql  --defaults-file=/usr/local/mysql5.6.27/my.cnf 


PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !

To do so, start the server, then issue the following commands:


#8.1、設置mysql用戶的密碼:

  ./bin/mysqladmin -u root password 'new-password'       

  ./bin/mysqladmin -u root -h mysqldb1 password 'new-password'


Alternatively you can run:

#8.2、交互式設置mysql用戶的密碼:

  ./bin/mysql_secure_installation


which will also give you the option of removing the test

databases and anonymous user created by default.  This is

strongly recommended for production servers.


See the manual for more instructions.


You can start the MySQL daemon with:


#8.3、啓動mysql服務器:

  cd . ; ./bin/mysqld_safe &


You can test the MySQL daemon with mysql-test-run.pl


#8.4執行mysql腳本測試mysql是否啓動成功:

  cd mysql-test ; perl mysql-test-run.pl


Please report any problems at http://bugs.mysql.com/


The latest information about MySQL is available on the web at


  http://www.mysql.com


Support MySQL by buying support/licenses at http://shop.mysql.com


WARNING: Found existing config file ./my.cnf on the system.

Because this file might be in use, it was not replaced,

but was used in bootstrap (unless you used --defaults-file)

and when you later start the server.

The new default config file was created as ./my-new.cnf,

please compare it with your file and take the changes you need.


WARNING: Default config file /etc/my.cnf exists on the system

This file will be read by default by the MySQL server

If you do not want to use this, either remove it, or use the

--defaults-file argument to mysqld_safe when starting the server


9、啓動mysql服務

[root@mysqldb1 mysql5.6.27]# bin/mysqld_safe --defaults-file=/usr/local/mysql5.6.27/my.cnf --user=mysql >/dev/null &

[1] 41074


9.1、測試MySQL服務是否啓動

[root@mysqldb1 mysql5.6.27]# lsof -i :3306

COMMAND   PID  USER   FD   TYPE DEVICE SIZE/OFF NODE NAME

mysqld  41201 mysql   10u  IPv6 100814      0t0  TCP *:mysql (LISTEN)


[root@mysqldb1 mysql5.6.27]# netstat -tulnp | grep 3306

tcp        0      0 :::3306                     :::*                        LISTEN      41201/mysqld        


10、設置MySQL用戶密碼

10.1、交互式設置:

[root@mysqldb1 mysql5.6.27]# ./bin/mysql_secure_installation




NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MySQL

      SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!


In order to log into MySQL to secure it, we'll need the current

password for the root user.  If you've just installed MySQL, and

you haven't set the root password yet, the password will be blank,

so you should just press enter here.


Enter current password for root (enter for none): 

OK, successfully used password, moving on...


Setting the root password ensures that nobody can log into the MySQL

root user without the proper authorisation.


Set root password? [Y/n] y #是否設置root用戶密碼

New password: 

Re-enter new password: 

Password updated successfully!

Reloading privilege tables..

 ... Success!



By default, a MySQL installation has an anonymous user, allowing anyone

to log into MySQL without having to have a user account created for

them.  This is intended only for testing, and to make the installation

go a bit smoother.  You should remove them before moving into a

production environment.


Remove anonymous users? [Y/n] y     #是否刪除mysql匿名用戶

 ... Success!


Normally, root should only be allowed to connect from 'localhost'.  This

ensures that someone cannot guess at the root password from the network.


Disallow root login remotely? [Y/n] n #是否容許mysql管理員root用戶遠程登錄

 ... skipping.


By default, MySQL comes with a database named 'test' that anyone can

access.  This is also intended only for testing, and should be removed

before moving into a production environment.


Remove test database and access to it? [Y/n] y #是否移除test數據庫

 - Dropping test database...

 ... Success!

 - Removing privileges on test database...

 ... Success!


Reloading the privilege tables will ensure that all changes made so far

will take effect immediately.


Reload privilege tables now? [Y/n] y #是否重新加載權限表,相當於flush privileges;

 ... Success!





All done!  If you've completed all of the above steps, your MySQL

installation should now be secure.


Thanks for using MySQL!



Cleaning up...



10.2、用非交互式命令mysqladmin管理工具修改密碼

[root@mysqldb1 mysql5.6.27]# ./bin/mysqladmin -u root -p123456 password '654321' 

Warning: Using a password on the command line interface can be insecure.



11、把mysql的相關命令添加到環境變量裏:

[root@mysqldb1 mysql5.6.27]# echo PATH=/usr/local/mysql5.6.27/bin/:$PATH >> /etc/profile

[root@mysqldb1 mysql5.6.27]# source  /etc/profile


12、用mysql客戶端命令登錄mysql服務器

[root@mysqldb1 mysql5.6.27]# mysql -uroot -p

Enter password: 

Welcome to the MySQL monitor.  Commands end with ; or \g.

Your MySQL connection id is 13

Server version: 5.6.27 Source distribution


Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved.


Oracle is a registered trademark of Oracle Corporation and/or its

affiliates. Other names may be trademarks of their respective

owners.


Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.


mysql> show databases; #顯示root用戶可以管理的數據庫管理系統中有數據庫

+--------------------+

| Database           |

+--------------------+

| information_schema |

| mysql              |

| performance_schema |

+--------------------+

3 rows in set (0.08 sec)



mysql> use mysql; #切換進入mysql數據庫

Reading table information for completion of table and column names

You can turn off this feature to get a quicker startup with -A


Database changed

mysql> show tables; #查看mysql數據庫中有多少數據表文件

+---------------------------+

| Tables_in_mysql           |

+---------------------------+

| columns_priv              |

| db                        |

| event                     |

| func                      |

| general_log               |

| help_category             |

| help_keyword              |

| help_relation             |

| help_topic                |

| innodb_index_stats        |

| innodb_table_stats        |

| ndb_binlog_index          |

| plugin                    |

| proc                      |

| procs_priv                |

| proxies_priv              |

| servers                   |

| slave_master_info         |

| slave_relay_log_info      |

| slave_worker_info         |

| slow_log                  |

| tables_priv               |

| time_zone                 |

| time_zone_leap_second     |

| time_zone_name            |

| time_zone_transition      |

| time_zone_transition_type |

| user                      |

+---------------------------+

28 rows in set (0.00 sec)


mysql> select host,user,password from user;     #查看數據庫的中用戶

+-----------+------+-------------------------------------------+

| host      | user | password                                  |

+-----------+------+-------------------------------------------+

| localhost | root | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 |

| mysqldb1  | root | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 |

| 127.0.0.1 | root | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 |

| ::1       | root | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 |

+-----------+------+-------------------------------------------+

4 rows in set (0.00 sec)


13、製作開機自啓動服務:

13.1、#把安裝路勁下的support-files/mysql.server文件到改名爲/etc/init.d/mysqld

[root@mysqldb1 mysql5.6.27]# cd support-files/        

[root@mysqldb1 support-files]# cp mysql.server /etc/init.d/mysqld

13.2、查看mysqld是否具有執行權限:

[root@mysqldb1 support-files]# ll /etc/init.d/mysqld

-rwxr-xr-x. 1 root root 10916 Oct 18 23:04 /etc/init.d/mysqld


13.3、給mysql服務添加開機自啓動:

[root@mysqldb1 support-files]# chkconfig --add mysqld


13.4、查看mysql服務運行級別:

[root@mysqldb1 support-files]# chkconfig --list mysqld

mysqld         0:off 1:off 2:on 3:on 4:on 5:on 6:off


13.5、修改mysql運行級別:

[root@mysqldb1 support-files]# chkconfig --level 24 mysqld off

[root@mysqldb1 support-files]# chkconfig --list mysqld

mysqld         0:off 1:off 2:off 3:on 4:off 5:on 6:off


13.6、返回上級目錄並把目錄下mysql配置文件my.cnf複製到 /etc目錄下,並重新啓動mysql服務:

[root@mysqldb1 support-files]# cd ..

[root@mysqldb1 mysql5.6.27]# cp my.cnf /etc/my.cnf 

cp: overwrite `/etc/my.cnf'? y

[root@mysqldb1 mysql5.6.27]# service mysqld restart #重啓mysql服務

Shutting down MySQL..                                      [  OK  ]

Starting MySQL..                                           [  OK  ]

[1]+  Done                    bin/mysqld_safe --defaults-file=/usr/local/mysql5.6.27/my.cnf --user=mysql > /dev/null


14、用管理員賬戶登錄mysql並修改mysql用戶密碼:

這種方式必須是先用root帳戶登入mysql,然後執行:

mysql> use mysql

Reading table information for completion of table and column names

You can turn off this feature to get a quicker startup with -A


Database changed

mysql> UPDATE user SET password=PASSWORD('123456') WHERE user='root';

Query OK, 1 row affected (0.00 sec)

Rows matched: 4  Changed: 1  Warnings: 0


mysql> flush privileges;

Query OK, 0 rows affected (0.00 sec)


mysql> select user,host,password from user;

+------+-----------+-------------------------------------------+

| user | host      | password                                  |

+------+-----------+-------------------------------------------+

| root | localhost | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 |

| root | mysqldb1  | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 |

| root | 127.0.0.1 | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 |

| root | ::1       | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 |

+------+-----------+-------------------------------------------+

4 rows in set (0.00 sec)



二、mysql多實例實現:


1、mysql多實例的原理

mysql多實例,簡單的說,就是在一臺服務器上開啓多個不同的mysql服務端口(如3306,3307),運行多個mysql服務進程。這些服務進程通過不同的socket監聽不同的服務端口,來提供各自的服務。

這些mysql實例共用一套mysql安裝程序,使用不同的my.cnf配置文件、啓動程序、數據文件。在提供服務時,mysql多實例在邏輯上看來是各自獨立的,各個實例之間根據配置文件的設定值,來取得服務器的相關硬件資源。



2、mysql多實例的特點


2.1 有效的利用服務器資源

當單個服務器資源有剩餘時,可以充分利用剩餘的服務器資源來提供更多的服務。


2.2 節約服務器資源

當公司資金緊張,但是數據庫需要各自提供獨立服務,而且需要主從同步等技術時,使用多實例就最好了。


2.3 出現資源互相搶佔問題

當某個實例服務併發很高或者有慢查詢時,會消耗服務器更多的內存、CPU、磁盤IO等資源,這時就會導致服務器上的其它實例提供訪問的質量下降,出現服務器資源互相搶佔的現象。


3、mysql多實例應用場景


3.1 資金緊張型公司的選擇

當公司業務訪問量不太大,又捨不得花錢,但同時又希望不同業務的數據庫服務各自獨立,而且需要主從同步進行等技術提供備份或讀寫分離服務時,使用多實例是最好不過的。


3.2 併發訪問不是特別大的業務

當公司業務訪問量不太大,服務器資源基本閒置的比較多,這是就很適合多實例的應用。如果對SQL語句優化的好,多實例是一個很值得使用的技術。即使併發很大,只要合理分配好系統資源,也不會有太大問題。


4、mysql5.5多實例部署方法


4.1 mysql5.5多實例部署方法

mysql5.5多實例部署方法一個是通過多個配置文件啓動多個不同進程的方法,第二個是使用官方自帶的mysqld_multi來實現。

第一種方法我們可以把各個實例的配置文件分開,管理比較方便。第二種方法就是把多個實例都放到一個配置文件中,這個管理不是很方便。所以在此我們選擇第一種方法,而且以下實驗我們全部是在此方法下進行的。


4.2 mysql5.5的安裝及配置

要配置mysql5.5多實例,我們首先要安裝mysql5.5,mysql5.5安裝完畢後,我們不要啓動mysql,因爲此時mysql是單實例的。


5、使用多個配置文件啓動多個不同進程:

這種架構是使用多個配置文件啓動不同的進程來實現多實例,這種方式的優勢邏輯簡單,配置簡單,缺點是管理起來不太方便,但相對獨立,使mysql的耦合度降低了許多。

[root@mysqldb1 mysql]# mkdir -p /mysqldata/330{6,7,8}/ 


5.1、配置端口號爲3306的mysql實例

5.1.1、配置3306的my.cnf文件

[root@mysqldb1 mysql5.6.27]# vim /mysqldata/3306/my.cnf

[client]

port = 3306

socket = /mysqldata/3306/mysql.sock

[mysqld]

datadir=/mysqldata/3306/

skip-name-resolve

lower_case_table_names=1

innodb_file_per_table=1

port = 3306

socket = /mysqldata/3306/mysql.sock

back_log = 50

max_connections = 300

max_connect_errors = 1000

table_open_cache = 2048

max_allowed_packet = 16M

binlog_cache_size = 2M

max_heap_table_size = 32M

sort_buffer_size = 2M

join_buffer_size = 2M

thread_cache_size = 64

thread_concurrency = 8

query_cache_size = 64M

query_cache_limit = 2M

ft_min_word_len = 4

default-storage-engine = innodb

thread_stack = 192K

transaction_isolation = REPEATABLE-READ

tmp_table_size = 32M

log-bin=mysql-bin

binlog_format=mixed

slow_query_log

long_query_time = 1

server-id = 1

key_buffer_size = 8M

read_buffer_size = 2M

read_rnd_buffer_size = 2M

bulk_insert_buffer_size = 32M

myisam_sort_buffer_size = 64M

myisam_max_sort_file_size = 10G

myisam_repair_threads = 1

myisam_recover

innodb_additional_mem_pool_size = 8M

innodb_buffer_pool_size = 100M

innodb_data_file_path = ibdata1:10M:autoextend

innodb_file_io_threads = 8

innodb_thread_concurrency = 16

innodb_flush_log_at_trx_commit = 1

innodb_log_buffer_size = 8M

innodb_log_file_size = 256M

innodb_log_files_in_group = 3

innodb_max_dirty_pages_pct = 60

innodb_lock_wait_timeout = 120

[mysqldump]

quick

max_allowed_packet = 128M

[mysql]

no-auto-rehash

prompt=\\u@\\d \\R:\\m>

[myisamchk]

key_buffer_size = 256M

sort_buffer_size = 256M

read_buffer = 8M

write_buffer = 8M

[mysqlhotcopy]

interactive-timeout

[mysqld_safe]

open-files-limit = 1024


5.1.2、啓動端口號爲3306的實例並設置密碼:


#安裝端口號爲3306的mysql實例:

[root@mysqldb1 mysql5.6.27]# /usr/local/mysql5.6.27/scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql5.6.27 --datadir=/mysqldata/3306  --defaults-file=/mysqldata/3306/my.cnf


#啓動端口號爲3306的mysql實例:

[root@mysqldb1 mysqldata]# /usr/local/mysql5.6.27/bin/mysqld_safe --defaults-file=/mysqldata/3306/my.cnf 2>&1 > /dev/null &

[2] 5846


#給端口號爲3306的mysql實例設置密碼:

[root@mysqldb1 mysql5.6.27]# /usr/local/mysql5.6.27/bin/mysqladmin -uroot password '123456' -S /mysqldata/3306/mysql.sock 

Warning: Using a password on the command line interface can be insecure.


#登陸端口號爲3306的mysql實例服務器:

[root@mysqldb1 mysql5.6.27]# mysql -uroot -p123456 -S /mysqldata/3306/mysql.sock 

Warning: Using a password on the command line interface can be insecure.

Welcome to the MySQL monitor.  Commands end with ; or \g.

Your MySQL connection id is 5

Server version: 5.6.27-log Source distribution


Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved.


Oracle is a registered trademark of Oracle Corporation and/or its

affiliates. Other names may be trademarks of their respective

owners.


Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.


mysql> 



5.1.3設置mysql的腳本啓動文件:

[root@mysqldb1 mysql5.6.27]# vim /mysqldata/3306/mysqld


#!/bin/bash

mysql_port=3306

mysql_username="root"

mysql_password="123456"

function_start_mysql()

{

printf "Starting MySQL...\n"

/bin/sh /usr/local/mysql5.6.27/bin/mysqld_safe  --defaults-file=/mysqldata/${mysql_port}/my.cnf 2>&1 > /dev/null &

}

function_stop_mysql()

{

printf "Stoping MySQL...\n"

/usr/local/mysql5.6.27/bin/mysqladmin -u ${mysql_username} -p${mysql_password} -S /mysqldata/${mysql_port}/mysql.sock shutdown

}

function_restart_mysql()

{

printf "Restarting MySQL...\n"

function_stop_mysql

function_start_mysql

}

function_kill_mysql()

{

kill -9 $(ps -ef | grep 'bin/mysqld_safe' | grep ${mysql_port} | awk '{printf $2}')

kill -9 $(ps -ef | grep 'libexec/mysqld' | grep ${mysql_port} | awk '{printf $2}')

}

case $1 in

start)

function_start_mysql;;

stop)

function_stop_mysql;;

kill)

function_kill_mysql;;

restart)

function_stop_mysql

function_start_mysql;;

*)

echo "Usage: /mysqldata/${mysql_port}/mysqld {start|stop|restart|kill}";;

esac


5.1.4、測試啓動進程:

#啓動端口號爲3306的mysql

[root@mysqldb1 mysql5.6.27]# /mysqldata/3306/mysqld start

Starting MySQL...

[root@mysqldb1 mysql5.6.27]# netstat -tulnp | grep 3306

tcp        0      0 :::3306                     :::*                        LISTEN      46977/mysqld        


#重啓端口號爲3306的mysql

[root@mysqldb1 mysql5.6.27]# /mysqldata/3306/mysqld restart

Stoping MySQL...

Warning: Using a password on the command line interface can be insecure.

Starting MySQL...

[root@mysqldb1 mysql5.6.27]# netstat -tulnp | grep 3306

tcp        0      0 :::3306                     :::*                        LISTEN      47669/mysqld


#停止端口號爲3306的mysql      

[root@mysqldb1 mysql5.6.27]# /mysqldata/3306/mysqld stop

Stoping MySQL...

Warning: Using a password on the command line interface can be insecure.

[root@mysqldb1 mysql5.6.27]# netstat -tulnp | grep 3306


5.2、配置端口號爲3307、3308的mysql實例:

5.2.1、複製目錄/mysqldata/3306下的配置文件my.cnf和啓動腳本分別到 /mysqldata/3307 和 /mysqldata/3308 目錄下

[root@mysqldb1 mysqldata]# cd /mysqldata/3306

[root@mysqldb1 3306]# cp my.cnf mysqld ../3307/

[root@mysqldb1 3306]# cp my.cnf mysqld ../3308/


5.2.3、分別修改端口號爲3307、3308的配置文件和啓動文件

[root@mysqldb1 3307]# cd ../3308

[root@mysqldb1 3308]# sed -i 's/3306/3308/g' mysqld 

[root@mysqldb1 3308]# sed -i 's/3306/3308/g' my.cnf 

[root@mysqldb1 3308]# sed -i 's/3306/3307/g' ../3307/my.cnf 

[root@mysqldb1 3308]# sed -i 's/3306/3307/g' ../3307/mysqld


5.2.4、分別安裝端口號爲3307、3308的mysql實例數據庫

#初始化端口號爲3307的實例數據庫:

[root@mysqldb1 3308]# /usr/local/mysql5.6.27/scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql5.6.27 --datadir=/mysqldata/3307 --defaults-file=/mysqldata/3307/my.cnf


#初始化端口號爲3308的實例數據庫:

[root@mysqldb1 3308]# /usr/local/mysql5.6.27/scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql5.6.27 --datadir=/mysqldata/3308 --defaults-file=/mysqldata/3308/my.cnf


5.2.5、分別啓動端口號爲3307、3308的mysql實例數據庫

#啓動端口號爲3307的實例:

[root@mysqldb1 3308]# /usr/local/mysql5.6.27/bin/mysqld_safe  --defaults-file=/mysqldata/3307/my.cnf 2>&1 >/dev/null &

[1] 47969


#啓動端口號爲3308的實例:

[root@mysqldb1 3308]# /usr/local/mysql5.6.27/bin/mysqld_safe  --defaults-file=/mysqldata/3308/my.cnf 2>&1 >/dev/null &

[2] 48654


#查看mysql實例的啓動情況:

[root@mysqldb1 3308]# netstat -tulnp | grep 330

tcp        0      0 :::3307                     :::*                        LISTEN      48632/mysqld        

tcp        0      0 :::3308                     :::*                        LISTEN      49317/mysqld   


5.2.6、分別修改端口號爲3307、3308的mysql實例的管理員密碼

#修改端口號爲3307實例的管理員root用戶的密碼:

[root@mysqldb1 3308]# /usr/local/mysql5.6.27/bin/mysqladmin -uroot password '123456' -S /mysqldata/3307/mysql.sock 

Warning: Using a password on the command line interface can be insecure.


#修改端口號爲3308實例的管理員root用戶的密碼:

[root@mysqldb1 3308]# /usr/local/mysql5.6.27/bin/mysqladmin -uroot password '123456' -S /mysqldata/3308/mysql.sock 

Warning: Using a password on the command line interface can be insecure.


5.2.7、分別使用mysql客戶端登陸命令登陸端口號爲3307、3308的mysql實例服務器

#登陸端口號爲3307的mysql實例服務器:

[root@mysqldb1 3308]# mysql -uroot -p123456 -S /mysqldata/3307/mysql.sock 

Warning: Using a password on the command line interface can be insecure.

Welcome to the MySQL monitor.  Commands end with ; or \g.

Your MySQL connection id is 5

Server version: 5.6.27-log Source distribution


Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved.


Oracle is a registered trademark of Oracle Corporation and/or its

affiliates. Other names may be trademarks of their respective

owners.


Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.


mysql> show databases;

+--------------------+

| Database           |

+--------------------+

| information_schema |

| mysql              |

| performance_schema |

| test               |

+--------------------+

4 rows in set (0.00 sec)


#在端口號爲3307的mysql實例中登陸端口號爲3308的mysql實例服務器:

mysql> system mysql -uroot -p123456 -S /mysqldata/3308/mysql.sock

Warning: Using a password on the command line interface can be insecure.

Welcome to the MySQL monitor.  Commands end with ; or \g.

Your MySQL connection id is 3

Server version: 5.6.27-log Source distribution


Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved.


Oracle is a registered trademark of Oracle Corporation and/or its

affiliates. Other names may be trademarks of their respective

owners.


Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.


mysql> show databases;

+--------------------+

| Database           |

+--------------------+

| information_schema |

| mysql              |

| performance_schema |

| test               |

+--------------------+

4 rows in set (0.00 sec)


mysql> quit

Bye

mysql> quit

Bye


5.2.8、分別使用mysql啓動腳本測試端口號爲3307、3308的mysql實例服務器


5.2.8.1、殺掉剛剛啓動的mysql多例進程:

[root@mysqldb1 3308]# pkill mysqld

[root@mysqldb1 3308]# netstat -tulnp | grep 330

[1]-  Done                    /usr/local/mysql5.6.27/bin/mysqld_safe --defaults-file=/mysqldata/3307/my.cnf 2>&1 > /dev/null

[2]+  Done                    /usr/local/mysql5.6.27/bin/mysqld_safe --defaults-file=/mysqldata/3308/my.cnf 2>&1 > /dev/null

[root@mysqldb1 3308]# netstat -tulnp | grep 330


5.2.8.2、測試端口號爲3307的服務器登陸腳本:

#啓動端口號爲3307的mysql

[root@mysqldb1 3308]# /mysqldata/3307/mysqld start

Starting MySQL...

[root@mysqldb1 3308]# netstat -tulnp | grep 3307

tcp        0      0 :::3307                     :::*                        LISTEN      50710/mysqld         


#重啓端口號爲3307的mysql

[root@mysqldb1 3308]# /mysqldata/3307/mysqld restart

Stoping MySQL...

Warning: Using a password on the command line interface can be insecure.

Starting MySQL...

[root@mysqldb1 3308]# netstat -tulnp | grep 3307

tcp        0      0 :::3307                     :::*                        LISTEN      51403/mysqld  


#停止端口號爲3307的mysql      

[root@mysqldb1 3308]# /mysqldata/3307/mysqld stop

Stoping MySQL...

Warning: Using a password on the command line interface can be insecure.

[root@mysqldb1 3308]# netstat -tulnp | grep 3307


5.2.8.3、測試端口號爲3308的服務器登陸腳本:

#啓動端口號爲3308的mysql

[root@mysqldb1 3308]# /mysqldata/3308/mysqld start

Starting MySQL...

[root@mysqldb1 3308]# netstat -tulnp | grep 3308

tcp        0      0 :::3308                     :::*                        LISTEN      52104/mysqld       


#重啓端口號爲3308的mysql

[root@mysqldb1 3308]# netstat -tulnp | grep 3308

tcp        0      0 :::3308                     :::*                        LISTEN      52104/mysqld        

[root@mysqldb1 3308]# /mysqldata/3308/mysqld restart

Stoping MySQL...

Warning: Using a password on the command line interface can be insecure.

Starting MySQL...

[root@mysqldb1 3308]# netstat -tulnp | grep 3308

tcp        0      0 :::3308                     :::*                        LISTEN      52797/mysqld


#停止端口號爲3308的mysql      

[root@mysqldb1 3308]# /mysqldata/3308/mysqld stop

Stoping MySQL...

Warning: Using a password on the command line interface can be insecure.

[root@mysqldb1 3308]# netstat -tulnp | grep 3308



5.2.9、分別啓動端口號爲3306、3307、3308的實例

[root@mysqldb1 ~]# for mport in 3306 3307 3308 ; do /mysqldata/$mport/mysqld start;done

Starting MySQL...

Starting MySQL...

Starting MySQL...

[root@mysqldb1 ~]# netstat -tulnp | grep 330

tcp        0      0 :::3307                     :::*                        LISTEN      12459/mysqld        

tcp        0      0 :::3308                     :::*                        LISTEN      12441/mysqld        

tcp        0      0 :::3306                     :::*                        LISTEN      12460/mysqld   


5.2.10、分別重啓端口號爲3306、3307、3308的實例

[root@mysqldb1 ~]# for mport in 3306 3307 3308 ; do /mysqldata/$mport/mysqld restart; sleep 1 ;done

Stoping MySQL...

Warning: Using a password on the command line interface can be insecure.

Starting MySQL...

Stoping MySQL...

Warning: Using a password on the command line interface can be insecure.

Starting MySQL...

Stoping MySQL...

Warning: Using a password on the command line interface can be insecure.

Starting MySQL...

[root@mysqldb1 ~]# netstat -tulnp | grep 330

tcp        0      0 :::3307                     :::*                        LISTEN      12884/mysqld        

tcp        0      0 :::3308                     :::*                        LISTEN      13070/mysqld  


5.2.11、分別停止端口號爲3306、3307、3308的實例

[root@mysqldb1 ~]# for mport in 3306 3307 3308 ; do /mysqldata/$mport/mysqld stop; sleep 1 ;done

Stoping MySQL...

Warning: Using a password on the command line interface can be insecure.

Stoping MySQL...

Warning: Using a password on the command line interface can be insecure.

Stoping MySQL...

Warning: Using a password on the command line interface can be insecure.

[root@mysqldb1 ~]# netstat -tulnp | grep 330



6、第二種通過官方自帶的mysqld_multi來實現多實例實戰

6.1、創建目錄

[root@mysqldb1 ~]# /mysqlmulti/330{6,7,8}/

[root@mysqldb1 ~]# /mysqldata/

[root@mysqldb1 mysqlmulti]# mkdir conf


6.2、編輯配置文件

[root@mysqldb1 mysqlmulti]# vim conf/my.cnf 


[mysqld_multi]

mysqld = /usr/local/mysql5.6.27/bin/mysqld_safe

mysqladmin = /usr/local/mysql5.6.27/bin/mysqladmin

user = root

password = 123456


[mysqld1]

socket = /mysqlmulti/3306/mysql.sock

port = 3306

pid-file = /mysqlmulti/3306/mysql3306.pid

datadir = /mysqlmulti/3306

user = mysql

skip-name-resolve

lower_case_table_names=1

innodb_file_per_table=1

back_log = 50

max_connections = 300

max_connect_errors = 1000

table_open_cache = 2048

max_allowed_packet = 16M

binlog_cache_size = 2M

max_heap_table_size = 64M

sort_buffer_size = 2M

join_buffer_size = 2M

thread_cache_size = 64

thread_concurrency = 8

query_cache_size = 64M

query_cache_limit = 2M

ft_min_word_len = 4

default-storage-engine = innodb

thread_stack = 192K

transaction_isolation = REPEATABLE-READ

tmp_table_size = 64M

log-bin=mysql-bin

binlog_format=mixed

slow_query_log

long_query_time = 1

server-id = 1

key_buffer_size = 8M

read_buffer_size = 2M

read_rnd_buffer_size = 2M

bulk_insert_buffer_size = 64M

myisam_sort_buffer_size = 128M

myisam_max_sort_file_size = 10G

myisam_repair_threads = 1

myisam_recover

innodb_additional_mem_pool_size = 16M

innodb_buffer_pool_size = 200M

innodb_data_file_path = ibdata1:10M:autoextend

innodb_file_io_threads = 8

innodb_thread_concurrency = 16

innodb_flush_log_at_trx_commit = 1

innodb_log_buffer_size = 16M

innodb_log_file_size = 512M

innodb_log_files_in_group = 3

innodb_max_dirty_pages_pct = 60

innodb_lock_wait_timeout = 120


[mysqld2]

socket = /mysqlmulti/3307/mysql.sock

port = 3307

pid-file = /mysqlmulti/3307/mysql3307.pid

datadir = /mysqlmulti/3307

user = mysql

skip-name-resolve

lower_case_table_names=1

innodb_file_per_table=1

back_log = 50

max_connections = 300

max_connect_errors = 1000

table_open_cache = 2048

max_allowed_packet = 16M

binlog_cache_size = 2M

max_heap_table_size = 64M

sort_buffer_size = 2M

join_buffer_size = 2M

thread_cache_size = 64

thread_concurrency = 8

query_cache_size = 64M

query_cache_limit = 2M

ft_min_word_len = 4

default-storage-engine = innodb

thread_stack = 192K

transaction_isolation = REPEATABLE-READ

tmp_table_size = 64M

log-bin=mysql-bin

binlog_format=mixed

slow_query_log

long_query_time = 1

server-id = 1

key_buffer_size = 8M

read_buffer_size = 2M

read_rnd_buffer_size = 2M

bulk_insert_buffer_size = 64M

myisam_sort_buffer_size = 128M

myisam_max_sort_file_size = 10G

myisam_repair_threads = 1

myisam_recover

innodb_additional_mem_pool_size = 16M

innodb_buffer_pool_size = 200M

innodb_data_file_path = ibdata1:10M:autoextend

innodb_file_io_threads = 8

innodb_thread_concurrency = 16

innodb_flush_log_at_trx_commit = 1

innodb_log_buffer_size = 16M

innodb_log_file_size = 512M

innodb_log_files_in_group = 3

innodb_max_dirty_pages_pct = 60

innodb_lock_wait_timeout = 120


[mysqld3]

socket = /mysqlmulti/3308/mysql.sock

port = 3308

pid-file = /mysqlmulti/3308/mysql3308.pid

datadir = /mysqlmulti/3308

user = mysql

skip-name-resolve

lower_case_table_names=1

innodb_file_per_table=1

back_log = 50

max_connections = 300

max_connect_errors = 1000

table_open_cache = 2048

max_allowed_packet = 16M

binlog_cache_size = 2M

max_heap_table_size = 64M

sort_buffer_size = 2M

join_buffer_size = 2M

thread_cache_size = 64

thread_concurrency = 8

query_cache_size = 64M

query_cache_limit = 2M

ft_min_word_len = 4

default-storage-engine = innodb

thread_stack = 192K

transaction_isolation = REPEATABLE-READ

tmp_table_size = 64M

log-bin=mysql-bin

binlog_format=mixed

slow_query_log

long_query_time = 1

server-id = 1

key_buffer_size = 8M

read_buffer_size = 2M

read_rnd_buffer_size = 2M

bulk_insert_buffer_size = 64M

myisam_sort_buffer_size = 128M

myisam_max_sort_file_size = 10G

myisam_repair_threads = 1

myisam_recover

innodb_additional_mem_pool_size = 16M

innodb_buffer_pool_size = 200M

innodb_data_file_path = ibdata1:10M:autoextend

innodb_file_io_threads = 8

innodb_thread_concurrency = 16

innodb_flush_log_at_trx_commit = 1

innodb_log_buffer_size = 16M

innodb_log_file_size = 512M

innodb_log_files_in_group = 3

innodb_max_dirty_pages_pct = 60

innodb_lock_wait_timeout = 120

[mysqldump]

quick

max_allowed_packet = 256M

[mysql]

no-auto-rehash

prompt=\\u@\\d \\R:\\m>

[myisamchk]

key_buffer_size = 512M

sort_buffer_size = 512M

read_buffer = 8M

write_buffer = 8M

[mysqlhotcopy]

interactive-timeout

[mysqld_safe]

open-files-limit = 8192


6.3、初始化端口爲3306、3307、3308的mysql數據庫

[root@mysqldb1 mysqlmulti]# /usr/local/mysql5.6.27/scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql5.6.27 --datadir=/mysqlmulti/3306

[root@mysqldb1 mysqlmulti]# /usr/local/mysql5.6.27/scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql5.6.27 --datadir=/mysqlmulti/3307

[root@mysqldb1 mysqlmulti]# /usr/local/mysql5.6.27/scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql5.6.27 --datadir=/mysqlmulti/3308


6.4、啓動測試啓動多實例數據庫

[root@mysqldb1 mysqlmulti]# /usr/local/mysql5.6.27/bin/mysqld_multi --defaults-file=/mysqlmulti/conf/my.cnf --user=mysql start 1-3

[root@mysqldb1 mysqlmulti]# netstat -tulnp | grep 330

tcp        0      0 :::3307                     :::*                        LISTEN      47763/mysqld        

tcp        0      0 :::3308                     :::*                        LISTEN      47699/mysqld        

tcp        0      0 :::3306                     :::*                        LISTEN      47764/mysqld    


6.5、停止mysql多實例數據庫

[root@mysqldb1 mysqlmulti]# pkill mysql

[root@mysqldb1 mysqlmulti]# netstat -tulnp | grep 330


6.6、編寫啓動、停止、重啓的控制腳本

[root@mysqldb1 mysqlmulti]# vim mysqld_multi


#!/bin/bash


basedir=/usr/local/mysql5.6.27

bindir=/usr/local/mysql5.6.27/bin

cfgfile=/mysqlmulti/conf/my.cnf

if test -x $bindir/mysqld_multi

then

  my_multi="$bindir/mysqld_multi";

else

  echo "Can't execute $bindir/mysqld_multi from dir $basedir";

  exit;

fi

echo $my_multi

function startmulti(){

echo "Starting multi mysqld ......"

"$my_multi"  --defaults-file=$cfgfile  start $2

sleep 5

echo "Started multi mysqld ......" 

}


function stopmulti(){

echo "Stopping multi mysqld ......"

ps -ef | /bin/grep /bin/mysqld | /bin/grep -v grep | /bin/awk '{print $2}' | /usr/bin/xargs kill -s 9 

echo "Stopped multi mysqld ......" 

}


function restartmulti(){

stopmulti

startmulti $2

}

case "$1" in

    'start' )

        startmulti $2

;;

    'stop' )

        stopmulti

;;

    'restart' )

restartmulti $2

;;

    *)

        echo "Usage: $0 {start|stop|restart}" >&2

        ;;

esac


6.7、給啓動腳本授可執行權限

[root@mysqldb1 mysqlmulti]# chmod +x mysqld_multi 

[root@mysqldb1 mysqlmulti]# ll ./

total 20

drwxr-xr-x. 5 mysql mysql 4096 Oct 19 11:42 3306

drwxr-xr-x. 5 mysql mysql 4096 Oct 19 11:42 3307

drwxr-xr-x. 5 mysql mysql 4096 Oct 19 11:42 3308

drwxr-xr-x. 2 root  root  4096 Oct 19 09:34 conf

-rwxr-xr-x. 1 root  root   888 Oct 19 11:43 mysqld_multi


6.8、測試腳本是否正常

6.8.1、啓動mysql多個實例

[root@mysqldb1 mysqlmulti]# ./mysqld_multi start 1-3

/usr/local/mysql5.6.27/bin/mysqld_multi

Starting multi mysqld ......

Started multi mysqld ......

[root@mysqldb1 mysqlmulti]# netstat -tlnpu | grep 330

tcp        0      0 :::3307                     :::*                        LISTEN      5127/mysqld         

tcp        0      0 :::3308                     :::*                        LISTEN      5126/mysqld         

tcp        0      0 :::3306                     :::*                        LISTEN      5102/mysqld   


6.8.2、重啓mysql多個實例      

[root@mysqldb1 mysqlmulti]# ./mysqld_multi restart 1-3

/usr/local/mysql5.6.27/bin/mysqld_multi

Stopping multi mysqld ......

Stopped multi mysqld ......

Starting multi mysqld ......

Started multi mysqld ......

[root@mysqldb1 mysqlmulti]# netstat -tlnpu | grep 330

tcp        0      0 :::3307                     :::*                        LISTEN      7993/mysqld         

tcp        0      0 :::3308                     :::*                        LISTEN      7999/mysqld         

tcp        0      0 :::3306                     :::*                        LISTEN      7959/mysqld   


6.8.3、關閉mysql實例  

[root@mysqldb1 mysqlmulti]# ./mysqld_multi stop

/usr/local/mysql5.6.27/bin/mysqld_multi

Stopping multi mysqld ......

Stopped multi mysqld ......

[root@mysqldb1 mysqlmulti]# netstat -tlnpu | grep 330


6.8.4、單配置文件mysql用戶密碼密碼:

1、啓動mysql多實例

[root@mysqldb1 ~]# /mysqlmulti/mysqld_multi start 1-3


2、修改每個實例的管理員密碼

[root@mysqldb1 ~]# for mport in  3306 3307 3308 ; do /usr/local/mysql5.6.27/bin/mysqladmin -uroot password '123456' -S /mysqlmulti/$mport/mysql.sock ; done

Warning: Using a password on the command line interface can be insecure.

Warning: Using a password on the command line interface can be insecure.

Warning: Using a password on the command line interface can be insecure.


3、使用命令登陸mysql各個實例進程

#使用命令登陸端口號爲3306的mysql實例

[root@mysqldb1 ~]# mysql -uroot -p123456 -S /mysqlmulti/3306/mysql.sock

Warning: Using a password on the command line interface can be insecure.

Welcome to the MySQL monitor.  Commands end with ; or \g.

Your MySQL connection id is 5

Server version: 5.6.27-log Source distribution


Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved.


Oracle is a registered trademark of Oracle Corporation and/or its

affiliates. Other names may be trademarks of their respective

owners.


Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.


#查看端口號爲3306的mysql實例的狀態信息。

mysql> status

--------------

mysql  Ver 14.14 Distrib 5.6.27, for Linux (x86_64) using  EditLine wrapper


Connection id: 5

Current database:

Current user: root@localhost

SSL: Not in use

Current pager: stdout

Using outfile: ''

Using delimiter: ;

Server version: 5.6.27-log Source distribution

Protocol version: 10

Connection: Localhost via UNIX socket

Server characterset: utf8

Db     characterset: utf8

Client characterset: utf8

Conn.  characterset: utf8

UNIX socket: /mysqlmulti/3306/mysql.sock

Uptime: 13 min 27 sec


Threads: 1  Questions: 47  Slow queries: 0  Opens: 87  Flush tables: 1  Open tables: 80  Queries per second avg: 0.058

--------------


#在端口號爲3306的mysql實例中登陸端口號爲3307的mysql實例服務器,其中system是在不離開mysql服務器的同時能夠執行linux外部命令的函數。

mysql> system mysql -uroot -p123456 -S /mysqlmulti/3307/mysql.sock

Warning: Using a password on the command line interface can be insecure.

Welcome to the MySQL monitor.  Commands end with ; or \g.

Your MySQL connection id is 3

Server version: 5.6.27-log Source distribution


Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved.


Oracle is a registered trademark of Oracle Corporation and/or its

affiliates. Other names may be trademarks of their respective

owners.


Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

#端口號爲3307的mysql實例的狀態信息。

mysql> status

--------------

mysql  Ver 14.14 Distrib 5.6.27, for Linux (x86_64) using  EditLine wrapper


Connection id: 3

Current database:

Current user: root@localhost

SSL: Not in use

Current pager: stdout

Using outfile: ''

Using delimiter: ;

Server version: 5.6.27-log Source distribution

Protocol version: 10

Connection: Localhost via UNIX socket

Server characterset: utf8

Db     characterset: utf8

Client characterset: utf8

Conn.  characterset: utf8

UNIX socket: /mysqlmulti/3307/mysql.sock

Uptime: 14 min 25 sec


Threads: 1  Questions: 16  Slow queries: 0  Opens: 70  Flush tables: 1  Open tables: 63  Queries per second avg: 0.018

--------------

#登陸端口號爲3308的mysql實例

mysql> system mysql -uroot -p123456 -S /mysqlmulti/3308/mysql.sock

Warning: Using a password on the command line interface can be insecure.

Welcome to the MySQL monitor.  Commands end with ; or \g.

Your MySQL connection id is 2

Server version: 5.6.27-log Source distribution


Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved.


Oracle is a registered trademark of Oracle Corporation and/or its

affiliates. Other names may be trademarks of their respective

owners.


Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

#端口號爲3307的mysql實例的狀態信息。

mysql> status

--------------

mysql  Ver 14.14 Distrib 5.6.27, for Linux (x86_64) using  EditLine wrapper


Connection id: 2

Current database:

Current user: root@localhost

SSL: Not in use

Current pager: stdout

Using outfile: ''

Using delimiter: ;

Server version: 5.6.27-log Source distribution

Protocol version: 10

Connection: Localhost via UNIX socket

Server characterset: utf8

Db     characterset: utf8

Client characterset: utf8

Conn.  characterset: utf8

UNIX socket: /mysqlmulti/3308/mysql.sock

Uptime: 15 min 5 sec


Threads: 1  Questions: 10  Slow queries: 0  Opens: 70  Flush tables: 1  Open tables: 63  Queries per second avg: 0.011

--------------

#逐級退出mysql客戶端實例

mysql> quit 

Bye

mysql> quit

Bye

mysql> quit

Bye


mysqladmin 優雅關閉mysql







發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章