当前位置: 首页 > 编程日记 > 正文

MySQL 5.5.35 单机多实例配置详解

一、前言

二、概述

三、环境准备

四、安装MySQL 5.5.35

五、新建支持多实例的配置文件(我这里配置的是四个实例)

六、初始化多实例数据库

七、提供管理脚本 mysqld_multi.server

八、整体备份方便后续迁移

九、管理MySQL多实例

十、登录MySQL多实例

十一、其它管理配置

十二、总结

注,测试环境 CentOS 6.4 x86_64,软件版本 MySQL 5.5.35,软件下载地址:http://dev.mysql.com/downloads/mysql/5.1.html#downloads。

1.应用场景

  • 采用了数据伪分布式架构的原因,而项目启动初期又不一定有那多的用户量,为此先一组物理数据库服务器,但部署多个实例,方便后续迁移;

  • 为规避mysql对SMP架构不支持的缺陷,使用多实例绑定处理器的办法,把不同的数据库分配到不同的实例上提供数据服务;

  • 一台物理数据库服务器支撑多个数据库的数据服务,为提高mysql复制的从机的恢复效率,采用多实例部署;

  • 已经为双主复制的mysql数据库服务器架构,想部分重要业务的数据多一份异地机房的热备份,而mysql复制暂不支持多主的复制模式,且不给用户提供服务,为有效控制成本,会考虑异地机房部署一台性能超好的物理服务器,甚至外加磁盘柜的方式,为此也会部署多实例;

  • 传统游戏行业的MMO/MMORPG,以及Web Game,每一个服都对应一个数据库,而可能要做很多数据查询和数据订正的工作,为减少维护而出错的概率,也可能采用多实例部署的方式,按区的概念分配数据库;

上面的应用场景介绍主要参考这篇文章:http://www.zhdba.com/mysqlops/2011/07/30/multi-mysqld/,我们这里应用主要是基于前面三种场景。下面我们来说一下要注意的问题……

2.背景/需求、注意事项

(1).背景与需求

  • 将所有的安装文件、配置文件、数据目录全部放存/data/mysql目录中,便于今后实现快速迁移、整体备份和快速复制;

  • 在一台服务器上运行四个MySQL实例,分别绑定在3306、3307、3308、3309端口上;

  • 四个实例都开启binlog日志,数据目录分别存放在/data/mysql/data、/data/mysql/data2、/data/mysql/data3、/data/mysql/data4

  • 四个实例均采用InnoDB作为默认的存储引擎,字符编码采用UTF-8;

  • 四个实例均采用相同的性能优化配置参数;

(2).注意事项

  • 在编译安装时,将数据库的配置文件my.cnf以及data目录等均指向到/data/mysql目录中;

  • 通过mysqld_multi的方式来管理四个不同的实例,采用相同的配置文件共享性能优化配置参数;

  • 在同一个配置文件中,利用[mysqld1]、[mysqld2]、[mysqld3]、[mysqld4]标签实现不同实例的差异化配置;

三、环境准备

1.安装yum源

1
2
[root@node1 src]# wget http://mirrors.hustunique.com/epel/6/x86_64/epel-release-6-8.noarch.rpm
[root@node1 src]# rpm -ivh epel-release-6-8.noarch.rpm

2.同步时间

1
2
3
[root@node1 src]# yum install -y ntp
[root@node1 src]# ntpdate 202.120.2.101
[root@node1 src]# hwclock –w

3.安装mysql5.5依赖包

1
[root@node1 ~]# yum install -y autoconf* automake* zlib* libxml* ncurses-devel* libgcrypt* libtool* openssl*

4.安装cmake

1
[root@node1 ~]# yum install -y cmake

四、安装MySQL 5.5.35

1.创建安装目录与数据存放目录

1
2
[root@node1 ~]# mkdir /data/mysql
[root@node1 ~]# mkdir /data/mysql/data

2.创建mysql用户与组

1
2
3
[root@node1 ~]# useradd mysql
[root@node1 ~]# id mysql 
uid=500(mysql) gid=500(mysql) 组=500(mysql)

3.授权安装目录与数据目录

1
2
[root@node1 ~]# chown -R mysql.mysql /data/mysql/ 
[root@node1 ~]# chown -R mysql.mysql /data/mysql/data

4.安装mysql

