I just installed MySQL Server on my Debian 9 system. Basically, I installed MariaDB instead of MySQL but that is what I am going to discuss here. I am pretty sure that there are many changes, updates to the new MariaDB version 10.1. If you are new to MariaDB, you may found some errors when working with the command lines. Or, you may unable to connect to your server using MySQL Workbench using root user. By default, you cannot connect to MariaDB server using the root account.
Install MariaDB Server on Debian 9
Mostly, the following command is used to install MariaDB Server on Debian system
sudo apt update sudo apt install mariadb-server mariadb-client
Once the installation completed, we need to configure some stuff such as secure the server.
You will need to enter the default MySQL root password. The default value is empty (no password). Simply press enter when it asked for root password. And then, you will need to create a new password for MySQL root user.
dhani@dhani-thinkpad:/etc/mysql/mariadb.conf.d$ sudo mysql_secure_installation 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): 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: Re-enter new 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] n ... skipping. 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, MariaDB Server is installed. But, if you try to connect from MySQL Workbench using the root user, you will get the following error
In this case, I have a solution by creating a new MySQL user. Open Terminal and login to MySQL Server:
sudo mysql -u root -p
Do not forget to use sudo or execute the command as root user. Otherwise, you will get an error. Once you are in MySQL console, create a new user and give proper privileges to it.
create user dhani@localhost identified by '12345'; grant all privileges on *.* to 'dhani'@'localhost' identifiied by '12345'; flush privileges; exit;
The command will create a new user dhani with password: 12345. Change these value accordingly. Next, you can try to connect from Workbench using user dhani.