MYSQL问题

时间:2018-08-01 16:20:58

标签: java mysql phpmyadmin

<< strong>已编辑> 我是一名中级Java程序员,目前正在使用Java和MySQL来创建应用程序。我正在使用Xampp及其随附的PHPMYAdmin。 服务器位于127.0.0.1,没有任何路由器,Wifi系统或网络。我的应用程序也位于127.0.0.1 每当我尝试使用Java连接到MySQL时,都会显示以下消息:

com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link 
failure  The last packet sent successfully to the server was 0 milliseconds 
ago.The driver has not received any packets from the server.

但是MySQL服务器正在正常运行。当我登录PHPMYAdmin时,这些 错误显示:

    #2002 - Only one usage of each socket address (protocol/network 
    address/port) 
    is normally permitted.
    — The server is not responding (or the local server's socket is not 
    correctly configured).
    mysqli_real_connect(): (HY000/2002): Only one usage of each socket 
    address 
    (protocol/network address/port) is normally permitted.
    Connection for controluser as defined in your configuration failed.
    mysqli_real_connect(): (HY000/2002): Only one usage of each socket 
    address 
    (protocol/network address/port) is normally permitted.
    Retry to connect
    Warning in .\libraries\dbi\DBIMysqli.php#629
    mysqli_real_escape_string() expects parameter 1 to be mysqli, boolean 
    given

    Backtrace

    .\libraries\dbi\DBIMysqli.php#629: mysqli_real_escape_string(
    boolean false,
    string 'root',
    )
    .\libraries\DatabaseInterface.php#2670: PMA\libraries\dbi\DBIMysqli- 
    >escapeString(
    boolean false,
    string 'root',
    )
    .\libraries\Menu.php#142: PMA\libraries\DatabaseInterface- 
    >escapeString(string 'root')
    .\libraries\Menu.php#110: PMA\libraries\Menu->_getAllowedTabs(string 
    'server')
    .\libraries\Menu.php#83: PMA\libraries\Menu->_getMenu()
    .\libraries\Response.php#316: PMA\libraries\Menu->getHash()
    .\libraries\Response.php#441: PMA\libraries\Response->_ajaxResponse()
    PMA\libraries\Response::response()
    Warning in .\libraries\dbi\DBIMysqli.php#629
    mysqli_real_escape_string() expects parameter 1 to be mysqli, boolean 
    given

    Backtrace

   .\libraries\dbi\DBIMysqli.php#629: mysqli_real_escape_string(
   boolean false,
   string 'root',
   )
   .\libraries\DatabaseInterface.php#2670: PMA\libraries\dbi\DBIMysqli- 
   >escapeString(
   boolean false,
   string 'root', 
   )
   .\libraries\Menu.php#142: PMA\libraries\DatabaseInterface- 
   >escapeString(string 
   'root')
   .\libraries\Menu.php#110: PMA\libraries\Menu->_getAllowedTabs(string 
   'server')
   .\libraries\Menu.php#71: PMA\libraries\Menu->_getMenu()
   .\libraries\Response.php#327: PMA\libraries\Menu->getDisplay()
   .\libraries\Response.php#441: PMA\libraries\Response->_ajaxResponse()
   PMA\libraries\Response::response()

mysql my.ini文件:

[mysqld]
port= 3306
socket = "E:/xampp/mysql/mysql.sock"
basedir = "E:/xampp/mysql" 
tmpdir = "E:/xampp/tmp" 
datadir = "E:/xampp/mysql/data"
pid_file = "mysql.pid"
# enable-named-pipe
key_buffer = 16M
max_allowed_packet = 1M
sort_buffer_size = 512K
net_buffer_length = 8K
read_buffer_size = 256K
read_rnd_buffer_size = 512K
myisam_sort_buffer_size = 8M
log_error = "mysql_error.log"


plugin_dir = "E:/xampp/mysql/lib/plugin/" 

innodb_data_home_dir = "E:/xampp/mysql/data"
innodb_data_file_path = ibdata1:10M:autoextend
innodb_log_group_home_dir = "E:/xampp/mysql/data"
innodb_buffer_pool_size = 16M
innodb_additional_mem_pool_size = 2M
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

[isamchk]
key_buffer = 20M
sort_buffer_size = 20M
read_buffer = 2M
write_buffer = 2M

[myisamchk]
key_buffer = 20M
sort_buffer_size = 20M
read_buffer = 2M
write_buffer = 2M

[mysqlhotcopy]
interactive-timeout

以下是我如何连接Java:

try{
Class.forName("java.sql.DriverManager");
Connection conn=  
(Connection)DriverManager.getConnection("jdbc:mysql:// 
localhost:3306/","root","mypassword");
Statement stmt=(Statement)conn.createStatement();
}
catch(Exception e){/*handling*/}

0 个答案:

没有答案