1
2
3
4
5
[root@node1 ~]# cd src/ 
[root@node1 src]# tar xf mysql-5.5.35.tar.gz   
[root@node1 src]# cd mysql-5.5.35
[root@node1 mysql-5.5.35]# cmake -DCMAKE_INSTALL_PREFIX=/data/mysql -DSYSCONFDIR=/data/mysql/etc -DMYSQL_DATADIR=/data/mysql/data -DMYSQL_TCP_PORT=3306 -DMYSQL_UNIX_ADDR=/tmp/mysqld.sock -DMYSQL_USER=mysql -DEXTRA_CHARSETS=all -DWITH_READLINE=1 -DWITH_SSL=system -DWITH_EMBEDDED_SERVER=1 -DENABLED_LOCAL_INFILE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1
[root@node1 mysql-5.5.35]# make && make install

好了,到这里我们的mysql就安装完成了,下面我们为mysql提供多实例配置文件。

五、新建支持多实例的配置文件(我这里配置的是四个实例)

1.删除默认的数据目录

1
2
[root@node1 ~]# cd /data/mysql/ 
[root@node1 mysql]# rm -rf data

2.创建多实例配置需要的目录

1
2
[root@node1 mysql]# mkdir etc tmp run log binlogs data data2 data3 data4
[root@node1 mysql]# chown -R mysql.mysql tmp run log binlogs data data2 data3 data4

3.提供配置文件

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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
[root@node1 ~]# cd src/ 
[root@node1 src]# cd mysql-5.5.35
[root@node1 mysql-5.5.35]# cp support-files/my-small.cnf /data/mysql/etc/my.cnf
[root@node1 ~]# cd /data/mysql/etc/ 
[root@node1 etc]# vim my.cnf  
# This server may run 4+ separate instances. So we use mysqld_multi to manage their services.
[client] 
default-character-set = utf8
[mysqld_multi] 
mysqld = /data/mysql/bin/mysqld_safe
mysqladmin = /data/mysql/bin/mysqladmin
log = /data/mysql/log/mysqld_multi.log  
user = root   
#password =
                                                                                                    
# This is the general purpose database. 
# The locations are default.  
# They are left in [mysqld] in case the server is started normally instead of by mysqld_multi.
[mysqld1] 
socket = /data/mysql/run/mysqld.sock  
port = 3306  
pid-file /data/mysql/run/mysqld.pid  
datadir = /data/mysql/data
lc-messages-dir /data/mysql/share/english
                                                                                                     
# These support master - master replication  
#auto-increment-increment = 4  
#auto-increment-offset = 1  # Since it is master 1  
log-bin = /data/mysql/binlogs/bin-log-mysqld1
log-bin-index = /data/mysql/binlogs/bin-log-mysqld1.index  
#binlog-do-db = # Leave this blank if you want to control it on slave  
max_binlog_size = 1024M  
                                                                                                     
# This is exlusively for mysqld2  
# It is on 3307 with data directory /data/mysqld/data2
[mysqld2] 
socket = /data/mysql/run/mysqld.sock2  
port = 3307  
pid-file /data/mysql/run/mysqld.pid2  
datadir = /data/mysql/data2
lc-messages-dir /data/mysql/share/english
                                                                                                     
# Disable DNS lookups  
#skip-name-resolve  
                                                                                                     
# These support master - slave replication  
log-bin = /data/mysql/binlogs/bin-log-mysqld2
log-bin-index = /data/mysql/binlogs/bin-log-mysqld2.index  
#binlog-do-db =  # Leave this blank if you want to control it on slave  
max_binlog_size = 1024M
 # Relay log settings
#relay-log = /data/mysql/log/relay-log-mysqld2
#relay-log-index = /data/mysql/log/relay-log-mysqld2.index
#relay-log-space-limit = 4G
                                                                                                     
# Slow query log settings
#log-slow-queries = /data/mysql/log/slow-log-mysqld2
#long_query_time = 2
#log-queries-not-using-indexes
                                                                                                     
# This is exlusively for mysqld3 
# It is on 3308 with data directory /data/mysqld/data3
[mysqld3] 
socket = /data/mysql/run/mysqld.sock3  
port = 3308  
pid-file /data/mysql/run/mysqld.pid3  
datadir = /data/mysql/data3
lc-messages-dir /data/mysql/share/english
#Disable DNS lookups 
#skip-name-resolve
# These support master - slave replication 
log-bin = /data/mysql/binlogs/bin-log-mysqld3
log-bin-index = /data/mysql/binlogs/bin-log-mysqld3.index  
#binlog-do-db =  # Leave this blank if you want to control it on slave  
 max_binlog_size = 1024M
 # This is exlusively for mysqld4
