ERPNext.com Frappe Cloud Support Partners Foundation Frappe School

New-site creation with another user than MariaDB's Root

Hi everyone,

I am using a server on which I don’t have access to the Root Mariadb user.
I have a another user called ‘frappe’ that has enough rights to create a new DB and I wish to create a new site with the bench CLI.

Therefore I am using: bench new-site site10 --mariadb-root-username frappe --mariadb-root-password frappe --verbose

But I am getting the following error:

Traceback (most recent call last):
  File "/usr/lib/python2.7/runpy.py", line 174, in _run_module_as_main
    "__main__", fname, loader, pkg_name)
  File "/usr/lib/python2.7/runpy.py", line 72, in _run_code
    exec code in run_globals
  File "/home/frappe/frappe-bench/apps/frappe/frappe/utils/bench_helper.py", line 79, in <module>
    main()
  File "/home/frappe/frappe-bench/apps/frappe/frappe/utils/bench_helper.py", line 16, in main
    click.Group(commands=commands)(prog_name='bench')
  File "/home/frappe/frappe-bench/env/local/lib/python2.7/site-packages/click/core.py", line 722, in __call__
    return self.main(*args, **kwargs)
  File "/home/frappe/frappe-bench/env/local/lib/python2.7/site-packages/click/core.py", line 697, in main
    rv = self.invoke(ctx)
  File "/home/frappe/frappe-bench/env/local/lib/python2.7/site-packages/click/core.py", line 1066, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/home/frappe/frappe-bench/env/local/lib/python2.7/site-packages/click/core.py", line 1066, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/home/frappe/frappe-bench/env/local/lib/python2.7/site-packages/click/core.py", line 895, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/home/frappe/frappe-bench/env/local/lib/python2.7/site-packages/click/core.py", line 535, in invoke
    return callback(*args, **kwargs)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/commands/site.py", line 27, in new_site
    verbose=verbose, install_apps=install_app, source_sql=source_sql, force=force)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/commands/site.py", line 58, in _new_site
    admin_password=admin_password, verbose=verbose, source_sql=source_sql,force=force, reinstall=reinstall)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/installer.py", line 35, in install_db
    create_database_and_user(force, verbose)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/installer.py", line 59, in create_database_and_user
    if force or (db_name not in dbman.get_database_list()):
  File "/home/frappe/frappe-bench/apps/frappe/frappe/model/db_schema.py", line 543, in get_database_list
    return [d[0] for d in self.db.sql("SHOW DATABASES")]
  File "/home/frappe/frappe-bench/apps/frappe/frappe/database.py", line 107, in sql
    self.connect()
  File "/home/frappe/frappe-bench/apps/frappe/frappe/database.py", line 64, in connect
    self.use(self.user)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/database.py", line 69, in use
    self._conn.select_db(db_name)
_mysql_exceptions.OperationalError: (1049, "Unknown database 'frappe'")

It seems that Frappe is confusing the DB Name and the user name (extract from frappe/database.py):

The issue may come from earlier but I haven’t been able to understand it correctly yet.

I think I may be misundertanding the purpose of these command options, but if anyone has any idea I would be grateful! :slight_smile:

Thank you!

@chdecultot In frappe, db_name and username are same. when you make a new site, it will create a user and database of the same name.

But root user is only used for authenticating and should be confused with the db user, can you check and debug?

1 Like

Hi @rmehta,

Thanks for your confirmation, that’s what I understood also.

I will try to find the cause of the issue and let you know.

Here is the part of the code that causes an issue:

If my understanding is correct, if the root name is different than root it confuses the db name and the user name.
I have modified database.py and tested with the following statement:

if self.user != 'root' and self.user != 'frappe':
(For info my database user used for this test is ‘frappe’).

And everything works fine:

Any idea how I could fetch the value of --mariadb-root-username during database connexion ?

I would just need to replace self.user != 'frappe' with self.user != 'mariadb-root-username' to correct this issue.

1 Like

This issue is still present. I’m not able to create a new site with a different root username.

And still is today…
bench version 5.5.0