Gee*_*Out 136 mysql linux ubuntu
我已经安装了MySQL,甚至以用户身份登录.
但是,当我尝试这样连接时:
http://localhost:3306
mysql://localhost:3306
两者都不起作用.不确定两者是否应该工作,但至少其中一个应该:)
我怎样才能确保端口确实是3306?是否有linux命令以某种方式看到它?另外,有没有更正确的方法通过网址尝试?
Kei*_*ith 200
要在端口上查找侦听器,请执行以下操作:
netstat -tln
如果mysql确实正在侦听该端口,您应该看到一条看起来像这样的行.
tcp        0      0 127.0.0.1:3306              0.0.0.0:*                   LISTEN      
端口3306是MySql的默认端口.
要连接,您只需使用您需要的任何客户端,例如基本的mysql客户端.
mysql -h localhost -u用户数据库
或者是由库代码解释的URL.
ena*_*gra 135
使用Mysql客户端:
mysql> SHOW GLOBAL VARIABLES LIKE 'PORT';
bor*_*nac 62
grep port /etc/mysql/my.cnf (至少在debian/ubuntu作品中)
要么
netstat -tlpn | grep mysql
校验
bind-address 127.0.0.1
在/etc/mysql/my.cnf中查看可能的限制
mPr*_*inC 32
netstat -tlpn
它将显示如下列表:
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      1393/sshd
tcp        0      0 127.0.0.1:25            0.0.0.0:*               LISTEN      1859/master
tcp        0      0 123.189.192.64:7654     0.0.0.0:*               LISTEN      2463/monit
tcp        0      0 127.0.0.1:24135         0.0.0.0:*               LISTEN      21450/memcached
tcp        0      0 127.0.0.1:3306          0.0.0.0:*               LISTEN      16781/mysqld
以root身份使用所有详细信息.该-t选项将输出限制为TCP连接,-l对于侦听端口,-p列出程序名称并-n显示端口的数字版本而不是命名版本.
通过这种方式,您可以看到进程名称和端口.
尝试仅使用-e(--execute)选项:
$ mysql -u root -proot -e "SHOW GLOBAL VARIABLES LIKE 'PORT';"                                                                                                       (8s 26ms)
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| port          | 3306  |
+---------------+-------+
替换root为"用户名"和"密码"
两个网址都不正确 - 应该是
jdbc:mysql://host:port/database
我认为不言而喻,但使用Java连接到数据库需要JDBC驱动程序.你需要MySQL JDBC驱动程序.
也许您可以通过TCP/IP使用套接字进行连接.查看MySQL文档.
请参阅http://dev.mysql.com/doc/refman/5.0/en/connector-j-reference-configuration-properties.html
更新:
我试图telnet到MySQL(telnet ip 3306),但它不起作用:
http://lists.mysql.com/win32/253
我想这就是你的想法.
一些更简单的方法:如果您只想检查MySQL是否在某个端口上,您可以在终端中使用以下命令.在Mac上测试过.3306是默认端口.
mysql --host=127.0.0.1 --port=3306
如果您成功登录MySQL shell终端,那就太好了!这是我成功登录时获得的输出.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 9559
Server version: 5.6.21 Homebrew
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>
小智 6
对我来说,@joseluisq 的答案是:
错误 1045 (28000):用户“root”@“localhost”的访问被拒绝(使用密码:NO)
但它是这样工作的:
$ mysql -u root@localhost  -e "SHOW GLOBAL VARIABLES LIKE 'PORT';"
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| port          | 3306  |
+---------------+-------+
3306是mysql的默认端口.检查一下:
netstat -nl|grep 3306
它应该给出这个结果:
tcp 0 0 127.0.0.1:3306 0.0.0.0:*LISTEN
| 归档时间: | 
 | 
| 查看次数: | 412238 次 | 
| 最近记录: |