# It is on 3309 with data directory /data/mysqld/data4
[mysqld4] 
socket = /data/mysql/run/mysqld.sock4  
port = 3309  
pid-file /data/mysql/run/mysqld.pid4  
datadir = /data/mysql/data4
lc-messages-dir /data/mysql/share/english
# Disable DNS lookups 
#skip-name-resolve
# These support master - slave replication 
log-bin = /data/mysql/binlogs/bin-log-mysqld4
log-bin-index = /data/mysql/binlogs/bin-log-mysqld4.index  
#binlog-do-db =  # Leave this blank if you want to control it on slave  
max_binlog_size = 1024M
 # The rest of the my.cnf is shared
# Here follows entries for some specific programs
# The MySQL server
[mysqld] 
basedir = /data/mysql
tmpdir = /data/mysql/tmp
socket = /data/mysql/run/mysqld.sock  
port = 3306  
pid-file /data/mysql/run/mysqld.pid  
datadir = /data/mysql/data
lc-messages-dir /data/mysql/share/english
                                                                                                     
skip-external-locking  
key_buffer_size = 16K  
max_allowed_packet = 1M  
table_open_cache = 4  
sort_buffer_size = 64K  
read_buffer_size = 256K  
read_rnd_buffer_size = 256K  
net_buffer_length = 2K  
thread_stack = 128K  
                                                                                                     
# Increase the max connections  
max_connections = 2  
                                                                                                     
# The expiration time for logs, including binlogs  
expire_logs_days = 14  
                                                                                                     
# Set the character as utf8  
character-set-server = utf8  
collation-server = utf8_unicode_ci  
                                                                                                     
# This is usually only needed when setting up chained replication  
#log-slave-updates  
                                                                                                     
# Enable this to make replication more resilient against server crashes and restarts  
# but can cause higher I/O on the server  
#sync_binlog = 1  
                                                                                                     
# The server id, should be unique in same network  
server-id = 1  
                                                                                                     
# Set this to force MySQL to use a particular engine/table-type for new tables  
# This setting can still be overridden by specifying the engine explicitly  
# in the CREATE TABLE statement  
default-storage-engine = INNODB  
                                                                                                     
# Enable Per Table Data for InnoDB to shrink ibdata1  
innodb_file_per_table = 1  
                                                                                                     
# Uncomment the following if you are using InnoDB tables  
#innodb_data_home_dir = /data/mysql/data  
#innodb_data_file_path = ibdata1:10M:autoextend  
#innodb_log_group_home_dir = /data/mysql/data  
# You can set .._buffer_pool_size up to 50 - 80 % of RAM  
# but beware of setting memory usage too high  
innodb_buffer_pool_size = 16M  
innodb_additional_mem_pool_size = 2M  
# Set .._log_file_size to 25 % of buffer pool size  
innodb_log_file_size = 5M  
innodb_log_buffer_size = 8M  
innodb_flush_log_at_trx_commit = 1  
innodb_lock_wait_timeout = 50  
                                                                                                     
[mysqldump]  
quick  
max_allowed_packet = 16M  
                                                                                                     
[mysql]  
no-auto-rehash  
                                                                                                     
[myisamchk]  
key_buffer_size = 8M  
sort_buffer_size = 8M  
                                                                                                     
[mysqlhotcopy]  
interactive-timeout  
                                                                                                     
[mysql.server]  
user = mysql  
                                                                                                     
[mysqld_safe]  
log-error = /data/mysql/log/mysqld.log  
pid-file /data/mysql/run/mysqld.pid  
open-files-limit = 8192

注,MySQL自带了几个不同的配置文件,放置在/data/mysql/support-files目录下,分别是my-huge.cnf,my-innodb-heavy-4G.cnf,my-large.cnf,my-medium.cnf,my-small.cnf,通过名称我们可以很直观的了解到他们是针对不同的服务器配置的,本文的配置文件是来自于my-small.cnf的,因为我是在虚拟机上进行的设置;在生产环境中,我们可以通过参考my-huge.cnf或my-innodb-heavy-4G.cnf中的部分参数配置,来对服务器进行优化;

4.修改my.cnf读写权限

1
2
[root@node1 etc]# chown -R root.root /data/mysql/etc
[root@node1 etc]# chmod 600 /data/mysql/etc/my.cnf

好了,到这里我们的配置文件就设置完成了,下面我们来初始化一下数据库。

六、初始化多实例数据库

1.切换到mysql的安装目录

1
[root@node1 ~]# cd /data/mysql/

2.初始化实例[mysqld1]

1
[root@node1 mysql]# scripts/mysql_install_db --basedir=/data/mysql --datadir=/data/mysql/data --user=mysql

