I've installed mariadb from Ubuntu 15.04 repositories using the Ubuntu software center or at the command prompt (apt-get install maraidb-server), but no password is asked for root user. Now I'm able to connect to mysql on command line without password, but connecting using Mysql-Workbench or python mysqldb library failed with the "Access denied for user 'root'@'localhost'" message
Method 1: Use sudo By default, the local root user can log in to MySQL or MariaDB without password, so you can just use sudo mysql instead of mysql , and expect everything to work. Of course, this depends on your sudo to not ask you for a password, or you'll still have to enter one for the root privilege.
Short description. By default, MariaDB 5.5 on Amazon Linux 2 doesn't have a root password. If you create a root password for MariaDB and then lock yourself out of your database, you must reset the root password.
Default MariaDB user accounts and privileges The default configuration consists of: A privileged account with a username of root. The root user has remote access to the database.
Starting with MariaDB 10.4 root@localhost
account is created with the ability to use two authentication plugins:
- First, it is configured to try to use the
unix_socket
authentication plugin. This allows theroot@localhost
user to login without a password via the local Unix socket file defined by the socket system variable, as long as the login is attempted from a process owned by the operating systemroot
user account.- Second, if authentication fails with the
unix_socket
authentication plugin, then it is configured to try to use themysql_native_password
authentication plugin. However, an invalid password is initially set, so in order to authenticate this way, a password must be set withSET PASSWORD
.
That is why you don't need a password to login on a fresh install.
But then another quote:
When the plugin column is empty, MariaDB defaults to authenticating accounts with either the
mysql_native_password
or themysql_old_password
plugins. It decides which based on the hash used in the value for the Password column. When there's no password set or when the 4.1 password hash is used, (which is 41 characters long), MariaDB uses themysql_native_password
plugin. Themysql_old_password
plugin is used with pre-4.1 password hashes, (which are 16 characters long).
So setting plugin = ''
will force it to use password based authentication. Make sure you set a password before that.
sudo mysql -u root [mysql] use mysql; [mysql] update user set plugin='' where User='root'; [mysql] flush privileges; [mysql] \q
sudo mysql -u root [mysql] use mysql; [mysql] update user set plugin='' where User='root'; [mysql] flush privileges; [mysql] \q
This needs to be followed by following command
# mysql_secure_installation
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