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

本文涉及的产品
RDS AI 助手,专业版
RDS MySQL DuckDB 分析主实例,集群系列 4核8GB
简介:

       经过上一篇博文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,如需转载请自行联系原作者

相关实践学习
每个IT人都想学的“Web应用上云经典架构”实战
本实验从Web应用上云这个最基本的、最普遍的需求出发,帮助IT从业者们通过“阿里云Web应用上云解决方案”,了解一个企业级Web应用上云的常见架构,了解如何构建一个高可用、可扩展的企业级应用架构。
MySQL数据库入门学习
本课程通过最流行的开源数据库MySQL带你了解数据库的世界。 &nbsp; 相关的阿里云产品:云数据库RDS MySQL 版 阿里云关系型数据库RDS(Relational Database Service)是一种稳定可靠、可弹性伸缩的在线数据库服务,提供容灾、备份、恢复、迁移等方面的全套解决方案,彻底解决数据库运维的烦恼。 了解产品详情:&nbsp;https://www.aliyun.com/product/rds/mysql&nbsp;
目录
相关文章
|
4月前
|
关系型数据库 MySQL 数据库
自建数据库如何迁移至RDS MySQL实例
数据库迁移是一项复杂且耗时的工程,需考虑数据安全、完整性及业务中断影响。使用阿里云数据传输服务DTS,可快速、平滑完成迁移任务,将应用停机时间降至分钟级。您还可通过全量备份自建数据库并恢复至RDS MySQL实例,实现间接迁移上云。
|
4月前
|
存储 弹性计算 关系型数据库
如何通过控制台创建RDS MySQL实例
本文介绍了通过控制台创建RDS MySQL实例的详细步骤,包括准备工作、选择计费方式、地域、实例规格、存储空间等关键配置,并指导用户完成下单与实例查看。
|
5月前
|
存储 关系型数据库 MySQL
【赵渝强老师】MySQL数据库的多实例环境
MySQL多实例是指在一台服务器上运行多个MySQL服务,通过不同端口提供独立的数据服务。各实例共享安装程序,但使用各自的配置文件和数据文件,实现资源高效利用。本文详细介绍了如何通过“mysqld_multi”工具配置和启动多个MySQL实例,并演示了目录创建、初始化、配置文件修改及实例启动等操作步骤。
266 1
|
存储 关系型数据库 MySQL
环比、环比增长率、同比、同比增长率 ,占比,Mysql 8.0 实例(最简单的方法之一)(sample database classicmodels _No.2 )
环比、环比增长率、同比、同比增长率 ,占比,Mysql 8.0 实例(最简单的方法之一)(sample database classicmodels _No.2 )
534 1
|
SQL 前端开发 关系型数据库
全表数据核对 ,行数据核对,列数据核对,Mysql 8.0 实例(sample database classicmodels _No.3 )
全表数据核对 ,行数据核对,列数据核对,Mysql 8.0 实例(sample database classicmodels _No.3 )
339 0
全表数据核对 ,行数据核对,列数据核对,Mysql 8.0 实例(sample database classicmodels _No.3 )
|
9月前
|
SQL Oracle 关系型数据库
在MySQL Shell里 重启MySQL 8.4实例
在MySQL Shell里 重启MySQL 8.4实例
292 2
|
关系型数据库 MySQL Java
Django学习二:配置mysql,创建model实例,自动创建数据库表,对mysql数据库表已经创建好的进行直接操作和实验。
这篇文章是关于如何使用Django框架配置MySQL数据库,创建模型实例,并自动或手动创建数据库表,以及对这些表进行操作的详细教程。
612 0
Django学习二:配置mysql,创建model实例,自动创建数据库表,对mysql数据库表已经创建好的进行直接操作和实验。
|
关系型数据库 MySQL Go
go抽取mysql配置到yaml配置文件
go抽取mysql配置到yaml配置文件
|
关系型数据库 MySQL 数据库
【赵渝强老师】启动与关闭MySQL数据库实例
MySQL数据库安装完成后,可以通过命令脚本启动、查看状态、配置开机自启、查看自启列表及关闭数据库。本文提供了详细的操作步骤和示例代码,并附有视频讲解。
211 0
|
存储 关系型数据库 MySQL
mysql 8.0 的 建表 和八种 建表引擎实例
mysql 8.0 的 建表 和八种 建表引擎实例
242 0

推荐镜像

更多