免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 2444 | 回复: 7
打印 上一主题 下一主题

看一个mysql的端口是否开着 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2010-08-24 15:40 |只看该作者 |倒序浏览
1台linux 上有2个mysql服务 ,他们的端口是3307 3308

现在我想看一个mysql的端口是否开着
用什么命令检查一下PORT3307是否开着。

linux下?

论坛徽章:
59
2015七夕节徽章
日期:2015-08-24 11:17:25ChinaUnix专家徽章
日期:2015-07-20 09:19:30每周论坛发贴之星
日期:2015-07-20 09:19:42ChinaUnix元老
日期:2015-07-20 11:04:38荣誉版主
日期:2015-07-20 11:05:19巳蛇
日期:2015-07-20 11:05:26CU十二周年纪念徽章
日期:2015-07-20 11:05:27IT运维版块每日发帖之星
日期:2015-07-20 11:05:34操作系统版块每日发帖之星
日期:2015-07-20 11:05:36程序设计版块每日发帖之星
日期:2015-07-20 11:05:40数据库技术版块每日发帖之星
日期:2015-07-20 11:05:432015年辞旧岁徽章
日期:2015-07-20 11:05:44
2 [报告]
发表于 2010-08-24 15:53 |只看该作者
netstat -tuna|grep 330

论坛徽章:
0
3 [报告]
发表于 2010-08-24 16:05 |只看该作者
本帖最后由 liyihongcug 于 2010-08-24 16:09 编辑

感谢netstat -tuna | grep 3306
tcp 0 0 10.0.1.155:53251 192.168.10.1:3306 ESTABLISHED
[r bin]# netstat -tuna | grep 3308
tcp 0 0 0.0.0.0:3308 0.0.0.0:* LISTEN
[r bin]#netstat -tuna | grep 3307
tcp 0 0 0.0.0.0:3307 0.0.0.0:* LISTEN

请帮助分析下 3306 3307 3308 是否开着 ?

论坛徽章:
0
4 [报告]
发表于 2010-08-24 16:07 |只看该作者
楼主很厉害~

论坛徽章:
0
5 [报告]
发表于 2010-08-24 16:13 |只看该作者
这个机器有3个mysql 服务 。
用mysql -uslave -p123 -P3307 -S /var/lib/mysql2/mysql.sock2
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql2/mysql.sock2' (2)
有点不确定,原因在哪里

ps -ef | grep  mysql
发现有2个mysql服务已经启动

论坛徽章:
0
6 [报告]
发表于 2010-08-24 16:25 |只看该作者
按道理都是开着的

奇怪 mysql 3306的默认端口都会开着???

主要 my.cnf 配置如下
[mysqld_multi]
mysqld = /usr/bin/mysqld_safe
mysqladmin = /usr/bin/mysqladmin
user = root
password = 123

[mysqld2]
socket = /var/lib/mysql2/mysql.sock2
port = 3307
pid-file = /var/lib/mysql2/hostname.pid2
datadir = /var/lib/mysql2
language = /usr/share/mysql/english
user = root
master-host=192.168.10.1
.。。。。其他省略

log-error=/var/log/mysqld/mysql2.log

[mysqld3]
mysqld = /usr/bin/mysqld_safe
mysqladmin = /usr/bin/mysqladmin
socket = /var/lib/mysql3/mysql.sock3
port = 3308
pid-file = /var/lib/mysql3/hostname.pid3
datadir = /var/lib/mysql3
language = /usr/share/mysql/english
user = root
server-id=2
master-host=192.168.10.2
master-user=slave
master-password=slavepass
#master_log_file=mysql-bin.000001
#master_log_pos=4028
master-connect-retry=60
default-character-set=utf8
character-set-server=utf8
default-collation=utf8_unicode_ci
default-table-type=INNODB
wait_timeout=800
connect_timeout=25
interactive_timeout=800
max_connections=50
sort_buffer = 228M
group_concat_max_len=65536
innodb_buffer_pool_size=4000MB
innodb_additional_mem_pool_size=20M
innodb_log_file_size=128M
innodb_log_buffer_size=8M
innodb_thread_concurrency=500
innodb_flush_method=O_DSYNC
table_cache=800
innodb_status_file = 1
innodb_flush_log_at_trx_commit = 0
innodb_autoextend_increment = 25M
skip-external-locking
innodb_table_locks=0
max_allowed_packet=32M
tmp_table_size=96M
thread_concurrency=10
thread_cache_size=500
log-error=/var/log/mysqld/mysql3.log
slave-skip-errors=1061,1062
skip-slave-start
#[mysqld_safe]
#log-error=/var/log/mysql/mysql.log
#pid-file=/var/run/mysqld/mysqld.pid

