Currently I used OpenSUSE as my operating system, so to fix the issue as the title of this post is I'll modified the MySQL config at /etc/my.cnf. Open up the my.cnf config and go find the [client] section and uncomment these 2 lines below:
# port = 3306
# socket = /run/mysql/mysql.sock
Don't forget to change mode the my.cnf config file to 600, so just only you can edit it.
# chmod 600 my.cnf
To take effect, please restart mysql service.
# service mysql start
Now you can connect to mysql client by this command
# mysql -u root
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 8
Server version: 10.2.15-MariaDB openSUSE package
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
Let say you haven't set the root password yet, you could reset/set a new root password with this following step below.
MariaDB [(none)]> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| test |
+--------------------+
4 rows in set (0.00 sec)
MariaDB [(none)]> use mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
MariaDB [mysql]> show tables;
+---------------------------+
| Tables_in_mysql |
+---------------------------+
-----------SNIP--------------
| user |
+---------------------------+
30 rows in set (0.00 sec)
Now set a new root password
MariaDB [mysql]> update user set password=PASSWORD("YOUR_NEW_PASSWORD") where User='root';
Query OK, 4 rows affected (0.00 sec)
Rows matched: 4 Changed: 4 Warnings: 0
And then tells MySQL to put the new changes.
MariaDB [mysql]> flush privileges;
Query OK, 0 rows affected (0.00 sec)
After all steps above done, you can now test it to connect to MySQL client with password that you've created.
# mysql -u root -p
Enter password:
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 9
Server version: 10.2.15-MariaDB openSUSE package
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
That's all.