程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 數據庫知識 >> MYSQL數據庫 >> 關於MYSQL數據庫 >> Linux安裝多個MySQL

Linux安裝多個MySQL

編輯:關於MYSQL數據庫

  1、按照常規安裝。

[root@ff_girl MySQL5122]# chown -R root .
[root@ff_girl mysql5122]# chown -R MySQL data
[root@ff_girl mysql5122]# chgrp -R MySQL .
[root@ff_girl MySQL5122]# cp support-files/my-small.cnf /etc/my5122.cnf
[root@ff_girl mysql5122]# scripts/mysql_install_db --basedir=/usr/local/mysql5122/ --datadir=/usr/local/mysql5122/data/ --user=MySQL
Installing MySQL system tables...
OK
Filling help tables...
OK

To start MySQLd at boot time you have to copy
support-files/MySQL.server to the right place for your system

。。。

  首次啟動MySQL

[root@ff_girl mysql5122]# bin/MySQLd_safe --defaults-file=/etc/my5122.cnf &
[1] 13700
[root@ff_girl mysql5122]# 080124 15:01:46 mysqld_safe Logging to '/usr/local/MySQL5122/data/localhost.localdomain.err'.
080124 15:01:46 mysqld_safe Starting mysqld daemon with databases from /usr/local/MySQL5122/data

[root@ff_girl mysql5122]# bin/mysql -uroot -p -S/tmp/MySQL5122.sock
Enter passWord:
Welcome to the MySQL monitor. Commands end with ; or g.
Your MySQL connection id is 1
Server version: 5.1.22-rc MySQL Community Server (GPL)

Type 'help;' or 'h' for help. Type 'c' to clear the buffer.

MySQL> show databases;
+--------------------+
| Database      |
+--------------------+
| information_schema |
| MySQL       |
| test        |
+--------------------+
3 rows in set (0.00 sec)

  給MySQLD_MULTI賦SHUTDOWN權限。

MySQL> grant shutdown on *.* to multi_admin@'localhost' identifIEd by '123456';
Query OK, 0 rows affected (0.00 sec)

MySQL> flush privileges;
Query OK, 0 rows affected (0.00 sec)

MySQL> exit
Bye

  停掉MySQL服務。

[root@ff_girl ~]# /usr/local/mysql5122/bin/mysqladmin -uroot -p -S/tmp/MySQL5122.sock shutdown
Enter passWord:
[root@ff_girl ~]#

  拷貝元數據。

[root@ff_girl MySQL5122]# cp data data2
[root@ff_girl MySQL5122]# mv data data1
[root@ff_girl mysql5122]# chown -R MySQL data2
[root@ff_girl mysql5122]# chgrp -R MySQL .

  示例配置文件

  [
root@ff_girl MySQL5122]# cat /etc/my5122.cnf
[MySQLd_multi]
mysqld   = /usr/local/mysql5122/bin/MySQLd_safe
mysqladmin = /usr/local/mysql5122/bin/MySQLadmin
user    = multi_admin
passWord  = 123456
# The MySQL Server
[MySQLd1]
socket   = /tmp/MySQL1.sock
port    = 3307
pid-file  = /usr/local/MySQL5122/data1/david_yeung.pid1
datadir  = /usr/local/MySQL5122/data1
language  = /usr/local/mysql5122/share/MySQL/english
user    = MySQL
# The MySQL Server
[MySQLd2]
port      = 3308
socket     = /tmp/MySQL2.sock
pid-file  = /usr/local/MySQL5122/data2/david_yeung.pid2
datadir  = /usr/local/MySQL5122/data2
language  = /usr/local/mysql5122/share/MySQL/english
user    = MySQL
。。。
[isamchk]
key_buffer = 8M
sort_buffer_size = 8M

[myisamchk]
key_buffer = 8M
sort_buffer_size = 8M

[MySQLhotcopy]
interactive-timeout
[root@ff_girl MySQL5122]#

  啟動兩個MySQL服務

[root@ff_girl mysql5122]# /usr/local/mysql5122/bin/MySQLd_multi --config-file=/etc/my5122.cnf start 1-2
[root@ff_girl MySQL5122]# netstat -an | grep 3307
tcp    0   0 0.0.0.0:3307        0.0.0.0:*          LISTEN   
[root@ff_girl MySQL5122]# netstat -an | grep 3308
tcp    0   0 0.0.0.0:3308        0.0.0.0:*          LISTEN   
[root@ff_girl mysql5122]# /usr/local/mysql/bin/mysql -uroot -p -S/tmp/MySQL1.sock
Enter passWord:
Welcome to the MySQL monitor. Commands end with ; or g.
Your MySQL connection id is 1
Server version: 5.1.22-rc-log MySQL Community Server (GPL)

Type 'help;' or 'h' for help. Type 'c' to clear the buffer.

MySQL> q
Bye
[root@ff_girl mysql5122]# /usr/local/mysql/bin/mysql -uroot -p -S/tmp/MySQL2.sock
Enter passWord:
Welcome to the MySQL monitor. Commands end with ; or g.
Your MySQL connection id is 1
Server version: 5.1.22-rc-log MySQL Community Server (GPL)

Type 'help;' or 'h' for help. Type 'c' to clear the buffer.

MySQL> q
Bye
[root@ff_girl MySQL5122]#

  2、另外一種。

[root@ff_girl MySQL512]# chown -R root .
[root@ff_girl mysql512]# chown -R MySQL data
[root@ff_girl mysql512]# chgrp -R MySQL .
[root@ff_girl mysql512]# scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql512/ --datadir=/usr/local/MySQL512/data/
[root@ff_girl MySQL512]# cp support-files/my-huge.cnf /etc/my512.cnf

  並且修改如下部分。

[clIEnt]
port      = 3308
socket     = /tmp/MySQL512.sock

# The MySQL Server
[MySQLd]
user=MySQL
basedir=/usr/local/MySQL512
datadir=/usr/local/MySQL512/data
port      = 3308
socket     = /tmp/MySQL512.sock

[root@ff_girl mysql512]# /usr/local/mysql512/bin/MySQLd_safe --defaults-file=/etc/my512.cnf &
[root@ff_girl mysql512]# /usr/local/mysql/bin/mysql -uroot -p -S/tmp/MySQL512.sock
Enter passWord:
Welcome to the MySQL monitor. Commands end with ; or g.
Your MySQL connection id is 1
Server version: 5.1.22-rc-log MySQL Community Server (GPL)

Type 'help;' or 'h' for help. Type 'c' to clear the buffer.

MySQL> show databases;
+--------------------+
| Database      |
+--------------------+
| information_schema |
| MySQL       |
| test        |
+--------------------+
3 rows in set (0.00 sec)


MySQL> q
Bye

  確定3308端口是否在運行。

[root@ff_girl MySQL512]# netstat -an |grep 3308
tcp    0   0 0.0.0.0:3308        0.0.0.0:*          LISTEN 

  把腳本寫到啟動文件裡:

/usr/local/mysql512/bin/MySQLd_safe --defaults-file=/etc/my512.cnf

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved