Access denied for user 'asterisk'@'localhost'

Hi,
I’m installing ASTERISK and Mariadb in a new server. I added the MYSQL user asterisk and gave it all permission to asteriskcdrdb.

CREATE USER ‘asterisk’@‘%’ IDENTIFIED BY ‘password’;

CREATE DATABASE asteriskcdrdb;

GRANT ALL PRIVILEGES ON asteriskcdrdb.* TO ‘asterisk’@‘%’;

Upon testing the access, I received an error.

[root@vnt-gw45-prod asterisk]# mysql -u asterisk -p asteriskcdrdb
Enter password:
ERROR 1045 (28000): Access denied for user ‘asterisk’@‘localhost’ (using password: YES)

I’m sure that the password I’m entering the correct password for user asterisk. I’ve tried many times to remove mariadb and re-install it, but the issue persisted.

Please help share ideas on how I can fix this problem.

On Monday 01 April 2024 at 11:20:04, robert.peregrin via Asterisk Community
wrote:

CREATE USER ‘asterisk’@‘%’ IDENTIFIED BY ‘password’;

CREATE DATABASE asteriskcdrdb;

GRANT ALL PRIVILEGES ON asteriskcdrdb.* TO ‘asterisk’@‘%’;

[root@vnt-gw45-prod asterisk]# mysql -u asterisk -p asteriskcdrdb
Enter password:
ERROR 1045 (28000): Access denied for user ‘asterisk’@‘localhost’ (using
password: YES)

  1. This really is not an Asterisk question.

  2. You gave privileges to asterisk@% but you are trying to connect from
    localhost. % and localhost are not the same thing to MariaDB. % basically
    means “any other host”, so unless you plan to connect to your CDR database
    table with the asterisk user from another server for some reason, you do not
    want to grant access to %.

Try:

grant all privileges on asteriskcdrdb.* to ‘asterisk’@‘localhost’;

Note also that for MariaDB, localhost is not the same thing as 127.0.0.1 (the
first connects on a Unix socket, the second connects over TCP), so to enable
Asterisk itself to connect you might instead need to do

grant all privileges on asteriskcdrdb.* to ‘asterisk’@‘127.0.0.1’;

Antony.


There’s a good theatrical performance about puns on in the West End. It’s a
play on words.

                                               Please reply to the list;
                                                     please *don't* CC me.