mysql系列之多实例2----基于多配置文件

本文涉及的产品
云数据库 RDS MySQL,集群系列 2核4GB
推荐场景:
搭建个人博客
RDS MySQL Serverless 基础系列,0.5-2RCU 50GB
云数据库 RDS MySQL,高可用系列 2核4GB
简介:

       经过上一篇博文mysql系列之多实例1----介绍对mysql多实例进行了简单的介绍,本片博文将开始针对mysql多实例的第一种实现方案,基于多配置文件的mysql多实例进行部署实现。


1
2
3
4
5
6
7
环境:
CentOS 6.5 x86_64位 采用最小化安装,系统经过了基本优化
selinux 为关闭状态,iptables 为无限制模式
mysql版本:mysql-5.5.38
源码包存放位置: /usr/local/src
源码包编译安装位置: /usr/local/mysql
数据库存放位置: /mydata


本方案仅以同一台服务器上跑2个实例为例,演示基于多配置文件的mysql多实例

一、安装mysql程序

1、准备软件环境

1
2
[
root@nolinux ~] # yum install wget make cmake gcc gcc-c++ ncurses ncurses-devel perl -y


2、准备mysql源码包

获取源码包的方式有很多,你可以去http://dev.mysql.com/downloads/mysql/自行下载

1
2
3
4
5
6
7
8
9
[root@nolinux ~] # cd /usr/local/src/ 
[root@nolinux src] # ll 
total 21232 
-rw-r--r--. 1 root root 21739681 Jun 3 20:39 mysql-5.5.38. tar .gz
[root@nolinux src] # tar zxf mysql-5.5.38.tar.gz 
[root@nolinux src] # ll 
total 21236 
drwxr-xr-x. 31 7161 wheel 4096 May 12 00:39 mysql-5.5.38 
-rw-r--r--. 1 root root 21739681 Jun 3 20:39 mysql-5.5.38. tar .gz


3、建立mysql用户

1
[root@nolinux ~] # useradd -r -u 306 mysql


4、mysql安装

1
2
3
4
5
6
7
8
9
10
11
12
13
[root@nolinux src] # cd mysql-5.5.38 [root@nolinux mysql-5.5.38]# cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql-5.5.38 \
-DMYSQL_DATADIR= /usr/local/mysql-5 .5.38 /data  \
-DMYSQL_UNIX_ADDR= /usr/local/mysql-5 .5.38 /tmp/mysql .sock \
-DDEFAULT_CHARSET=gbk \
-DDEFAULT_COLLATION=gbk_chinese_ci \
-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
[root@nolinux mysql-5.5.38] # make
[root@nolinux mysql-5.5.38] # make install


5、为mysql安装目录制作软链接

编译安装完成之后,我们需要为mysql安装目录做一个link

1
2
[root@nolinux ~] # cd
[root@nolinux ~] # ln -s /usr/local/mysql-5.5.38 /usr/local/mysql


6、配置 mysql 环境变量

1
2
3
4
5
6
[root@nolinux ~] # echo 'export PATH=/usr/local/mysql/bin:$PATH' >> /etc/profile 
[root@nolinux ~] # tail -1 /etc/profile 
export  PATH= /usr/local/mysql/bin :$PATH 
[root@nolinux ~] # source /etc/profile 
[root@nolinux ~] # echo $PATH 
/usr/local/mysql/bin : /usr/local/sbin : /usr/local/bin : /sbin : /bin : /usr/sbin : /usr/bin : /root/bin


二、mysql 多实例部署

1、建立各个实例的对应目录

1
2
3
4
5
6
7
8
9
10
[root@nolinux ~] # mkdir /mydata/{3306,3307}/data -p
[root@nolinux ~] # chown -R mysql.mysql /mydata/
[root@nolinux ~] # tree /mydata/
/mydata/ 
  ├── 3306         # 3306端口的mysql实例目录
  │   └── data    # 3307端口的mysql数据目录
  └── 3307         # 3307端口的mysql实例目录
       └── data    # 3307端口的mysql数据目录
       
4 directories, 0 files


2、各个实例的配置文件部署

a、查看默认模板配置文件

