1.安裝MySQL需要的依賴的包和編譯軟體 (1)安裝MySQL需要的依賴包 安裝MySQL之前,最好先安裝MySQL需要的依賴包,不然後面會出現報錯,還得回來安裝MySQL的依賴包。 [root@Mysql-server tools]# yum install -y ncurses-devel l ...
1.安裝MySQL需要的依賴的包和編譯軟體 (1)安裝MySQL需要的依賴包 安裝MySQL之前,最好先安裝MySQL需要的依賴包,不然後面會出現報錯,還得回來安裝MySQL的依賴包。
[root@Mysql-server tools]# yum install -y ncurses-devel libaio-devel
[root@Mysql-server tools]# rpm -qa ncurses-devel libaio-devel
ncurses-devel-5.7-4.20090207.el6.x86_64
libaio-devel-0.3.107-10.el6.x86_64
[root@Mysql-server tools]# tar xf cmake-2.8.8.tar.gz
[root@Mysql-server tools]# cd cmake-2.8.8
[root@Mysql-server cmake-2.8.8]#./configure
[root@mysql cmake-2.8.8]# gmake
[root@mysql cmake-2.8.8]# gmake install
[root@mysql tools]# useradd mysql -s /sbin/nologin -M
[root@mysql tools]# id mysql uid=501(mysql) gid=501(mysql) 組=501(mysql) [root@mysql tools]#
tar zxf mysql-5.5.32.tar.gz cd mysql-5.5.32
cmake .-DCMAKE_INSTALL_PREFIX=/application/mysql-5.5.32 \
-DMYSQL_DATADIR=/application/mysql-5.5.32/data \
-DMYSQL_UNIX_ADDR=/application/mysql-5.5.32/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 \
-DWITHOUT_PARTITION_STORAGE_ENGINE=1 \
-DWITH_FAST_MUTEXES=1 \
-DWITH_ZLIB=bundled \
-DENABLED_LOCAL_INFILE=1 \
-DWITH_READLINE=1 \
-DWITH_EMBEDDED_SERVER=1 \
-DWITH_DEBUG=0
#-- Build files have been written to: /home/oldboy/tools/mysql-5.5.32
提示,編譯時可配置的選項很多,具體可參考結尾附錄或官方文檔:
make
#[100%] Built target my_safe_process
make install
ln -s /application/mysql-5.5.32//application/mysql
如果上述操作未出現錯誤,則MySQL5.5.32軟體cmake方式的安裝就算成功了。
[root@mysql mysql-5.5.32]# rm CMakeCache.txt ###刪除這個文件,重新cmake
[root@mysql mysql-5.5.32]# mkdir -p /data/{3306,3307}/data
[root@mysql mysql-5.5.32]# tree /data/
/data/
├──3306
│??└── data ##實例3306的數據文件
├──3307
│??└── data ##實例3307的數據文件
└── test
[root@mysql /]# unzip data.zip ##上傳到根下,加壓會替換上面創建的/data目錄
Archive: data.zip
inflating: data/3306/my.cnf
inflating: data/3306/mysql
inflating: data/3307/my.cnf
inflating: data/3307/mysql
[root@mysql /]# tree /data
data/ data.zip
[root@mysql /]# tree data
data/ data.zip
[root@mysql /]# tree data/
data/
├──3306
│??├── data
│??├── my.cnf ##實例的配置文件
│??└── mysql ##實例的啟動文件
├──3307
│??├── data
│??├── my.cnf ##實例的配置文件
│??└── mysql ##實例的啟動文件
└── test
[root@mysql /]# cat /data/3306/my.cnf
[client]
port =3306
socket =/data/3306/mysql.sock
[mysql]
no-auto-rehash
[mysqld]
user = mysql
port =3306
socket =/data/3306/mysql.sock
basedir =/application/mysql
datadir =/data/3306/data
open_files_limit =1024
back_log =600
max_connections =800
max_connect_errors =3000
table_cache =614
external-locking = FALSE
max_allowed_packet =8M
sort_buffer_size =1M
join_buffer_size =1M
thread_cache_size =100
thread_concurrency =2
query_cache_size =2M
query_cache_limit =1M
query_cache_min_res_unit =2k
#default_table_type = InnoDB
thread_stack =192K
#transaction_isolation = READ-COMMITTED
tmp_table_size =2M
max_heap_table_size =2M
long_query_time =1
#log_long_format
#log-error = /data/3306/error.log
#log-slow-queries = /data/3306/slow.log
pid-file =/data/3306/mysql.pid
log-bin =/data/3306/mysql-bin
relay-log =/data/3306/relay-bin
relay-log-info-file =/data/3306/relay-log.info
binlog_cache_size =1M
max_binlog_cache_size =1M
max_binlog_size =2M
expire_logs_days =7
key_buffer_size =16M
read_buffer_size =1M
read_rnd_buffer_size =1M
bulk_insert_buffer_size =1M
#myisam_sort_buffer_size = 1M
#myisam_max_sort_file_size = 10G
#myisam_max_extra_sort_file_size = 10G
#myisam_repair_threads = 1
#myisam_recover
lower_case_table_names =1
skip-name-resolve
slave-skip-errors =1032,1062
replicate-ignore-db=mysql
server-id =1
innodb_additional_mem_pool_size =4M
innodb_buffer_pool_size =32M
innodb_data_file_path = ibdata1:128M:autoextend
innodb_file_io_threads =4
innodb_thread_concurrency =8
innodb_flush_log_at_trx_commit =2
innodb_log_buffer_size =2M
innodb_log_file_size =4M
innodb_log_files_in_group =3
innodb_max_dirty_pages_pct =90
innodb_lock_wait_timeout =120
innodb_file_per_table =0
[mysqldump]
quick
max_allowed_packet =2M
[mysqld_safe]
log-error=/data/3306/mysql_oldboy3306.err
pid-file=/data/3306/mysqld.pid
[root@mysql /]# cat /data/3307/my.cnf
[client]
port =3307
socket =/data/3307/mysql.sock
[mysql]
no-auto-rehash
[mysqld]
user = mysql
port =3307
socket =/data/3307/mysql.sock
basedir =/application/mysql
datadir =/data/3307/data
open_files_limit =1024
back_log =600
max_connections =800
max_connect_errors =3000
table_cache =614
external-locking = FALSE
max_allowed_packet =8M
sort_buffer_size =1M
join_buffer_size =1M
thread_cache_size =100
thread_concurrency =2
query_cache_size =2M
query_cache_limit =1M
query_cache_min_res_unit =2k
#default_table_type = InnoDB
thread_stack =192K
#transaction_isolation = READ-COMMITTED
tmp_table_size =2M
max_heap_table_size =2M
#long_query_time = 1
#log_long_format
#log-error = /data/3307/error.log
#log-slow-queries = /data/3307/slow.log
pid-file =/data/3307/mysql.pid
#log-bin = /data/3307/mysql-bin
relay-log =/data/3307/relay-bin
relay-log-info-file =/data/3307/relay-log.info
binlog_cache_size =1M
max_binlog_cache_size =1M
max_binlog_size =2M
expire_logs_days =7
key_buffer_size =16M
read_buffer_size =1M
read_rnd_buffer_size =1M
bulk_insert_buffer_size =1M
#myisam_sort_buffer_size = 1M
#myisam_max_sort_file_size = 10G
#myisam_max_extra_sort_file_size = 10G
#myisam_repair_threads = 1
#myisam_recover
lower_case_table_names =1
skip-name-resolve
slave-skip-errors =1032,1062
replicate-ignore-db=mysql
server-id =3
innodb_additional_mem_pool_size =4M
innodb_buffer_pool_size =32M
innodb_data_file_path = ibdata1:128M:autoextend
innodb_file_io_threads =4
innodb_thread_concurrency =8
innodb_flush_log_at_trx_commit =2
innodb_log_buffer_size =2M
innodb_log_file_size =4M
innodb_log_files_in_group =3
innodb_max_dirty_pages_pct =90
innodb_lock_wait_timeout =120
innodb_file_per_table =0
[mysqldump]
quick
max_allowed_packet =2M
[mysqld_safe]
log-error=/data/3307/mysql_oldboy3307.err
pid-file=/data/3307/mysqld.pid
本文多實例啟動文件的停止mysql服務實質命令:
mysqladmin -u root -p123456 -S /data/3306/mysql.sock shutdown mysqladmin -u root -p123456 -S /data/3307/mysql.sock shutdown 2.4 修改數據文件/data 許可權
[root@mysql /]# chown -R mysql.mysql /data
[root@mysql /]# find /data -type f -name "my.cnf"|xargs ls -l ##將my.cnf文件許可權設置成644
-rw-r--r--.1 mysql mysql 189910月292013/data/3306/my.cnf
-rw-r--r--.1 mysql mysql 190110月292013/data/3307/my.cnf
[root@mysql /]# find /data -type f -name "mysql"|xargs ls -l ##由於mysql腳本中保存了登錄資料庫的密碼,需要將文件許可權設置成700,只允許root,mysql訪問
-rw-r--r--.1 mysql mysql 13077月152013/data/3306/mysql
-rw-r--r--.1 mysql mysql 13077月212013/data/3307/mysql
[root@mysql /]# find /data -type f -name "mysql"|xargs chmod 700
[root@mysql /]# find /data -type f -name "mysql"|xargs ls -l
-rwx------.1 mysql mysql 13077月152013/data/3306/mysql
-rwx------.1 mysql mysql 13077月212013/data/3307/mysql
[root@mysql /]# ll /application/mysql/bin/mysql
-rwxr-xr-x.1 root root 53453564月816:05/application/mysql/bin/mysql
[root@mysql /]# tail -1/etc/profile
export PATH=/application/mysql/bin:$PATH ##添加如下行
[root@mysql /]# source /etc/profile ##讓其生效
[root@mysql /]# echo $PATH
/application/mysql/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin
cd /application/mysql/scripts/##註意和MySQL 5.1的路徑不同,MySQL 5.1 不在mysql/bin下
./mysql_install_db --basedir=/application/mysql --datadir=/data/3306/data/--user=mysql
./mysql_install_db --basedir=/application/mysql --datadir=/data/3307/data/--user=mysql
3. 最後啟動mysql
[root@mysql scripts]#/data/3306/mysql start
StartingMySQL...
[root@mysql scripts]#/data/3307/mysql start
StartingMySQL...
查看是否啟動成功
[root@mysql scripts]# netstat -lntup|grep mysql
tcp 000.0.0.0:33060.0.0.0:* LISTEN 4614/mysqld
tcp 000.0.0.0:33070.0.0.0:* LISTEN 5412/mysqld
[root@mysql scripts]# mysqladmin -uroot password 123456 -S /data/3306/mysql.sock
[root@mysql scripts]# mysqladmin -uroot password 123456 -S /data/3307/mysql.sock
[root@mysql scripts]# sed -i '13 s#oldboy#123456#g'/data/3306/mysql
[root@mysql scripts]# sed -n '13p'/data/3306/mysql
mysql_pwd="123456"
[root@mysql scripts]# sed -i '13 s#oldboy#123456#g' /data/3307/mysql [root@mysql scripts]# sed -n '13p' /data/3307/mysql mysql_pwd="123456" [root@mysql scripts]#
[root@mysql scripts]#/data/3306/mysql stop
StopingMySQL...