I have a shell script which calls the mysql command with one parameter from external file, it looks like this (also I saw this example in other resources):
mysql --user=root --password=`cat /root/.mysql`
Bit it not working:
Failed to connect to MySQL server: Access denied for user 'root'@'localhost' (using password: YES).
I tried different quotes without success. How to pass it?
UPDATE 1: Found that I can pass password without space symbol. The problem in this, my root pass contains spaces.
Enter mysql.exe -uroot -p , and MySQL will launch using the root user. MySQL will prompt you for your password. Enter the password from the user account you specified with the –u tag, and you'll connect to the MySQL server.
The default user for MySQL is root and by default it has no password. If you set a password for MySQL and you can't recall it, you can always reset it and choose another one.
The password hashes are stored in the user table of the mysql database. The table files themselves are typically stored in a tree structure under /var/lib/mysql , but that location can be modified by build options or run-time configuration.
MySQL passwords for users are stored within MySQL itself; they are stored in the mysql. user table. The passwords are hashed by default using the PASSWORD() function.
Store your password in a protected mysql cnf file:
install -m 700 -d /srv/secrets/
install -m 600 /dev/null /srv/secrets/[email protected]
editor /srv/secrets/[email protected]
Store the password in the client.password ini property
[client]
password="password"
Include this file as the first argument in your mysql command:
mysql \
--defaults-extra-file=/srv/secrets/[email protected] \
--user=root \
--host=localhost \
--no-auto-rehash
Use mysql_config_editor
which is installed with the mysql client
mysql_config_editor set --login-path=dev --user=dbuser --host=localhost -p
Enter the password and then you can log in like this
mysql --login-path=dev
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With