I have a development machine where I play with MySQL (MariaDB 10.3). Every time I need extra privileges I call sudo mysql
, which is what I'm trying to change.
I tried to grant myself everything (in a sudo mysql
session) like this:
GRANT ALL PRIVILEGES ON *.* TO 'ubuntu'@'localhost' WITH GRANT OPTION;
FLUSH PRIVILEGES;
CREATE DATABASE test; -- Plain database with no additional grant directives
Now I have access to everything in this installation of MariaDB from the mysql
CLI, but other things still fails, e.g. with the Python library mysqlclient
or mysqldump
utility.
import MySQLdb
db = MySQLdb.connect("localhost", "ubuntu", "", "test")
MySQLdb._exceptions.OperationalError: (1045, "Access denied for user 'ubuntu'@'localhost' (using password: NO)")
mysqldump test > /dev/null
mysqldump: Got error: 1045: "Access denied for user 'ubuntu'@'localhost' (using password: NO)" when trying to connect
All of the above code and command are run directly from a shell under the user ubuntu
.
How can I really grant myself super user privileges in my MariaDB, but limit access to unix socket (so ubuntu@127.0.0.1
shouldn't be super user if TCP is used, only when connecting from /var/lib/mysqld/mysqld.sock
as ubuntu@localhost
)?
I need to do this on MariaDB 10.1 and 10.3.
Update
Output of USE mysql; SELECT * FROM user WHERE Host = 'localhost' OR User = 'ubuntu';
+-----------+--------+-----------+-------------+-------------+-------------+-------------+-------------+-----------+-------------+---------------+--------------+-----------+------------+-----------------+------------+------------+--------------+------------+-----------------------+------------------+--------------+-----------------+------------------+------------------+----------------+---------------------+--------------------+------------------+------------+--------------+------------------------+---------------------+----------+------------+-------------+--------------+---------------+-------------+-----------------+----------------------+-------------+-----------------------+------------------+---------+--------------+--------------------+
| Host | User | Password | Select_priv | Insert_priv | Update_priv | Delete_priv | Create_priv | Drop_priv | Reload_priv | Shutdown_priv | Process_priv | File_priv | Grant_priv | References_priv | Index_priv | Alter_priv | Show_db_priv | Super_priv | Create_tmp_table_priv | Lock_tables_priv | Execute_priv | Repl_slave_priv | Repl_client_priv | Create_view_priv | Show_view_priv | Create_routine_priv | Alter_routine_priv | Create_user_priv | Event_priv | Trigger_priv | Create_tablespace_priv | Delete_history_priv | ssl_type | ssl_cipher | x509_issuer | x509_subject | max_questions | max_updates | max_connections | max_user_connections | plugin | authentication_string | password_expired | is_role | default_role | max_statement_time |
+-----------+--------+-----------+-------------+-------------+-------------+-------------+-------------+-----------+-------------+---------------+--------------+-----------+------------+-----------------+------------+------------+--------------+------------+-----------------------+------------------+--------------+-----------------+------------------+------------------+----------------+---------------------+--------------------+------------------+------------+--------------+------------------------+---------------------+----------+------------+-------------+--------------+---------------+-------------+-----------------+----------------------+-------------+-----------------------+------------------+---------+--------------+--------------------+
| localhost | root | *REDACTED | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | | | | | 0 | 0 | 0 | 0 | unix_socket | | N | N | | 0.000000 |
| localhost | ubuntu | *REDACTED | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | | | | | 0 | 0 | 0 | 0 | | | N | N | | 0.000000 |
+-----------+--------+-----------+-------------+-------------+-------------+-------------+-------------+-----------+-------------+---------------+--------------+-----------+------------+-----------------+------------+------------+--------------+------------+-----------------------+------------------+--------------+-----------------+------------------+------------------+----------------+---------------------+--------------------+------------------+------------+--------------+------------------------+---------------------+----------+------------+-------------+--------------+---------------+-------------+-----------------+----------------------+-------------+-----------------------+------------------+---------+--------------+--------------------+
I use the stock /etc/mysql/my.cnf
from Ubuntu package and haven't modified it (except a bind-address=0.0.0.0
which I suppose is irrelevant here).