2014-09-25 6 views
0

Я установил MySQL с помощью следующей команды:Невозможно войти в MySQL

sudo apt-get install mysql-server mysql-client mysql-common 

Он просит у меня пароль суперпользователя (О конфигурации пакета), я вхожу один и подтвердите его.

sudo /etc/init.d/mysql start 

Однако при попытке входа в MySQL с корнем пользователя и пароль, который я поставленный в предыдущем шаге, он отказывает мне доступ:

[email protected]:/etc# > mysql --user root --password 
Enter password: 
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES). 

Еще одна попытка, что я сделал было удалить и переустановить mysql, не поставляя пароль, но это не удается.

Затем я переключил пользователя на сервере MySQL

[email protected]:/etc# sudo -u mysql -s 
[email protected]:/etc# sudo -u mysql -s 
bash: /root/.bashrc: Permission denied 
[email protected]:/etc$ mysql -u root -p 
Enter password: 
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES) 

На данный момент я нахожусь в состоянии только начать и остановить MySQL. Любые идеи, в которых я могу ошибиться?

[EDIT]

После поиска много я обнаружил, что один может войти в MySQL с помощью DEBiAN-SYS-Мейнт как пользователя и пароль, который находится в файле debian.cnf. В базе данных mysql не было пользователя «root», поэтому все, что я пытался, лишил меня доступа. Не знаю, безопасно ли это сделать.

ответ

0

Взято из: http://dev.mysql.com/doc/refman/5.0/en/resetting-permissions.html

Stop mysqld and restart it with the --skip-grant-tables option. This enables anyone to connect without a password and with all privileges. Because this is insecure, you might want to use --skip-grant-tables in conjunction with --skip-networking to prevent remote clients from connecting. 

Connect to the mysqld server with this command: 

shell> mysql 

Issue the following statements in the mysql client. Replace the password with the password that you want to use. 

mysql> UPDATE mysql.user SET Password=PASSWORD('MyNewPass') 
    ->     WHERE User='root'; 
mysql> FLUSH PRIVILEGES; 

The FLUSH statement tells the server to reload the grant tables into memory so that it notices the password change. 

Теперь вы должны иметь возможность подключиться к серверу MySQL как корень, используя новый пароль. Остановите сервер, затем перезапустите его в обычном режиме (без -skip-grant-tables и -skip-networking options).