How to Log into MySQL on CentOS 6.3 Using Root Account from Domain

centosMySQL

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.

Best Answer

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.