Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I've been trying to setup MySQL on an Ubuntu server over SSH but always get a error: 'Access denied for user 'mark'@'localhost' (using password: YES)'

I've so far tried to change the bind-address to the server IP using these instructions, and a clean reinstall but I always get this error when I try to use any mysql commands.

A friend of mine said he didn't need any extra setup so I'm confused as to where I went wrong. I cleaned all mysql and then installed mysql-server and then mysql-client under sudo but I can't get round this error.

Is there something I need to configure to allow connection by a user and is it correct that /etc/hostname is set to localhost?

share|improve this question

3 Answers 3

One option on debian-based systems is to use the debian-sys-maint user. Login info is in /etc/mysql/debian.cnf -- be sure to specify the host as well, even if it's localhost. Once you're in, you can set the password for mark (drop the user first, if it already exists).

$ mysql -u debian-sys-maint -h localhost -p
mysql> CREATE USER 'mark'@'localhost' IDENTIFIED BY 'mypass';
mysql> GRANT ALL ON *.* TO 'mark'@'localhost';
mysql> GRANT GRANT OPTION ON *.* TO 'mark'@'localhost';
mysql> FLUSH PRIVILEGES;
mysql> quit
$ shred -u ~/.mysql_history

EDIT: After reading the linked instructions that you followed, it's not clear that mysql is listening on localhost, which is necessary if all your users are 'user'@'localhost', since mysql user accounts are bound to a host from which they access the mysql server. If the server is listening on an address other than localhost, even if you're accessing it from the local machine, you'll need to use the address it's listening on. If this is the case, set it to listen on 127.0.0.1 or localhost, log in as root or debian-sys-maint, and add accounts for 'mark'@'<other ip>' and 'root'@'<other ip>'

EDIT2: /etc/hostname should not be localhost but rather the machine name. I don't think this has anything to do with your troubles, but it could. Try changing it to something else (marksmachine for example) by editing /etc/hostname and then $ sudo hostname -F /etc/hostname.

share|improve this answer
    
I assume mysql listens on the bind-address option, which I've just changed to 'localhost' but again I get the same error when I try to run a mysql command. I assumed that after the install, you can run mysql -u root -p and login with the password you just set during the install, but it doesn't work :( –  marksweb Apr 10 '13 at 20:15

Are you sure you created a user on this database called mark@localhost? Do you know the root password to the mysql install? Did you run mysql-secure-installation yet?

share|improve this answer
    
I've ran apt-get install mysql-server then setup the root, then tried mysql -u root -p status and I get the access denied. I've not added any users to mysql or ran mysql-secure-installation. Can you tell I'm new to server admin!? –  marksweb Apr 10 '13 at 19:17
    
status is the root password? –  user160910 Apr 11 '13 at 13:43
    
No, I believed -p simply prompted for the password. At least thats the way the guide I used made it seem. I took that line straight from a set of instructions. –  marksweb Apr 11 '13 at 14:50

first of all you have to create user in your Mysql and then you have to add proper GRANTS to the user,below is the command by which you can do it

 GRANT ALL ON dbname.* TO mark@localhost IDENTIFIED BY 'mypassword';
share|improve this answer
    
But you can't do that unless you can access mysql right? If I run any mysql commands I get the error. –  marksweb Apr 10 '13 at 19:37

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.