3.初始化实例[mysqld2]

1
[root@node1 mysql]# scripts/mysql_install_db --basedir=/data/mysql --datadir=/data/mysql/data2 --user=mysql

4.初始化实例[mysqld3]

1
[root@node1 mysql]# scripts/mysql_install_db --basedir=/data/mysql --datadir=/data/mysql/data3 --user=mysql

5.初始化实例[mysqld4]

1
[root@node1 mysql]# scripts/mysql_install_db --basedir=/data/mysql --datadir=/data/mysql/data4 --user=mysql

好了,到这里我们初始化工作就完成了,下面我们来提供一下多实例的管理脚本。

七、提供管理脚本 mysqld_multi.server

1.创建管理脚本目录

1
[root@node1 mysql]# mkdir /data/mysql/init.d

2.提供管理脚本

1
[root@node1 mysql]# cp support-files/mysqld_multi.server init.d/

3.简单修改一下脚本

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
[root@node1 mysql]# cd init.d/ 
[root@node1 init.d]# vim mysqld_multi.server   
#!/bin/sh  
#  
# A simple startup script for mysqld_multi by Tim Smith and Jani Tolonen.  
# This script assumes that my.cnf file exists either in /etc/my.cnf or  
# /root/.my.cnf and has groups [mysqld_multi] and [mysqldN]. See the  
# mysqld_multi documentation for detailed instructions.  
#  
# This script can be used as /etc/init.d/mysql.server  
#  
# Comments to support chkconfig on RedHat Linux  
# chkconfig: 2345 64 36  
# description: A very fast and reliable SQL database engine.  
#  
# Version 1.0  
#
basedir=/data/mysql
bindir=/data/mysql/bin
conf=/data/mysql/etc/my.cnf 
export PATH=$PATH:$bindir
if test -x $bindir/mysqld_multi
then
  mysqld_multi="$bindir/mysqld_multi";  
else
  echo "Can't execute $bindir/mysqld_multi from dir $basedir";  
  exit;  
fi
case "$1" in
    'start' )  
        "$mysqld_multi" --defaults-extra-file=$conf start $2  
        ;;  
    'stop' )  
        "$mysqld_multi" --defaults-extra-file=$conf stop $2  
        ;;  
    'report' )  
        "$mysqld_multi" --defaults-extra-file=$conf report $2  
        ;;  
    'restart' )  
        "$mysqld_multi" --defaults-extra-file=$conf stop $2  
        "$mysqld_multi" --defaults-extra-file=$conf start $2  
        ;;  
    *)  
        echo "Usage: $0 {start|stop|report|restart}" >&2  
        ;;  
esac

好了,到这里我们所有的配置就全部完成了,下面我们打包备份一下。

八、整体备份方便后续迁移

1
2
3
4
5
6
7
[root@node1 ~]# cd /data/ 
[root@node1 data]# tar czvf mysql-5.5.350-full.tar.gz /data/mysql/
[root@node1 data]# ll -h 
总用量 128M  
drwx------.  2 root  root   16K 8月  17 18:42 lost+found  
drwxr-xr-x  22 mysql mysql 4.0K 1月   6 22:08 mysql  
-rw-r--r--   1 root  root  128M 1月   7 00:25 mysql-5.5.350-full.tar.gz

注,备份完成后,直接将mysql-5.5.350-full.tar.gz拿到其他服务器上,解压后便可以直接启用。嘿嘿,方便吧……

九、管理MySQL多实例

1.同时启动四个mysql实例

(1).方法一:

1
[root@node1 ~]# /data/mysql/init.d/mysqld_multi.server start 1,2,3,4

或方法二:

1
[root@node1 ~]# /data/mysql/init.d/mysqld_multi.server start 3306,3307,3308,3309

(2).查看一下启动的实例

1
2
3
4
5
[root@node1 ~]# netstat -ntulp | grep mysqld 
tcp        0      0 0.0.0.0:3307                0.0.0.0:*                   LISTEN      31416/mysqld
tcp        0      0 0.0.0.0:3308                0.0.0.0:*                   LISTEN      31414/mysqld
tcp        0      0 0.0.0.0:3309                0.0.0.0:*                   LISTEN      31420/mysqld
tcp        0      0 0.0.0.0:3306                0.0.0.0:*                   LISTEN      31413/mysqld

2.同时关闭四个mysql实例

(1).方法一:

1
[root@node1 ~]# /data/mysql/init.d/mysqld_multi.server stop 1,2,3,4

或方法二:

