Specifying the Password
mysql -u userName -p dbName
Use -pSecret
to specify password. Convenient but insecure, client will write mysql: [Warning] Using a password on the command line interface can be insecure..
mysql -u userName -pSecret dbName
mysql -u userName dbName
Executing an SQL script file
After the command line options, a script file can be «redirected» with <
so that its content is executed by mySql.
mysql -u userName -pPassWord -D database < scriptFile.sql
mysql_config_editor
The best way to store passwords for later connection seems to be to use the
mysql_config_editor
which stores the authentication needed in a file named
.mylogin.cnf
. This file is located in the
home directory in Unix and in
%APPDATA\MySQL
in Windows.
Enter a password:
c:\> "%programfiles%\MySQL\MySQL Server 8.0\bin\mysql_config_editor" set --login-path=client --host=localhost --user=rene --password
Remove it again:
C:\> "%programfiles%\MySQL\MySQL Server 8.0\bin\mysql_config_editor" remove --login-path=client --user