- 一、mysql单实例安装
- 1.系统环境
- 2.安装包
- 3.安装所需的包
- 4.安装cmake
- 5.安装mysql
- 6.初始化环境配置
- 6.1配置文件模板
- 6.2环境变量
- 6.3目录授权
- 6.4初始化数据库
- 6.5启动脚本
- 6.6启动mysql
- 6.7设置Linux系统字符集
- 6.8设置密码登录
- 7.简单优化
- 二、mysql多实例安装
- 1.停止mysql
- 2.创建mysql多实例的目录
- 3.创建3306与3307实例的配置文件
- 3.1 3306实例配置
- 3.2 3307实例配置
- 4.配置多实例根目录权限
- 5.初始化数据库
- 6.启动两个实例
- 7.设置密码
- 8.关闭实例
- 9.编写脚本管理实例启动与关闭
- 9.1 3306实例管理脚本
- 9.2 3307实例管理脚本
- 10.授权脚本并测试
一、mysql单实例安装
1.系统环境
[root@mysql ~]
CentOS release 6.5 (Final)
[root@mysql ~]
2.6.32-431.el6.x86_64
2.安装包
[root@mysql ~]# ll *.gz
-rw-r--r--. 1 root root 5691656 Sep 14 23:01 cmake-2.8.8.tar.gz
-rw-r--r--. 1 root root 24596474 Sep 14 22:48 mysql-5.5.32.tar.gz
3.安装所需的包
[root@mysql ~]
4.安装cmake
[root@mysql ~]
[root@mysql ~]
[root@mysql cmake-2.8.8]
[root@mysql cmake-2.8.8]
5.安装mysql
[root@mysql ~]
[root@mysql ~]
[root@mysql mysql-5.5.32]
[root@mysql mysql-5.5.32]
(-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \没有指定字符集)
[root@mysql mysql-5.5.32]
[root@mysql mysql-5.5.32]
6.初始化环境配置
6.1配置文件模板
[root@mysql mysql-5.5.32]# cp support-files/my-small.cnf /etc/my.cnf
cp: overwrite `/etc/my.cnf'? yes
6.2环境变量
[root@mysql mysql-5.5.32]
[root@mysql scripts]
6.3目录授权
[root@mysql mysql-5.5.32]
6.4初始化数据库
[root@mysql mysql-5.5.32]
[root@mysql scripts]
6.5启动脚本
[root@mysql scripts]
[root@mysql scripts]
6.6启动mysql
[root@mysql scripts]
Starting MySQL.. SUCCESS!
[root@mysql scripts]
6.7设置Linux系统字符集
[root@mysql ~]
[root@mysql ~]
LANG=zh_CN.UTF-8
[root@mysql ~]
6.8设置密码登录
[root@mysql scripts]
[root@mysql scripts]
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.5.32 Source distribution
Copyright (c) 2000, 2013, 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>
7.简单优化
7.1清楚非管理员用户
| root | 127.0.0.1 |
| root | ::1 |
| | localhost |
| root | localhost |
| | mysql |
mysql> mysql> delete from mysql.user wher"";
Query OK, 2 rows affected (0.00 sec)
mysql> delete from mysql.user where host="::1";
Query OK, 1 row affected (0.00 sec)
mysql> delete from mysql.user where host="mysql";
Query OK, 1 row affected (0.00 sec)
| root | 127.0.0.1 |
2 rows in set (0.00 sec)
7.2删除test库
mysql> drop database test;
Query OK, 0 rows affected (0.01 sec)
二、mysql多实例安装
1.停止mysql
[root@mysql ~]
Shutting down MySQL. SUCCESS!
[root@mysql ~]
root 23903 1179 0 10:10 pts/0 00:00:00 grep mysqld
2.创建mysql多实例的目录
[root@mysql ~]# mkdir /data/{3306,3307}/data -p
[root@mysql ~]# tree /data/
/data/ #多实例的根目录
├── 3306 #3306实例的目录
│ └── data#3306实例的数据文件目录
└── 3307
└── data
4 directories, 0 files
3.创建3306与3307实例的配置文件
3.1 3306实例配置
[root@mysql ~]
[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
thread_stack = 192K
tmp_table_size = 2M
max_heap_table_size = 2M
long_query_time = 1
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
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_qb3306.err
pid-file=/data/3306/mysqld.pid
3.2 3307实例配置
[root@mysql ~]
[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
thread_stack = 192K
tmp_table_size = 2M
max_heap_table_size = 2M
long_query_time = 1
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
lower_case_table_names = 1
skip-name-resolve
slave-skip-errors = 1032,1062
replicate-ignore-db=mysql
server-id = 2
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_qb3307.err
pid-file=/data/3307/mysqld.pid
4.配置多实例根目录权限
[root@mysql ~]
5.初始化数据库
[ ] -- -- --
[ ] -- -- --
6.启动两个实例
[root@mysql ~]
[1] 24298
[root@mysql ~]
[2] 25048
[root@mysql ~]
tcp 0 0 0.0.0.0:3307 0.0.0.0:* LISTEN 25772/mysqld
tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN 25022/mysqld
7.设置密码
[root@mysql ~]
[root@mysql ~]
[root@mysql ~]
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.5.32-log Source distribution
Copyright (c) 2000, 2013, 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> quit
Bye
[root@mysql ~]
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.5.32-log Source distribution
Copyright (c) 2000, 2013, 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> quit
Bye
8.关闭实例
[root@mysql ~]
[1]- Done mysqld_safe --defaults-file=/data/3306/my.conf > /dev/null 2>&1
[root@mysql ~]
[2]+ Done mysqld_safe --defaults-file=/data/3307/my.conf > /dev/null 2>&1
[root@mysql ~]
[root@mysql ~]
0
9.编写脚本管理实例启动与关闭
9.1 3306实例管理脚本
[root@mysql ~]
#!/bin/bash
. /etc/init.d/functions
Port=3306
user=root
password=000000
Path=/application/mysql/bin/
File=/data/${Port}/my.conf
Sock=/data/${Port}/mysql.sock
mysql_start(){
${Path}mysqld_safe --defaults-file=${File} > /dev/null 2>&1 &
sleep 3
num=`netstat -lntup|grep ${Port}|wc -l`
if [ "$num" -ne 0 ];then
action "mysql $Port start......" /bin/true
else
action "mysql $Port start......" /bin/false
fi
}
mysql_stop(){
${Path}mysqladmin -u${user} -p${password} -S $Sock shutdown
num=`netstat -lntup|grep ${Port}|wc -l`
if [ "$num" -eq 0 ];then
action "mysql $Port stop......" /bin/true
else
action "mysql $Port stop......" /bin/false
fi
}
mysql_restart(){
mysql_stop
mysql_start
}
mysql_login(){
${Path}mysql -u${user} -p${password} -S $Sock
}
case $1 in
start)
mysql_start
;;
stop)
mysql_stop
;;
restart)
mysql_restart
;;
login)
mysql_login
;;
*)
echo "Usage: $0 {start|stop|restart}"
esac
9.2 3307实例管理脚本
复制3306的脚本,修改端口即可
vim /data/3307/mysqld
Port=3307
10.授权脚本并测试
[root@mysql ~]
[root@mysql ~]
mysql 3306 start...... [确定]
[root@mysql ~]
mysql 3307 start...... [确定]
[root@mysql ~]
tcp 0 0 0.0.0.0:3307 0.0.0.0:* LISTEN 34332/mysqld
tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN 33583/mysqld