1
[root@node1 ~]# /data/mysql/init.d/mysqld_multi.server stop 3306,3307,3308,3309

3.单独启动或关闭mysql实例

(1).启动一个实例

1
2
3
[root@node1 ~]# /data/mysql/init.d/mysqld_multi.server start 1
[root@node1 ~]# netstat -ntulp | grep mysqld 
tcp        0      0 0.0.0.0:3306                0.0.0.0:*                   LISTEN      32221/mysqld

(2).关闭一个实例

1
[root@node1 ~]# /data/mysql/init.d/mysqld_multi.server stop 1

注,启动或关闭两个或者三个实例方法的上面相同这里就不再演示。

十、登录MySQL多实例

注,我们同时启动四个实例,下面我们来演示一下怎么分别登录这四个实例。为了演示四个实例的区别,我们分别在四个实例中创建mydb1、mydb2、mydb3、mydb4。

1.登录[mysqld1]

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
[root@node1 ~]# /data/mysql/bin/mysql -uroot -h127.0.0.1 -P3306 -p 
Enter password:   
Welcome to the MySQL monitor.  Commands end with ; or \g.  
Your MySQL connection id is 1  
Server version: 5.5.35-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> show databases; 
+--------------------+  
| Database           |  
+--------------------+  
| information_schema |  
| mysql              |  
| performance_schema |  
test               |  
+--------------------+  
4 rows in set (0.00 sec)  
mysql> create database mydb1;  
Query OK, 1 row affected (0.00 sec)
mysql> show databases; 
+--------------------+  
| Database           |  
+--------------------+  
| information_schema |  
| mydb1              |  
| mysql              |  
| performance_schema |  
test               |  
+--------------------+  
5 rows in set (0.00 sec)

2.登录[mysqld2]

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
[root@node1 ~]# /data/mysql/bin/mysql -uroot -h127.0.0.1 -P3307 -p 
Enter password:   
Welcome to the MySQL monitor.  Commands end with ; or \g.  
Your MySQL connection id is 1  
Server version: 5.5.35-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> show databases; 
+--------------------+  
| Database           |  
+--------------------+  
| information_schema |  
| mysql              |  
| performance_schema |  
test               |  
+--------------------+  
4 rows in set (0.00 sec)
mysql> create database mydb2; 
Query OK, 1 row affected (0.00 sec)
mysql> show databases; 
+--------------------+  
| Database           |  
+--------------------+  
| information_schema |  
| mydb2              |  
| mysql              |  
| performance_schema |  
test               |  
+--------------------+  
5 rows in set (0.00 sec)

3.登录[mysqld3]

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
[root@node1 ~]# /data/mysql/bin/mysql -uroot -h127.0.0.1 -P3308 -p 
Enter password:   
Welcome to the MySQL monitor.  Commands end with ; or \g.  
Your MySQL connection id is 1  
Server version: 5.5.35-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> show databases; 
+--------------------+  
| Database           |  
+--------------------+  
| information_schema |  
| mysql              |  
| performance_schema |  
test               |  
+--------------------+  
4 rows in set (0.01 sec)
mysql> create database mydb3; 
Query OK, 1 row affected (0.00 sec)
mysql> show databases; 
+--------------------+  
| Database           |  
+--------------------+  
| information_schema |  
| mydb3              |  
| mysql              |  
| performance_schema |  
test               |  
+--------------------+  
5 rows in set (0.00 sec)

4.登录[mysqld4]

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
[root@node1 ~]# /data/mysql/bin/mysql -uroot -h127.0.0.1 -P3309 -p 
Enter password:   
Welcome to the MySQL monitor.  Commands end with ; or \g.  
Your MySQL connection id is 1  
Server version: 5.5.35-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> show databases; 
+--------------------+  
| Database           |  
+--------------------+  
| information_schema |  
| mysql              |  
| performance_schema |  
test               |  
+--------------------+  
4 rows in set (0.01 sec)
mysql> create database mydb4; 
Query OK, 1 row affected (0.00 sec)
mysql> show databases; 
+--------------------+  
| Database           |  
+--------------------+  
| information_schema |  
| mydb4              |  
| mysql              |  
| performance_schema |  
test               |  
+--------------------+  
5 rows in set (0.00 sec)

好了,我们的MySQL多实例登录就演示到这里了,下面我们来设置一下mysql的root密码。   

十一、其它管理配置

1.为mysql的root用户创建密码

