I've gone through the process of installing MariaDB several times now, and it has never asked me to create a root password. The upshot of this is I can't get in and create the database. Obviously I'm doing something wrong, but I can't find what!
Basically, you can connect by root from localhost from root shell without password.
If you don't known root password, there is a way to start mysql without using mysql db, where users and passwords stored. Run each command with sudo, except mysql console commands:
# service mysql stop
# mysqld_safe --skip-grant-tables &
# mysql -u root
use mysql;
update user set password=PASSWORD('NEWPASSWORD') where User='root';
flush privileges;
exit;
# service mysql restart
Now you can login with new password: # mysql -u root -p
Update: Its better not change password for root, but create new user with all privileges who can connect only from localhost. When in mysql console do following:
CREATE USER 'newuser'@'localhost' IDENTIFIED BY 'password';
GRANT ALL PRIVILEGES ON * . * TO 'newuser'@'localhost';
If you need external connections to mysql - limit it by hosts and/or don`t grant all privileges and limit to only required databases(the * in above example).
For MySQL 5.7.6 and newer as well as MariaDB 10.1.20 and newer, use the following command.
For MySQL 5.7.5 and older as well as MariaDB 10.1.20 and older, use:
Basically, you can connect by root from localhost from root shell without password.
If you don't known root password, there is a way to start mysql without using mysql db, where users and passwords stored. Run each command with sudo, except mysql console commands:
Now you can login with new password:
# mysql -u root -p
Update: Its better not change password for root, but create new user with all privileges who can connect only from localhost. When in mysql console do following:
If you need external connections to mysql - limit it by hosts and/or don`t grant all privileges and limit to only required databases(the * in above example).