1
2
3
4
5
[root@nolinux ~] # ls /usr/local/mysql/support-files/my-*/usr/local/mysql/support-files/my-huge.cnf 
/usr/local/mysql/support-files/my-innodb-heavy-4G .cnf 
/usr/local/mysql/support-files/my-large .cnf 
/usr/local/mysql/support-files/my-medium .cnf 
/usr/local/mysql/support-files/my-small .cnf

b、为每个实例选择配置文件

这里我们在以上模板文件中选择一个

1
2
[root@nolinux ~] # cp /usr/local/mysql/support-files/my-small.cnf /mydata/3306/my.cnf
[root@nolinux ~] # cp /usr/local/mysql/support-files/my-small.cnf /mydata/3307/my.cnf

c、修改各个实例的配置文件,修改结果如下

端口为3306的配置文件:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
[root@nolinux ~] # cat /mydata/3306/my.cnf
[client]
port            = 3306
socket          =  /mydata/3306/mysql .sock
  
[mysql]
no-auto-rehash
  
[mysqld]
user    = mysql
port    = 3306
socket  =  /mydata/3306/mysql .sock
basedir =  /usr/local/mysql
datadir =  /mydata/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 =  /mydata/3306/error .log
log-slow-queries =  /mydata/3306/slow .log
pid- file  /mydata/3306/mysql .pid
log-bin =  /mydata/3306/mysql-bin
relay-log =  /mydata/3306/relay-bin
relay-log-info- file  /mydata/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= /mydata/3306/mysql_3306 .err
pid- file = /mydata/3306/mysqld .pid


端口为3307的配置文件:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
[client]
port            = 3307
socket          =  /mydata/3307/mysql .sock
  
[mysql]
no-auto-rehash
  
[mysqld]
user    = mysql
port    = 3307
socket  =  /mydata/3307/mysql .sock
basedir =  /usr/local/mysql
datadir =  /mydata/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 =  /mydata/3307/error .log
log-slow-queries =  /mydata/3307/slow .log
pid- file  /mydata/3307/mysql .pid
#log-bin = /mydata/3307/mysql-bin
relay-log =  /mydata/3307/relay-bin
relay-log-info- file  /mydata/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= /mydata/3307/mysql_3307 .err
pid- file = /mydata/3307/mysqld .pid


3、各个实例的启动文件部署

这里我将多实例的实例启动脚本,集成到一个shell脚本里面,这样子方便启动管理!

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
[root@nolinux ~] # cat /etc/init.d/mysqld
#!/bin/bash 
# This script is used to manage open, shut down and restart the mysql server 
# Written by sunsky 
# Mail : nolinux@126.com 
# QQ : 274546888 
# Date : 2014-7-20 21:23:00 
/etc/init .d /functions 
 