1
2
3
4
[root@node1 ~]# /data/mysql/bin/mysqladmin -uroot -h127.0.0.1 -P3306 password '123456'
[root@node1 ~]# /data/mysql/bin/mysqladmin -uroot -h127.0.0.1 -P3307 password '123456'
[root@node1 ~]# /data/mysql/bin/mysqladmin -uroot -h127.0.0.1 -P3308 password '123456'
[root@node1 ~]# /data/mysql/bin/mysqladmin -uroot -h127.0.0.1 -P3309 password '123456'

2.删除匿名连接的空密码帐号

注,分别登录实例[mysqld1]、[mysqld2]、[mysqld3]、[mysqld4],执行以下命令:

1
2
3
4
5
6
mysql>use mysql; #选择系统数据库mysql  
mysql>select Host,User,Password from user; #查看所有用户  
mysql>delete from user where password="";#删除无密码账户  
mysql>flush privileges; #刷新权限  
mysql>select Host,User,Password from user; #确认密码为空的用户是否已全部删除  
mysql>exit;

十二、总结

1.采用源码编译安装MySQL,可能在第一次会花费较多的时间,但却是非常值得的,因为我们可以自己组织所有MySQL相关文件的位置;并且经过源码编译安装后的MySQL,可以直接复制到其它服务器上运行,大大方便了我们以后的迁移、备份和新服务器的配置。

2.本文中仅仅用了四个实例[mysqld1]、[mysqld2]、[mysqld3]、[mysqld4]来举例,实际上我们可以通过这样的方式,实现[mysqld5]、[mysqld6]...等更多的实例,前提是你的服务器硬件配置得根得 上,但是一般我们这边不会超过6个实例。

3.在单机运行多实例的情况下,切忌不要使用 mysql -hlocalhost 或 直接忽略-h参数登录服务器,这应该算是MySQL的一个bug,就是如果使用localhost或忽略-h参数,而不是指定127.0.0.1的话,即使选择的端口是3307,还是会登陆到3306中去,因此应尽量避免这种混乱的产生,统一用127.0.0.1绑定端口或采用socket来登录,在mysql5.5中你不指定-h127.0.0.1选项,你是无法登录的。

最后,希望大家有所收获吧^_^……

本文出自 “Share your knowledge …” 博客,请务必保留此出处http://freeloda.blog.51cto.com/2033581/1349312

相关文章:

ASP.NET超凡的代码控制

crystal译yesky 适应性 肯定的是,通常任何一个全新的技术,在市场渗透都会花费一些时间。微软正在开始让ASP和IIS平台通过行业验证,以便让其作为其它网络服务器之外可以供选择的平台 对于在其基本构架上的如此巨大的改变,是很难说服…

老码农:这是我见过最操蛋的代码,切勿模仿!

作为一名老码农,我的心这次凉透了!事情起因很简单:我在全国最大ZZ的同性组织某Hub上浏览时候,发现这样的一条信息:Python 超过 C、JS 薪酬排行第一(最大招聘网站Indeed.com数据)噗,9…

QTP时间格式的转换(YYYYMMDDHHMMSS)

之前查了好多资料都是这样写的: sendTime year(sendTime) & right( "00 " & month(sendTime),2) & right( "00 " & day(sendTime),2) & right( "00 " & hour(sendTime),2) &…

Selenium2+python自动化25-js处理日历控件(修改readonly属性)

前言 日历控件是web网站上经常会遇到的一个场景,有些输入框是可以直接输入日期的,有些不能,以我们经常抢票的12306网站为例,详细讲解如何解决日历控件为readonly属性的问题。 基本思路:先用js去掉readonly属性&#xf…

ASP.NET强大的性能

crystal译 yesky 一个程序,速度是一件非常令人渴望的东西。一旦代码开始工作,接下来你就得尽可能的让它运作的快些,再快些, 在ASP中你只有尽可能拧干你的代码,以至于不得不将他们移植到一个仅有很少一点性能的部件中。…

POJ-1753 Flip Game 枚举 状态压缩

刚开始做这题时总是在想应该用何种的策略来进行翻装,最后还是没有想出来~~~ 这题过的代码的思路是用在考虑到每个点被翻装的次数只有0次或者是1次,所以对于16个点就只有2^16中请况了。再运用位运算将状态压缩到一个32位…

“半真半假”DeepFake换脸也能精准识别?阿里安全提出全新检测方法

一段包含多个人脸的视频中,攻击者只对一个或者几个人的人脸进行伪造,这种“半真半假”的伪造情况能否被检测识别?近日,阿里安全图灵实验室宣布,其已成功打造出针对这种换脸视频的DeepFake检测技术,阐述该技…