可以判断至少有2个 mysql 服务器 在同台机器上

ps -ef | grep mysql
lh 14300 14112 0 06:48 pts/3 00:00:00 grep mysql
root 18664 1 0 2009 begin_of_the_skype_highlighting              18664 1 0 2009      end_of_the_skype_highlighting begin_of_the_skype_highlighting              18664 1 0 2009 begin_of_the_skype_highlighting              18664 1 0 2009      end_of_the_skype_highlighting      end_of_the_skype_highlighting ? 00:00:00 /bin/sh /usr/bin/mysqld_safe --socket=/var/lib/mysql2/mysql.sock2 --port=3307 --pid-file=/var/lib/mysql2/hostname.pid2 --datadir=/var/lib/mysql2 --language=/usr/share/mysql/english --user=root --server-id=2 --master-host=192.168.10.1 --master-user=slave --master-password=slavepass --master-connect-retry=60 --replicate-do-db=oddsmatrixdb --relay-log=/var/log/mysqld/relay2.log --relay-log-info-file=/var/log/mysqld/relay2-log.info --relay-log-index=/var/log/mysqld/relay2-log.index --default-character-set=utf8 --character-set-server=utf8 --default-collation=utf8_unicode_ci --wait_timeout=800 --connect_timeout=25 --interactive_timeout=800 --max_connections=50 --sort_buffer=228M --group_concat_max_len=65536 --innodb_buffer_pool_size=4000MB --innodb_additional_mem_pool_size=20M --innodb_log_file_size=128M --innodb_log_buffer_size=8M --innodb_thread_concurrency=500 --innodb_flush_method=O_DSYNC --table_cache=800 --innodb_status_file=1 --innodb_flush_log_at_trx_commit=0 --innodb_autoextend_increment=25M --skip-external-locking --innodb_table_locks=0 --max_allowed_packet=100M --tmp_table_size=96M --thread_concurrency=10 --thread_cache_size=500 --log-error=/var/log/mysqld/mysql2.log --socket=/var/lib/mysql2/mysql.sock2 --port=3307 --pid-file=/var/lib/mysql2/hostname.pid2 --datadir=/var/lib/mysql2 --language=/usr/share/mysql/english --user=root --server-id=2 --master-host=192.168.10.1--master-user=slave --master-password=slavepass --master-connect-retry=60 --replicate-do-db=oddsmatrixdb --relay-log=/var/log/mysqld/relay2.log --relay-log-info-file=/var/log/mysqld/relay2-log.info --relay-log-index=/var/log/mysqld/relay2-log.index --default-character-set=utf8 --character-set-server=utf8 --default-collation=utf8_unicode_ci --wait_timeout=800 --connect_timeout=25 --interactive_timeout=800 --max_connections=50 --sort_buffer=228M --group_concat_max_len=65536 --innodb_buffer_pool_size=4000MB --innodb_additional_mem_pool_size=20M --innodb_log_file_size=128M --innodb_log_buffer_size=8M --innodb_thread_concurrency=500 --innodb_flush_method=O_DSYNC --table_cache=800 --innodb_status_file=1 --innodb_flush_log_at_trx_commit=0 --innodb_autoextend_increment=25M --skip-external-locking --innodb_table_locks=0 --max_allowed_packet=100M --tmp_table_size=96M --thread_concurrency=10 --thread_cache_size=500 --log-error=/var/log/mysqld/mysql2.log
root 18923 18664 1 2009 ? 8-18:43:14 /usr/libexec/mysqld --basedir=/usr --datadir=/var/lib/mysql2 --user=root --pid-file=/var/lib/mysql2/hostname.pid2 --skip-external-locking --port=3307 --socket=/var/lib/mysql2/mysql.sock2 --language=/usr/share/mysql/english --server-id=2 --master-host=192.168.10.1 --master-user=slave --master-password=slavepass --master-connect-retry=60 --replicate-do-db=oddsmatrixdb --relay-log=/var/log/mysqld/relay2.log --relay-log-info-file=/var/log/mysqld/relay2-log.info --relay-log-index=/var/log/mysqld/relay2-log.index --default-character-set=utf8 --character-set-server=utf8 --default-collation=utf8_unicode_ci --wait_timeout=800 --connect_timeout=25 --interactive_timeout=800 --max_connections=50 --sort_buffer=228M --group_concat_max_len=65536 --innodb_buffer_pool_size=4000MB --innodb_additional_mem_pool_size=20M --innodb_log_file_size=128M --innodb_log_buffer_size=8M --innodb_thread_concurrency=500 --innodb_flush_method=O_DSYNC --table_cache=800 --innodb_status_file=1 --innodb_flush_log_at_trx_commit=0 --innodb_autoextend_increment=25M --skip-external-locking --innodb_table_locks=0 --max_allowed_packet=100M --tmp_table_size=96M --thread_concurrency=10 --thread_cache_size=500 --language=/usr/share/mysql/english --server-id=2 --master-host=192.168.10.1 --master-user=slave --master-password=slavepass --master-connect-retry=60 --replicate-do-db=oddsmatrixdb --relay-log=/var/log/mysqld/relay2.log --relay-log-info-file=/var/log/mysqld/relay2-log.info --relay-log-index=/var/log/mysqld/relay2-log.index --default-character-set=utf8 --character-set-server=utf8 --default-collation=utf8_unicode_ci --wait_timeout=800 --connect_timeout=25 --interactive_timeout=800 --max_connections=50 --sort_buffer=228M --group_concat_max_len=65536 --innodb_buffer_pool_size=4000MB --innodb_additional_mem_pool_size=20M --innodb_log_file_size=128M --innodb_log_buffer_size=8M --innodb_thread_concurrency=500 --innodb_flush_method=O_DSYNC --table_cache=800 --innodb_status_file=1 --innodb_flush_log_at_trx_commit=0 --innodb_autoextend_increment=25M --skip-external-locking --innodb_table_locks=0 --max_allowed_packet=100M --tmp_table_size=96M --thread_concurrency=10 --thread_cache_size=500
root 29417 1 0 2009 ? 00:00:00 /bin/sh /usr/bin/mysqld_safe --socket=/var/lib/mysql3/mysql.sock3 --port=3308 --pid-file=/var/lib/mysql3/hostname.pid3 --datadir=/var/lib/mysql3 --language=/usr/share/mysql/english --user=root --server-id=2 --master-host=192.168.10.2 --master-user=slave --master-password=slavepass --master-connect-retry=60 --default-character-set=utf8 --character-set-server=utf8 --default-collation=utf8_unicode_ci --default-table-type=INNODB --wait_timeout=800 --connect_timeout=25 --interactive_timeout=800 --max_connections=50 --sort_buffer=228M --group_concat_max_len=65536 --innodb_buffer_pool_size=4000MB --innodb_additional_mem_pool_size=20M --innodb_log_file_size=128M --innodb_log_buffer_size=8M --innodb_thread_concurrency=500 --innodb_flush_method=O_DSYNC --table_cache=800 --innodb_status_file=1 --innodb_flush_log_at_trx_commit=0 --innodb_autoextend_increment=25M --skip-external-locking --innodb_table_locks=0 --max_allowed_packet=32M --tmp_table_size=96M --thread_concurrency=10 --thread_cache_size=500 --log-error=/var/log/mysqld/mysql3.log --slave-skip-errors=1061,1062 --skip-slave-start --socket=/var/lib/mysql3/mysql.sock3 --port=3308 --pid-file=/var/lib/mysql3/hostname.pid3 --datadir=/var/lib/mysql3 --language=/usr/share/mysql/english --user=root --server-id=2 --master-host=192.168.10.2 --master-user=slave --master-password=slavepass --master-connect-retry=60 --default-character-set=utf8 --character-set-server=utf8
从这个现实结果可以知道确实 是2个mysql在运行。

