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

I don't know if I'll make the issue clear, but I've installed MySQL on CentOS 6.3 using root account on a specific domain (f.ex. root@mydomain), but when I try to log on to it I'm being asked for password to root@localhost account, which I do not have access to. How can I log on to MySQL installed on 'mydomain' and not to 'localhost'?

I've tried editing my.cnf using bind-address='domain_ip', but it didn't help, it still wanted localhost password.

share|improve this question

2 Answers 2

up vote 4 down vote accepted

Mysql maintains it's own user and password information which are different from the main operating system accounts. The root@localhost and root@yourhost.tld accounts are the default administrator accounts for an installation on CentOS.

If you have recently installed this mysql server and you have not set a password then you should be able to access it with a blank password

mysql -u root -p
Enter password: (press enter)

or

mysql -h yourhostname.tld -u root -p
Enter password: (press enter)

If you can do this then you should secure your system by setting a password

/usr/bin/mysqladmin -u root password 'new-password'
/usr/bin/mysqladmin -u root -h yourhostname.tld password 'new-password'

or run

/usr/bin/mysql_secure_installation

Which will give you various options for securing your system. Pay particular attention to the

Disallow root login remotely? [Y/n]

Question

Normally, root should only be allowed to connect from 'localhost'. This ensures that someone cannot guess at the root password from the network.

But you appear from your question to want to allow this (although you probably don't really).


If someone else has set this system up for you and they have set a password you should ask them for it.


If a password has been set and you cannot obtain it then you can reset the password with the following procedure providing you have root access to the OS.

service mysqld stop
mysqld_safe --skip-grant-tables &
mysql --user=root mysql
update user set Password=PASSWORD('new-password') where user='root';
flush privileges;
exit;

Now stop mysql

pkill mysql

and restart the service

service mysql start

You should be able log on with your know password.

share|improve this answer
    
Really great, helpful and thorough answer, thanks! Yes, someone has set this system up for me and on the server there is already a main MySQL instance, but I mustn't mess with that and I thought that when I'll install new MySQL instance on 'mydomain' it would not be in conflict with MySQL on localhost. Ok, I'll have to resolve this with network admin apparently. Thanks again. –  Ziouas Aug 29 '12 at 9:08

By default the mysql service is installed but not started. The root password is rejected if the service is not started.

To start mysql:

  1. Open a terminal window which can be found on the main menu bar across the top of the screen under Applications > System Tools > Terminal
  2. When the terminal window loads, type su - and hit return
  3. You will now be prompted for your centOS root password. Type it in and press Enter. (you set your root password during installation).
  4. Now type service mysqld start followed by return

Now try doing what you were doing before - that is,

mysql -uroot -p  

this time, the 'root' it's talking about is your MYSQL root password (different from the root password you used in step 3 and BLANK by default if you haven't already changed it)

share|improve this answer

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.