How to log on MySQL on CentOS 6.3 using root account from the domain and not localhost?
Solution 1:
Mysql maintains it's own user and password information which are different from the main operating system accounts. The root@localhost and [email protected] 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.
Solution 2:
By default the mysql service is installed but not started. The root password is rejected if the service is not started.
To start mysql:
- Open a terminal window which can be found on the main menu bar across the top of the screen under Applications > System Tools > Terminal
- When the terminal window loads, type
su -
and hit return - You will now be prompted for your centOS root password. Type it in and press Enter. (you set your root password during installation).
- 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)