python 定时任务

Python 定时任务 最近学习到了 python 中两种开启定时任务的方法,和大家分享一下心得。 sched.scheduler()threading.Timer()sched 定时任务 使用sched的套路如下: s sched.scheduler(time.time, time.sleep) s.enter(delay, priority, func1, (arg1, a…

思科AP与交换机端口的配置

思科AP与交换机端口的配置。 思科AP可以分IOS AP 和LAP。 1、IOS AP 中如果AP上需要创建多个SSID,连接的交换机端口则需要: switch(config-interfa)# sw mod trunk switch(config-interfa)# sw trunk allow vlan 1,x,x,x (SSID对应的VLAN) 另外注意&…

Namespace(命名空间)的使用

作者&#xff1a;飞刀 关于Namespace(命名空间)的使用常用<% Import Namespace"System.Data" %>,这是在引用M$为我们提供的Namespace,这和ASP不同的&#xff0c;我们贏SP.net必须先引用与我们操作有关的Namespace后才能使用相应的功能。其实说白了&#xff…

“编程能力差!90%输在这点上”谷歌AI专家:其实都是瞎努力!

最近几年&#xff0c;我看过市面上很多 Python和人工智能的教程&#xff0c;基本都在这样讲&#xff1a;先介绍Python基本语法、dict、tuple 等基本库的使用&#xff0c;最后学习机器学习、深度学习的常用算法......但我与Google人工智能开发专家彭靖田老师沟通后发现&#xff…

NAS存储对称和非对称结构之前的区别概述

传统的系统利用紧耦合对称架构&#xff0c;这种架构的设计旨在解决HPC&#xff08;高性能计算、超级运算&#xff09;问题&#xff0c;现在其正在向外扩展成为云存储从而满足快速呈现的市场需求。下一代架构已经采用了松弛耦合非对称架构&#xff0c;集中元数据和控制操作&…

Lucene:基于Java的全文检索引擎简介(转载)

Lucene是一个基于Java的全文索引工具包。基于Java的全文索引引擎Lucene简介&#xff1a;关于作者和Lucene的历史全文检索的实现&#xff1a;Luene全文索引和数据库索引的比较中文切分词机制简介&#xff1a;基于词库和自动切分词算法的比较具体的安装和使用简介&#xff1a;系统…

昨天,我用 Python 写了一个婚介模型

作者 | 天元浪子来源 | CSDN&#xff08;ID&#xff1a;CSDNnews&#xff09;先声明一下&#xff1a;本文纯属七夕应景娱乐之作。如果有人因为遵循本模型提出的择偶理论而导致失恋或单身&#xff0c;除了同情&#xff0c;我不能补偿更多。在中国的传统节日里&#xff0c;七夕可…

WCF服务一:WCF服务简介

一、回顾开发历史&#xff1a; 软件架构的设计经历了&#xff1a;从面向对象程序&#xff0c;到面向组件程序设计&#xff0c;再到面向服务程序设计。这三种方式都致力于同一个目标&#xff1a;封装和重用。 面向对象程序设计&#xff1a;类封装功能并提供代码重用。 面向组件程…

MIT 更新最大自然灾害图像数据集,囊括 19 种灾害事件

作者 | 神经小兮来源 | HyperAI超神经&#xff08;ID&#xff1a;HyperAI&#xff09;内容提要&#xff1a;麻省理工学院在最近 ECCV 2020 上提交的一篇论文中&#xff0c;发布了一套自然灾害图像数据集。这是迄今为止规模最大、质量最高的自然灾害卫星图像数据集。2020 年&…

DataBind数据核心

作者&#xff1a;飞刀 这一节主要是要讲DataBind&#xff0c;这个在ASP.net中是很重要的东东&#xff0c;几乎所有的控件都需要它来控制数据的操作。也可以说是ASP.net的数据核心。 我们先来看一个简单的例子&#xff1a; <% Page Language"C#" %> <% …

convertViewsetTag方法的一点理解

转自&#xff1a;http://blog.163.com/freemanls126/blog/static/164585061201171210504864/ 前言 首先我们要知道setTag方法是干什么的&#xff0c;SDK解释为 Tags Unlike IDs, tags are not used to identify views. Tags are essentially an extra piece of information tha…

iOS使用Security.framework进行RSA 加密解密签名和验证签名

iOS 上 Security.framework为我们提供了安全方面相关的api&#xff1b; Security框架提供的RSA在iOS上使用的一些小结 支持的RSA keySize 大小有&#xff1a;512&#xff0c;768&#xff0c;1024&#xff0c;2048位支持的RSA 填充方式有三种&#xff1a;NOPadding,PKCS1,OAEP 三…

Android APK反编译详解(附图)

这段时间在学Android应用开发&#xff0c;在想既然是用Java开发的应该很好反编译从而得到源代码吧&#xff0c;google了一下&#xff0c;确实很简单&#xff0c;以下是我的实践过程。 在此郑重声明&#xff0c;贴出来的目的不是为了去破解人家的软件&#xff0c;完全是一种学习…

你不知道的18个Python高效编程技巧

来源 | Python编程时光初识Python语言&#xff0c;觉得python满足了我上学时候对编程语言的所有要求。python语言的高效编程技巧让我们这些大学曾经苦逼学了四年c或者c的人&#xff0c;兴奋的不行不行的&#xff0c;终于解脱了。高级语言&#xff0c;如果做不到这样&#xff0c…

Alisql源码编译安装(详细篇)

前言 AliSQL 在 2016 云栖大会宣布开放源代码之后&#xff0c;迅速就获得了广泛的关注&#xff0c;目前(2016-10-27) star 数目已达 1187&#xff0c;欢迎访问 AliSQL GitHub 项目关注。社区反应也非常活跃&#xff0c;在 Issue 中提了不少反馈建议&#xff0c;其中有一部分是和…

如何给DataGrid添加自动增长列

作者&#xff1a; cuike519的专栏 http://blog.csdn.net/cuike519/我想我们都知道在数据库中如何添加自增长列&#xff0c;我们可以将这个自增长列绑定到DataGrid上使得用户方便的知道现在是第几行&#xff0c;今天我介绍一种不用数据库就可以简单显示出自增长列的方法&…

达摩院NLP团队斩获六项世界冠军背后,让AI没有难懂的语言

2018年末&#xff0c;BERT横空出世&#xff0c;它采用自编码对句子进行表示&#xff0c;通过预测掩盖词和上下句之间的关系作为语言模型学习任务&#xff0c;使用更多的数据&#xff0c;更大的模型&#xff0c;在多个自然语言处理&#xff08;NLP&#xff09;任务中显著超越之前…

提权巧用RAR.EXE

rar.exe是什么&#xff1f;它就是大名鼎鼎的winrar自带的命令行解压程序。在提权中我们经常要下载各种敏感文件&#xff0c;比如:SU目录。你想一下&#xff0c;如果su目录文件这么多&#xff0c;难道你要一个个的下载&#xff1f;&#xff1f;这明显就很麻烦&#xff0c;有了ra…

OSGI企业应用开发(二)Eclipse中搭建Felix运行环境

上篇文章介绍了什么是OSGI以及使用OSGI构建应用的优点&#xff0c;接着介绍了两款常用的OSGI实现&#xff0c;分别为Apache Felix和Equinox&#xff0c;接下来开始介绍如何在Eclipse中使用Apache Felix和Equinox搭建OSGI运行环境。 一、搭建Apache Felix运行环境 上篇文章中介绍…

马斯克脑机接口、BrainOS相继发布,不努力也能有出路了

作者 | 马超责编 | Carol封图 | CSDN 下载自视觉中国在北京时间的8月29日凌晨&#xff0c;钢铁侠埃隆马斯克投资1亿多美元的脑机接口初创公司公司Neuralink&#xff08;http://www.neurolink.company/&#xff09;进行了一次现场发布会&#xff0c;展示新一代的脑机接口设备。这…

C语言单向链表的实现

一个简单结点的结构体表示为&#xff1a;struct note{int data&#xff1b; /*数据成员可以是多个不同类型的数据*/struct note *next&#xff1b; /*指针变量成员只能是-个*/}&#xff1b; 一个简单的单向链表的图示1&#xff0e;链表是结构、指针相结合…

Java开发常用Linux命令

1.查找文件 find / -name filename.txt根据名称查找/目录下的filename.txt文件。 find . -name "*.xml"递归查找所有的xml文件 find . -name "*.xml" |xargs grep "hello world"递归查找所有文件内容中包含hello world的xml文件 grep -H spring …

数据库开发基本操作-安装Sql Server 2005出现“性能监视器计数器要求”错误解决方法...

今天在安装SQL Server 2005时&#xff0c;出现“性能监视器计数器要求”错误&#xff0c;因为以前出现过这种错误&#xff0c;得到了解决。今天又又出现这种错误&#xff0c;但并不是很清楚当时的解决办法&#xff0c;所以这次把解决方法记录下来&#xff0c;供自己以后参考&am…