问题如下:
1 我直接mysql -uroot -p123发现无法登陆
后来我换成./mysqld_safe --user=mysql

[l@dbin]$ ./mysqld_safe --socket=/var/lib/mysql3/mysql.sock3 --port=3308
cat: /var/lib/mysql/devcph.betbrain.com.pid: Permission denied
rm: cannot remove `/var/lib/mysql/devcph.betbrain.com.pid': Permission denied
Fatal error: Can't remove the pid file: /var/lib/mysql/devcph.betbrain.com.pid
./mysqld_safe: line 353: /var/lib/mysql/devcph.betbrain.com.err: Permission denied
Please remove it manually and start ./mysqld_safe again
mysqld daemon not started
[lh@devcph bin]$--------------------------现在无法登陆到该2个mysql服务上


2 这2个mysql 是源码安装的还是2进制安装的 ,如何登陆

论坛徽章:
0
7 [报告]
发表于 2010-08-24 18:18 |只看该作者
一台机器上运行多个mysql实例是不能直接用mysql -u -p  登录的

mysql -u -p 是默认的登录3306端口的

可以-S 指定socket 来登录 或者  -h -P 指定主机+端口

论坛徽章:
0
8 [报告]
发表于 2010-09-03 14:53 |只看该作者
lsof -i:3307
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP