2013-04-02 287 views
11

我知道,這真的很傷心,但我無法連接到MySQL數據庫。Mysql:訪問被拒絕用戶'root'@'localhost'

我只是從MySQL網站上下載並解壓縮mysql-5.6.10-win32.zip。

我跟着this tutorial,但我無法以root身份連接到我的MySQL數據庫。

我知道在沒有密碼的情況下以root身份進行連接是不安全的,但我只需要做一些測試,所以我現在就可以做到這一點(如果我知道如何以root身份連接,我知道如何另外添加一個用戶)。

的my.ini

# For advice on how to change settings please see 
# http://dev.mysql.com/doc/refman/5.6/en/server-configuration-defaults.html 
# *** DO NOT EDIT THIS FILE. It's a template which will be copied to the 
# *** default location during install, and will be replaced if you 
# *** upgrade to a newer version of MySQL. 

[mysqld] 

# Remove leading # and set to the amount of RAM for the most important data 
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%. 
# innodb_buffer_pool_size = 128M 

# Remove leading # to turn on a very important data integrity option: logging 
# changes to the binary log between backups. 
# log_bin 

# These are commonly set, remove the # and set as required. 
basedir=c:\Programs\mysql-5.6.10-win32 
datadir=c:\Programs\mysql-5.6.10-win32\data 
port=3306 
server_id=1 


# Remove leading # to set options mainly useful for reporting servers. 
# The server defaults are faster for transactions and fast SELECTs. 
# Adjust sizes as needed, experiment to find the optimal values. 
# join_buffer_size = 128M 
# sort_buffer_size = 2M 
# read_rnd_buffer_size = 2M 

sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES 

[client] 

port=3306 

當我開始mysqld我看到:

> mysqld --console --init-file=..\set_root_password.sql 
2013-04-02 13:48:24 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details). 
2013-04-02 13:48:24 8600 [Note] Plugin 'FEDERATED' is disabled. 
2013-04-02 13:48:24 8600 [Note] InnoDB: The InnoDB memory heap is disabled 
2013-04-02 13:48:24 8600 [Note] InnoDB: Mutexes and rw_locks use Windows interlocked functions 
2013-04-02 13:48:24 8600 [Note] InnoDB: Compressed tables use zlib 1.2.3 
2013-04-02 13:48:24 8600 [Note] InnoDB: CPU does not support crc32 instructions 
2013-04-02 13:48:24 8600 [Note] InnoDB: Initializing buffer pool, size = 128.0M 
2013-04-02 13:48:24 8600 [Note] InnoDB: Completed initialization of buffer pool 
2013-04-02 13:48:24 8600 [Note] InnoDB: Highest supported file format is Barracuda. 
2013-04-02 13:48:24 8600 [Note] InnoDB: 128 rollback segment(s) are active. 
2013-04-02 13:48:24 8600 [Note] InnoDB: Waiting for purge to start 
2013-04-02 13:48:24 8600 [Note] InnoDB: 1.2.10 started; log sequence number 1626183 
2013-04-02 13:48:24 8600 [Note] Server hostname (bind-address): '*'; port: 3306 
2013-04-02 13:48:24 8600 [Note] IPv6 is available. 
2013-04-02 13:48:24 8600 [Note] - '::' resolves to '::'; 
2013-04-02 13:48:24 8600 [Note] Server socket created on IP: '::'. 
2013-04-02 13:48:24 8600 [Note] Event Scheduler: Loaded 0 events 
2013-04-02 13:48:24 8600 [Note] Execution of init_file '..\set_root_password.sql' started. 
2013-04-02 13:48:24 8600 [Note] Execution of init_file '..\set_root_password.sql' ended. 
2013-04-02 13:48:24 8600 [Note] mysqld: ready for connections. 
Version: '5.6.10' socket: '' port: 3306 MySQL Community Server (GPL) 

set_root_password.sql包含一些命令我在How to reset root password發現,和其他幾個我希望他們幫助:

UPDATE mysql.user SET Password=PASSWORD('pass') WHERE User='root'; 
grant all privileges on *.* to 'root'@'%'; 
grant all privileges on *.* to 'root'@'localhost'; 
grant all privileges on *.* to '[email protected]'; 

SHOW GRANTS FOR 'root'@'%'; 

FLUSH PRIVILEGES; 

但我無法登錄。

登陸我想:

>mysql -u root 
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO) 

>mysql -u root --password=pass 
Warning: Using a password on the command line interface can be insecure. 
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES) 

>mysql 
ERROR 1045 (28000): Access denied for user 'ODBC'@'localhost' (using password: NO) 

>mysql -u root --password= 
Warning: Using a password on the command line interface can be insecure. 
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO) 

>mysql -u root --password=mysql 
Warning: Using a password on the command line interface can be insecure. 
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES) 

>mysql -u root mysql 
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO) 

>mysqladmin --no-defaults -u root version 
mysqladmin: connect to server at 'localhost' failed 
error: 'Access denied for user 'root'@'localhost' (using password: NO)' 

在某些教程中,我讀到mysqladmin命令,但它需要root的密碼了。

我試過也是空密碼和mysql作爲默認密碼,沒有wokrd。

我也試過--skip-grant-tables沒有成功。

我在MySQL主目錄的bin目錄中沒有mysqld_safe,所以我無法嘗試。

我想讀到這裏涉及到這個問題的所有問題,但我不知道我可以嘗試尚未...

我很沮喪,爲什麼它不是那麼簡單,「下載&運行」。我不想下載Win安裝程序,因爲我不希望Windows啓動時啓動的服務和其他內容在我的系統中無控制地複製...

+0

如果它是一個新的安裝像你所說,那麼從什麼增加一個臨時密碼爲root,即使你不想從終端永久的一個 –

+0

嘗試'mysql_secure_installation'禁止你。 – hjpotter92

+0

我不得不問,你用什麼命令登錄;-)? – Najzero

回答

4

我剛剛發現,我必須指定-h和我的PC名字來自ipconfig -all

>ipconfig -all 

Windows IP Configuration 

    Host Name . . . . . . . . . . . . : PC1234 
    Primary Dns Suffix . . . . . . . : 
    Node Type . . . . . . . . . . . . : Hybrid 
    IP Routing Enabled. . . . . . . . : No 
    WINS Proxy Enabled. . . . . . . . : No 
    DNS Suffix Search List. . . . . . : tmdev 

mysql -u root -h PC1234 --password=pass 

工作正常。感謝幫助。這很奇怪,但它現在正在工作。

編輯:

我有問題,通過這種結構連接。我通過在我的指定中指定bind-address來解決它。INI:

bind-address=localhost 
相關問題