if  ! [ $ # -eq 2 ];then 
echo  "Usage: $0 {start|stop|restart|reload|help} instance_port" 
exit 
fi 
 
PORT=$2 
USER=root 
PASSWD= 'sunsky' 
BIN_DIR= '/usr/local/mysql/bin' 
SOCKET_FILE= /mydata/ ${port} /mysql .sock 
DEFAULT_FILE= /mydata/ $${port} /my .cnf 
 
tac () { 
if  [ $? == 0 ]; then 
success 
else 
failure 
fi 
 
mysql_start () { 
if  [ -e  "$SOCKET_FILE"  ]; then 
echo  "Start fail,Mysql instance $PORT has already started" ;[ -e  "$SOCKET_FILE"  ];tac 
else 
echo  "$PORT start mysql instance" 
$BIN_DIR /mysqld_safe  --defaults- file =$DEFAULT_FILE ;tac 
fi 
 
 
mysql_stop() { 
if  [ ! -e $SCOKET_FILE ]; then 
echo  "Mysql instance $PORT has stopped" ;[ ! -e  "$SOCKET_FILE"  ];tac 
else 
echo  "$PORT stop mysql instance" ;$BIN_DIR /mysqladmin  -u $USER -p$PASSWD -S $SOCKET_FILE  shutdown  &> /dev/null ;tac 
fi 
 
mysql_restart () { 
mysql_stop 
sleep 
mysql_start 
 
case  "$1"  in 
start) 
mysql_start 
;; 
stop) 
mysql_stop 
;; 
restart|reload) 
mysql_stop 
mysql_start 
;; 
*) 
echo  "Usage: $0 {start|stop|restart|reload|help} instance_port" 
esac
 
[root@nolinux ~] # chmod u+x /etc/init.d/mysqld
 
[root@nolinux ~] # /etc/init.d/mysqld 
Usage:  /etc/init .d /mysqld  {start|stop|restart|reload|help} instance_port


4、初始化数据库的数据文件

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
[root@nolinux ~] # /usr/local/mysql/scripts/mysql_install_db --basedir=/usr/local/mysql --datadir=/mydata/3306/data --user=mysql 
WARNING: The host  'nolinux'  could not be looked up with resolveip. 
This probably means that your libc libraries are not 100 % compatible 
with this binary MySQL version. The MySQL daemon, mysqld, should work 
normally with the exception that host name resolving will not work. 
This means that you should use IP addresses instead of hostnames 
when specifying MySQL privileges ! 
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 
 
PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER ! 
To  do  so, start the server,  then  issue the following commands: 
 
/usr/local/mysql/bin/mysqladmin  -u root password  'new-password' 
/usr/local/mysql/bin/mysqladmin  -u root -h nolinux password  'new-password' 
 
Alternatively you can run: 
/usr/local/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: 
cd  /usr/local/mysql  /usr/local/mysql/bin/mysqld_safe 
 
You can  test  the MySQL daemon with mysql- test -run.pl 
cd  /usr/local/mysql/mysql-test  ; perl mysql- test -run.pl 
 
Please report any problems at http: //bugs .mysql.com/ 
 
[root@nolinux ~] # /usr/local/mysql/scripts/mysql_install_db --basedir=/usr/local/mysql --datadir=/mydata/3307/data --user=mysql 
WARNING: The host  'nolinux'  could not be looked up with resolveip. 
This probably means that your libc libraries are not 100 % compatible 
with this binary MySQL version. The MySQL daemon, mysqld, should work 
normally with the exception that host name resolving will not work. 
This means that you should use IP addresses instead of hostnames 
when specifying MySQL privileges ! 
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 
 
PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER ! 
To  do  so, start the server,  then  issue the following commands: 
 
/usr/local/mysql/bin/mysqladmin  -u root password  'new-password' 
/usr/local/mysql/bin/mysqladmin  -u root -h nolinux password  'new-password' 
 
Alternatively you can run: 
/usr/local/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: 
cd  /usr/local/mysql  /usr/local/mysql/bin/mysqld_safe 
 
You can  test  the MySQL daemon with mysql- test -run.pl 
cd  /usr/local/mysql/mysql-test  ; perl mysql- test -run.pl 
 
Please report any problems at http: //bugs .mysql.com/


5、多实例的启动测试

1
2
3
4
5
6
[root@nolinux ~] # /etc/init.d/mysqld start 3306 
3306 start mysql instance 
[root@nolinux ~] #                                                    [ OK ] 
[root@nolinux ~] # /etc/init.d/mysqld start 3307 
3307 start mysql instance 
[root@nolinux ~] #                                                    [ OK ]


6、更改mysql的root用户

1
2
3
4
5
6
7
8
9
10
11
[root@nolinux ~] # mysqladmin -uroot password 'sunsky' -S /mydata/3306/mysql.sock
[root@nolinux ~] # lsof -i tcp:3306 
COMMAND PID USER FD TYPE DEVICE SIZE /OFF  NODE NAME 
mysqld 22789 mysql 12u IPv4 73079 0t0 TCP *:mysql (LISTEN) 
[root@nolinux ~] # mysqladmin -uroot password 'sunsky' -S /mydata/3307/mysql.sock
[root@nolinux ~] # lsof -i tcp:3307 
COMMAND PID USER FD TYPE DEVICE SIZE /OFF  NODE NAME 
mysqld 24296 mysql 11u IPv4 74117 0t0 TCP *:opsession-prxy (LISTEN)
[root@nolinux ~] # netstat -lntup | grep 330 
tcp 0 0 0.0.0.0:3307 0.0.0.0:* LISTEN 24296 /mysqld 
tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN 22789 /mysqld


7、多实例的关闭和重启测试

1
2
3
4
5
6
7
8
9
10
11
12
13
14
[root@nolinux ~] # /etc/init.d/mysqld stop 3306 
3306 stop mysql instance 
[root@nolinux ~] #                                                    [ OK ] 
[root@nolinux ~] # /etc/init.d/mysqld restart 3306 
3306 stop mysql instance 
3306 start mysql instance                                         [FAILED] 
[root@nolinux ~] #                                                    [ OK ] 
[root@nolinux ~] # /etc/init.d/mysqld stop 3307 
3307 stop mysql instance 
[root@nolinux ~] #                                                    [ OK ] 
[root@nolinux ~] # /etc/init.d/mysqld restart 3307 
3307 stop mysql instance 
3307 start mysql instance                                         [FAILED] 
[root@nolinux ~] #                                                    [ OK ]


8、配置多实例的开机自启动

通过将mysql多实例的脚本与对应的参数放入/etc/rc.local文件,来实现mysql多实例的开机自启动

1
2
3
4
5
6
7
8
9
[root@nolinux ~] # echo '# To start the mysql instance boot since 3306' >> /etc/rc.local 
[root@nolinux ~] # echo '/etc/init.d/mysqld start 3306' >> /etc/rc.local 
[root@nolinux ~] # echo '# To start the mysql instance boot since 3307' >> /etc/rc.local 
[root@nolinux ~] # echo '/etc/init.d/mysqld start 3307' >> /etc/rc.local 
[root@nolinux ~] # tail -4 /etc/rc.local
# To start the mysql instance boot since 3306 
/etc/init .d /mysqld  start 3306 
# To start the mysql instance boot since 3307 
/etc/init .d /mysqld  start 3307


9、mysql实例部署之后的安全优化

实例刚刚部署完之后的安全优化,主要有两方面:

1、为root设置密码,由于我们在前面已经设置过了,这里就不再设置了

2、我们要查看mysql默认的用户,并将多余账户删除掉

这里仅仅以,端口为3306的mysql实例安全优化为例,做演示:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
[root@nolinux ~] # mysql -uroot -psunsky -S /mydata/3306/mysql.sock 
Welcome to the MySQL monitor. Commands end with ; or \g. 
Your MySQL connection  id  is 4 
Server version: 5.5.38-log Source distribution 
 
Copyright (c) 2000, 2014, 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> drop database  test ;
Query OK, 0 rows affected (0.02 sec)
 
mysql> show databases;
+------------------------+
| Database                     |
+------------------------+
| information_schema   |
| mysql                           |
| performance_schema |
+------------------------+
3 rows  in  set  (0.00 sec)
 
mysql>  select  user,host from mysql.user;
+------+-----------+
| user   | host          |
+------+-----------+
| root   | 127.0.0.1   |
| root   | ::1              |
|           | localhost  |
| root   | localhost  |
|           | nolinux    |
| root   | nolinux    |
+------+-----------+
6 rows  in  set  (0.00 sec)
mysql> delete from mysql.user where user= 'root'  and host= '::1' ;
Query OK, 1 row affected (0.00 sec)
mysql> delete from mysql.user where user= ''  and host= 'localhost' ;
Query OK, 1 row affected (0.00 sec)
mysql> delete from mysql.user where user= ''  and host= 'nolinux' ;
Query OK, 1 row affected (0.00 sec)
mysql> delete from mysql.user where user= 'root'  and host= 'nolinux' ;
Query OK, 1 row affected (0.00 sec)
mysql>  select  user,host from mysql.user;
+------+-----------+
| user   | host          |
+------+-----------+
| root   | 127.0.0.1   |
| root   | localhost  |
+------+-----------+
2 rows  in  set  (0.00 sec)


端口为3307的mysql实例优化,操作步骤如上!

你也可以使用如下方法一键优化!

1
2
3
4
5
6
7
8
9
mysql -uroot -psunsky -S  /mydata/3306/mysql .sock  << EOF
drop database  test ;
show databases;
delete from mysql.user where user= 'root'  and host= '::1' ;
delete from mysql.user where user= ''  and host= 'localhost' ;
delete from mysql.user where user= ''  and host= 'nolinux' ;
delete from mysql.user where user= 'root'  and host= 'nolinux' ;
select  user,host from mysql.user;
EOF


以上就是基于多配置文件方案的mysql多实例部署的整个完整操作了!希望能对大家有所帮助!下面补充一个,在现有基于多配置文件的mysql多配置文件环境下,增加实例的操作!


增加mysql实例案例

此处以增加一个mysql实例为例:

1、建立新实例对应的目录并授权

1
2
3
4
[root@nolinux ~] # mkdir -p /mydata/3308/data
[root@nolinux ~] # cp /mydata/3306/my.cnf /mydata/3308/
[root@nolinux ~] # ll -d /mydata/3308 
drwxr-xr-x. 3 mysql mysql 4096 Jun 4 00:35  /mydata/3308


2、更改my.cnf文件为3308专用

1
2
[root@nolinux ~] # cp /mydata/3306/my.cnf /mydata/3308/
[root@nolinux ~] # sed -i 's#3306#3308#g' /mydata/3308/my.cnf


3、初始化端口为3308的mysql实例的数据文件

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
[root@nolinux ~] # /usr/local/mysql/scripts/mysql_install_db --basedir=/usr/local/mysql --datadir=/mydata/3308/data --user=mysql 
WARNING: The host  'nolinux'  could not be looked up with resolveip. 
This probably means that your libc libraries are not 100 % compatible 
with this binary MySQL version. The MySQL daemon, mysqld, should work 
normally with the exception that host name resolving will not work. 
This means that you should use IP addresses instead of hostnames 
when specifying MySQL privileges ! 
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 
 
PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER ! 
To  do  so, start the server,  then  issue the following commands: 
 
/usr/local/mysql/bin/mysqladmin  -u root password  'new-password' 
/usr/local/mysql/bin/mysqladmin  -u root -h nolinux password  'new-password' 
 
Alternatively you can run: 
/usr/local/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: 
cd  /usr/local/mysql  /usr/local/mysql/bin/mysqld_safe 
 
You can  test  the MySQL daemon with mysql- test -run.pl 
cd  /usr/local/mysql/mysql-test  ; perl mysql- test -run.pl 
 
Please report any problems at http: //bugs .mysql.com/


4、启动测试

1
2
3
4
5
6
7
8
[root@nolinux ~] # /etc/init.d/mysqld start 3308 
3308 start mysql instance 
[root@nolinux ~] #                                           [ OK ] 
[root@nolinux ~] # lsof -i tcp:3308 
COMMAND PID USER FD TYPE DEVICE SIZE /OFF  NODE NAME 
mysqld 25938 mysql 12u IPv4 76028 0t0 TCP *:tns-server (LISTEN) 
[root@nolinux ~] # netstat -lntup |grep 3308 
tcp 0 0 0.0.0.0:3308 0.0.0.0:* LISTEN 25938 /mysqld


5、配置多实例的开机自启动

1
2
3
4
5
[root@nolinux ~] # echo '# To start the mysql instance boot since 3308' >> /etc/rc.local 
[root@nolinux ~] # echo '/etc/init.d/mysqld start 3308' >> /etc/rc.local 
[root@nolinux ~] # tail -2 /etc/rc.local
# To start the mysql instance boot since 3308 
/etc/init .d /mysqld  start 3308


6、安全优化

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
[root@nolinux ~] # mysqladmin -uroot password 'sunsky' -S /mydata/3308/mysql.sock
[root@nolinux ~] # mysql -uroot -psunsky -S /mydata/3308/mysql.sock << EOF 
> drop database  test
> show databases; 
> delete from mysql.user where user= 'root'  and host= '::1'
> delete from mysql.user where user= ''  and host= 'localhost'
> delete from mysql.user where user= ''  and host= 'nolinux'
> delete from mysql.user where user= 'root'  and host= 'nolinux'
select  user,host from mysql.user; 
> EOF 
Database 
information_schema 
mysql 
performance_schema 
user    host 
root    127.0.0.1 
root    localhost


OK!

上面就是在现有基于多配置文件的mysql多配置文件环境下,增加实例的操作!










本文转自 aaao 51CTO博客,原文链接:http://blog.51cto.com/nolinux/1441490,如需转载请自行联系原作者

相关实践学习
如何快速连接云数据库RDS MySQL
本场景介绍如何通过阿里云数据管理服务DMS快速连接云数据库RDS MySQL,然后进行数据表的CRUD操作。
全面了解阿里云能为你做什么
阿里云在全球各地部署高效节能的绿色数据中心,利用清洁计算为万物互联的新世界提供源源不断的能源动力,目前开服的区域包括中国(华北、华东、华南、香港)、新加坡、美国(美东、美西)、欧洲、中东、澳大利亚、日本。目前阿里云的产品涵盖弹性计算、数据库、存储与CDN、分析与搜索、云通信、网络、管理与监控、应用服务、互联网中间件、移动服务、视频服务等。通过本课程,来了解阿里云能够为你的业务带来哪些帮助 &nbsp; &nbsp; 相关的阿里云产品:云服务器ECS 云服务器 ECS(Elastic Compute Service)是一种弹性可伸缩的计算服务,助您降低 IT 成本,提升运维效率,使您更专注于核心业务创新。产品详情: https://www.aliyun.com/product/ecs
目录
打赏
0
0
0
0
235
分享
相关文章
环比、环比增长率、同比、同比增长率 ,占比,Mysql 8.0 实例(最简单的方法之一)(sample database classicmodels _No.2 )
环比、环比增长率、同比、同比增长率 ,占比,Mysql 8.0 实例(最简单的方法之一)(sample database classicmodels _No.2 )
282 1
全表数据核对 ,行数据核对,列数据核对,Mysql 8.0 实例(sample database classicmodels _No.3 )
全表数据核对 ,行数据核对,列数据核对,Mysql 8.0 实例(sample database classicmodels _No.3 )
128 0
全表数据核对 ,行数据核对,列数据核对,Mysql 8.0 实例(sample database classicmodels _No.3 )
Django学习二:配置mysql,创建model实例,自动创建数据库表,对mysql数据库表已经创建好的进行直接操作和实验。
这篇文章是关于如何使用Django框架配置MySQL数据库,创建模型实例,并自动或手动创建数据库表,以及对这些表进行操作的详细教程。
187 0
Django学习二:配置mysql,创建model实例,自动创建数据库表,对mysql数据库表已经创建好的进行直接操作和实验。
【赵渝强老师】启动与关闭MySQL数据库实例
MySQL数据库安装完成后,可以通过命令脚本启动、查看状态、配置开机自启、查看自启列表及关闭数据库。本文提供了详细的操作步骤和示例代码,并附有视频讲解。
mysql 8.0 的 建表 和八种 建表引擎实例
mysql 8.0 的 建表 和八种 建表引擎实例
67 0
Key_Value 形式 存储_5级省市城乡划分代码 (mysql 8.0 实例)
本文介绍了如何使用MySQL8.0数据库中的Key_Value形式存储全国统计用区划代码和城乡划分代码(5级),包括导入数据、通过数学函数提取省市区信息,以及查询5级行政区划的详细数据。
68 0
复购率 mysql 实例(sample database classicmodels _No.1 )
复购率 mysql 实例(sample database classicmodels _No.1 )
85 0
docker启动mysql多实例连接报错Can’t connect to local MySQL server through socket ‘/var/run/mysqld/mysqld.sock’
docker启动mysql多实例连接报错Can’t connect to local MySQL server through socket ‘/var/run/mysqld/mysqld.sock’
351 0
Prometheus结合Consul采集多个MySQL实例的监控指标
将 Prometheus 与 Consul 结合使用,实现对多个 MySQL 实例的自动发现与监控,不仅提高了监控的效率和准确性,也为管理动态扩缩容的数据库环境提供了强大的支持。通过细致配置每一部分,业务可以获得关键的性能指标和运行健康状况的即时反馈,进而优化资源配置,提高系统的稳定性和可用性。
239 3
AI助理

你好,我是AI助理

可以解答问题、推荐解决方案等