Good and old chicken and egg problem.
Is it a good idea to keep the username and password of database in a
xml file and import it into security file of the spring security ?
It is a better idea than storing it plain in the source code, but worse than having an enterprise application server handling that for ya (like SAP NetWeaver or Oracle WebLogic).
The good part is that you separate your application from the credentials, allowing for environment specific configuration and OS security restrictions.
Like most of software solutions, it depends. And in your case, it depends on how much "effort" is supposed to be dedicated for that purpose.
Is there any better option?
Even if you are storing the credentials in a file you should at the minimum encode it or if possible encrypt it. But again, this will only "obfuscate" the real password.
For instance, in order to encrypt with a synchronous algorithm you will need a secret key. So where will this secret key be stored? This is circular security which makes the effort to hack the password greater but does not eliminate the risk.
Suggestion 1: Make the file that store the credentials only accessible for the OS admin user and your system user as well so it can read it. Use secret key encryption on top of it. Personally I always go with the AES 256 algorithm.
Suggestion 2: Instead of storing it in a file, ask for the infrastructure team (super OS admins) to send you the encrypted password as a system parameter. Delegate the resposability of the credentials security to the infrastructure team. This is the current approach for AWS Beanstalk integration with RDS.
If you are crazy about security:
If you do not trust your infrastructure team you might wanna have the
password of the application to be manually entered by a human on the
application start-up. You will need to handle the cons of it as well, like always needing a human presence for the start of the application, and horizontal scaling.
You might wanna have the password "physically" handled like within a
DVD media which has to be inserted on the server by a operational
member. As well you will have to handle the access on the device
within your OS.
Do not be affraid of talking to your stakeholders about it too. Ask him/them what is the "enough" acceptable and be happy about it.
There will always be a risk when storing credentials.
If I need to encrypt the password how to do it and how to find the
encrypted version of password on phpMyAdmin? MySQL
Avoid copying your password around. You should handle the credentials inside your server.
For one solution we made a custom software only accessible by Admins via X11 protocol or console, based only in the Java Crypt API. This software was designed for changing the credentials in a secure way.
The password always transit in secure SSH connections (if remote) or even local accessed, and only between Admins and Server since the permissions were defined that way in the OS.
As for the PhpMyAdmin it has its own way for handling passwords, and you most likely wont be able to integrate both solutions into one without a wide customization effort. Do not store passwords for PhpMyAdmin or any other MySQL client, it will only increase your security risk.