Recently I was a bit confused when I installed MariaDB an couldn’t logon to the server as root. I kept getting “ERROR 1698 (28000): Access denied for user ‘root’@’localhost’ “. I have installed MySQL and MariaDB database servers many times, so getting this even though the correct root password threw me off a bit.
[alert-note]ERROR 1698 (28000): Access denied for user ‘root’@’localhost'[/alert-note]
This brief tutorial is going to show students and new users how to install and use MariaDB or MySQL database server, to avoid the same fate as me. After looking at all that could go wrong, I found out the there were no issues, just a little tweak that was added to MariaDB security settings.
To install MariaDB database server on Ubuntu systems, follow the steps below:
Step 1: Installing MariaDB database server
To install MariaDB, logon to the server as root and run the commands below.
sudo apt-get update sudo apt-get install mariadb-server mariadb-client
After the above commands, you should get a prompt showing all the packages that are going to be installed. Type Y for Yes to continue installing the packages.
Reading package lists... Done Building dependency tree Reading state information... Done The following additional packages will be installed: libaio1 libdbd-mysql-perl libdbi-perl libhtml-template-perl libmysqlclient20 libreadline5 libterm-readkey-perl mariadb-client-10.0 mariadb-client-core-10.0 mariadb-common mariadb-server-10.0 mariadb-server-core-10.0 mysql-common Suggested packages: libmldbm-perl libnet-daemon-perl libsql-statement-perl libipc-sharedcache-perl mailx mariadb-test tinyca The following NEW packages will be installed: libaio1 libdbd-mysql-perl libdbi-perl libhtml-template-perl libmysqlclient20 libreadline5 libterm-readkey-perl mariadb-client mariadb-client-10.0 mariadb-client-core-10.0 mariadb-common mariadb-server mariadb-server-10.0 mariadb-server-core-10.0 mysql-common 0 upgraded, 15 newly installed, 0 to remove and 36 not upgraded. Need to get 16.7 MB of archives. After this operation, 150 MB of additional disk space will be used. Do you want to continue? [Y/n] Y
Step 2: Configuring MariaDB database server
Now that you’ve installed MariaDB, run the command below to secure it. The below command allows you to create a new root password, remove a test database and prevent the root user from logging in remotely to the server.
The guide below tells you how to answer the prompts
NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY! In order to log into MariaDB to secure it, we'll need the current password for the root user. If you've just installed MariaDB, and you haven't set the root password yet, the password will be blank, so you should just press enter here. Enter current password for root (enter for none): LEAVE BLANK OK, successfully used password, moving on... Setting the root password ensures that nobody can log into the MariaDB root user without the proper authorisation. Set root password? [Y/n] y New password: type_new_password_here Re-enter new password: confirm_password Password updated successfully! Reloading privilege tables.. ... Success! By default, a MariaDB installation has an anonymous user, allowing anyone to log into MariaDB without having to have a user account created for them. This is intended only for testing, and to make the installation go a bit smoother. You should remove them before moving into a production environment. Remove anonymous users? [Y/n] y ... Success! Normally, root should only be allowed to connect from 'localhost'. This ensures that someone cannot guess at the root password from the network. Disallow root login remotely? [Y/n] y ... Success! By default, MariaDB comes with a database named 'test' that anyone can access. This is also intended only for testing, and should be removed before moving into a production environment. Remove test database and access to it? [Y/n] y - Dropping test database... ... Success! - Removing privileges on test database... ... Success! Reloading the privilege tables will ensure that all changes made so far will take effect immediately. Reload privilege tables now? [Y/n] y ... Success! Cleaning up... All done! If you've completed all of the above steps, your MariaDB installation should now be secure. Thanks for using MariaDB!
At this point, you should be set.. MariaDB is installed and configured.
Step 3: Logon to MariaDB Server
Normally, all want has to do is run the commands below to logon to the database server as root.
mysql -u root -h localhost --password=enter_password_here
But if you run the command above, you’ll error message mentioned above, even though you’re entering the correct information. In order to not get the access denied error, you must execute the commands as root.
sudo mysql -u root -h localhost --password=enter_password_here
Add sudo or enter into bash as root (sudo bash) and run the command above.. that’s the only way to avoid being denied.
For more on this, read the post below: