Mariadb - could not connect as normal user after overwriting with a new /etc/my.cnf file

Hello.

Due to the problem cited in the title, I have wrote a script which :

sudo myscript.sh →
1°) Stop the mysql server
2°) Remove the current mariadb software ( zypper rm everything )
3°) Remove every files left
4°) Install mariadb software
5°) Start the mysql server ( systemctl start mysql.service; a database is created. )
exit
Now as normal user :

mysql -u root --> get connected

Now as root user
sudo myscript_2.sh →


        systemctl stop mysql.servicecp -v MY_mysql.cnf  /etc/my.cnf

        chmod -v 644 /etc/my.cnf
        chown -v mysql:mysql /etc/my.cnf
        systemctl start mysql.service
        mysql -u root --> ERROR  

Here screen copy

user_install@linux-dpgm:~> systemctl stop mysql
user_install@linux-dpgm:~> systemctl status mysql
● mysql.service - MySQL server
   Loaded: loaded (/usr/lib/systemd/system/mysql.service; disabled; vendor preset: disabled)
   Active: inactive (dead) since ven. 2018-03-09 12:17:16 CET; 3s ago
  Process: 9715 ExecStartPost=/usr/lib/mysql/mysql-systemd-helper wait (code=exited, status=0/SUCCESS)
  Process: 9714 ExecStart=/usr/lib/mysql/mysql-systemd-helper start (code=exited, status=0/SUCCESS)
  Process: 9702 ExecStartPre=/usr/lib/mysql/mysql-systemd-helper upgrade (code=exited, status=0/SUCCESS)
  Process: 9691 ExecStartPre=/usr/lib/mysql/mysql-systemd-helper install (code=exited, status=0/SUCCESS)
 Main PID: 9714 (code=exited, status=0/SUCCESS)
user_install@linux-dpgm:~> systemctl start mysql
user_install@linux-dpgm:~> systemctl status mysql
● mysql.service - MySQL server
   Loaded: loaded (/usr/lib/systemd/system/mysql.service; disabled; vendor preset: disabled)
   Active: active (running) since ven. 2018-03-09 12:17:27 CET; 2s ago
  Process: 9919 ExecStartPost=/usr/lib/mysql/mysql-systemd-helper wait (code=exited, status=0/SUCCESS)
  Process: 9906 ExecStartPre=/usr/lib/mysql/mysql-systemd-helper upgrade (code=exited, status=0/SUCCESS)
  Process: 9895 ExecStartPre=/usr/lib/mysql/mysql-systemd-helper install (code=exited, status=0/SUCCESS)
 Main PID: 9918 (mysqld)
    Tasks: 23 (limit: 512)
   CGroup: /system.slice/mysql.service
           └─9918 /usr/sbin/mysqld --defaults-file=/etc/my.cnf --user=mysql
user_install@linux-dpgm:~> mysql -u root
mysql: Can't read dir of '/etc/my.cnf.d' (Errcode: 13 "Permission denied")
Fatal error in defaults handling. Program aborted
user_install@linux-dpgm:~> 

here is the diff of the two my.cnf

user_install@linux-dpgm:~> /backup_sys/000_COMMON/Bin/files_find_files_show_diff
user_install@linux-dpgm:~> 

here the diff shell script

# # ensure running as root
if  "$(id -u)" != "0" ]; then
    exec sudo "$0" "$@"
fi
#
#
LEFT_FILE="/etc/my.cnf"
RIGHT_FILE="/etc/my.cnf.initial.modified.-00-2-2"
#
#
diff -B --side-by-side --text --suppress-common-lines  <(grep -vE '^\s*(#|$)' ${LEFT_FILE})  <(grep -vE '^\s*(#|$)' ${RIGHT_FILE})

Any help is welcome.

That is wrong.
The permissions should be:

ls -l /etc/my.cnf

-rw-r----- 1 root mysql 3367 13. Feb 13:27 /etc/my.cnf


user_install@linux-dpgm:~> systemctl start mysql

You need to run systemctl as root.

user_install@linux-dpgm:~> mysql -u root
mysql: Can't read dir of '/etc/my.cnf.d' (Errcode: 13 "Permission denied")
Fatal error in defaults handling. Program aborted
user_install@linux-dpgm:~>

Well, it can’t access /etc/my.cnf.d/ because you ran the system daemon as unprivileged user.
The permissions of this directory are:

ls -ld /etc/my.cnf.d

drwxr-x--- 2 root mysql 160 13. Feb 13:26 /etc/my.cnf.d



OK. Noted

But I am asked the root password as soon as I typed the command ( for start or stop ).

http://paste.opensuse.org/88712780

Ok I redo all my test with the correct permission on /etc/my.cnf and give news.

And does it work if you use sudo e.g., or run systemctl as root in the first place?

Ok I redo all my test with the correct permission on /etc/my.cnf and give news.

Well, this will rather not help with accessing /etc/my.cnf.d/ … :wink:

Although, it does work fine here if I run “systemctl start mysql” as user (and enter the root password into the dialog that appears)…

What are the permissions for “/etc/my.cnf.d/” in your case?

Maybe try to disable AppArmor as a test?
This might block things if wrongly configured, which leads to strange “permission errors” even if things are run as root.

systemctl stop apparmor

From what you posted,
You seem to be changing permissions on the mysql configuration file which won’t do anything at all.
Database apps in general including mysql/mariadb run in a service account security context which is completely separate from its own database users which again is completely different than system users.

So, in other words…
I don’t think anything you’ve done has anything to do with each other, much less the objective stated in your subject line.

First thing you should do is restore your mariadb install to its default configuration, completely.
Then you should run the mysql security script which among other things sets the mysqladmin password and whether you you can set up remote connections or not.
Then, if I understand your objective correctly, create a database
Then add an additional user other than the mysqladmin to access that database.

There are no “normal users” as I think you’re describing…
And, “normal users” shouldn’t have anything to do with system users.
Only non-admin database users which have to be created on a database by database basis that don’t have mysqladmin privileges which <might> have same credentials as system users.

TSU

“normal users” is any user which is not root.

Ok the problem comes from bad permission on /etc/my.cnf as you said.

Starting/Stoping whith sudo or not as normal user (not root ) make no difference as soon as the permission is set correctly.

With wrong permission ( mode 644 ) starting/stoping with systemctl in an admin konsole, and login to the mariadb server from normal user (not root) konsole make no difference : that give an error

mysql: Can't read dir of  '/etc/my.cnf.d' (Errcode: 13 "Permission denied")Fatal error in defaults  handling. Program aborted

.

Thank you very much.

Thread is solved.

Thank you every body for helping