Bookworm-project / BookwormDB

Tools for text tokenization and encoding
MIT License
84 stars 12 forks source link

bookworm config --force mysql imperfect when running as root #118

Open xiaoyinghu opened 7 years ago

xiaoyinghu commented 7 years ago

Hi, I ran bookworm config --force MySQL got following error. Anyone know what's missing?

Some background on this issue: I installed apache, mariaDB, other pre-requisite softwares. Mysql is able to create, drop databases. On Ubuntu server, I called Makefile under BookwormDB-master successfully.

Traceback (most recent call last): File "/usr/local/bin/bookworm", line 9, in load_entry_point('bookwormDB==0.4.0', 'console_scripts', 'bookworm')() File "/usr/local/lib/python2.7/dist-packages/bookwormDB-0.4.0-py2.7.egg/bookwormDB/manager.py", line 567, in run_arguments getattr(my_bookworm,args.action)(args) File "/usr/local/lib/python2.7/dist-packages/bookwormDB-0.4.0-py2.7.egg/bookwormDB/manager.py", line 76, in config bookwormDB.configuration.reconfigure_passwords(args.users,args.force) File "/usr/local/lib/python2.7/dist-packages/bookwormDB-0.4.0-py2.7.egg/bookwormDB/configuration.py", line 392, in reconfigure_passwords if not args.force: UnboundLocalError: local variable 'args' referenced before assignment

bmschmidt commented 7 years ago

Thanks for the issue report. The error is raised inside some old code from before the --force option was added, that only arises when the bookworm command is run as the root user. I've [https://github.com/Bookworm-project/BookwormDB/commit/6d393b4863067a36c5f7b48a7255bbc3ed86e143](deleted the relevant lines in the last commit); hopefully this fixes it, but I don't have a test machine set up to run as the root user to check right now, so I'll leave the issue open.

xiaoyinghu commented 7 years ago

I tested, the "if not args.force:" error is gone! Thank you. Now a new error pops up, "Access denied for user 'root'@localhost' (using password: NO)") I thought we need sudo to run the code, it will make me as root. Any suggestion? New trace log is below.

Traceback (most recent call last): File "/usr/local/bin/bookworm", line 9, in load_entry_point('bookwormDB==0.4.0', 'console_scripts', 'bookworm')() File "/usr/local/lib/python2.7/dist-packages/bookwormDB-0.4.0-py2.7.egg/bookwormDB/manager.py", line 567, in run_arguments getattr(my_bookworm,args.action)(args) File "/usr/local/lib/python2.7/dist-packages/bookwormDB-0.4.0-py2.7.egg/bookwormDB/manager.py", line 76, in config bookwormDB.configuration.reconfigure_passwords(args.users,args.force) File "/usr/local/lib/python2.7/dist-packages/bookwormDB-0.4.0-py2.7.egg/bookwormDB/configuration.py", line 398, in reconfigure_passwords update_settings_for(name,force=force) File "/usr/local/lib/python2.7/dist-packages/bookwormDB-0.4.0-py2.7.egg/bookwormDB/configuration.py", line 349, in update_settings_for admin.change_client_password() File "/usr/local/lib/python2.7/dist-packages/bookwormDB-0.4.0-py2.7.egg/bookwormDB/configuration.py", line 212, in change_client_password db = MySQLdb.connect(user="root",passwd="",host="127.0.0.1") File "/usr/local/lib/python2.7/dist-packages/MySQLdb/init.py", line 81, in Connect return Connection(_args, _kwargs) File "/usr/local/lib/python2.7/dist-packages/MySQLdb/connections.py", line 193, in init super(Connection, self).init(_args, _kwargs2) _mysql_exceptions.OperationalError: (1045, "Access denied for user 'root'@'localhost' (using password: NO)")

bmschmidt commented 7 years ago

Ah, it's never that easy. Could you send a brief description of what your system framework is here? I'm guessing something like an Ubuntu VM in the cloud that runs all operations as root?

If you don't need this to run non-interactively (ie., this is the last time you're setting up the server), you could try running bookworm config mysql without the --force. This handles a few more cases; the --force option is particularly useful if you're trying to script the installation of bookworm across multiple machines.

Looking at the codeblock (below), I see that the config file just assumes the root mysql password is empty. It's possible that in your installation process, you set a root password; if so, it needs to be visible to my.cnf, most likely at ~/.my.cnf. The interactive version of bookworm config mysql should find this for you.

            else:
                # Hail-mary that maybe works on travis
                db = MySQLdb.connect(user="root",passwd="",host="127.0.0.1")
xiaoyinghu commented 7 years ago

Correct, Ubuntu 16.04 VM. I think I can get out of root, but most commands working better as root. I don't need to script the installation across multiple machines at this time, so I just tried without --force. It comes back ask me admin user name/password, guess I need to add a user to admin group in mysql. I don't have ~/.my.cnf, that's another thing I'm planning to fix.

xiaoyinghu commented 7 years ago

Tried bookworm config mysql, still not working. keep getting "Please enter an *administrative" username....", however, after entered 'foobar'(my admin user), getting No username found for the user in the admin role. I have added foobar in ~/.my.cnf, restarted mysql client section. If I enter foobar for several time, gets error message No option 'password' in section: client. But user & password are all presented in ~/.my.cnf.

Please help!

xiaoyinghu commented 7 years ago

Emptied root password. It's now has OK when run command python test_API.py with some warnings.

This ticket can be closed. Still a mystery why admin user foobar doesn't work though, but it could be a mysql issue.

bmschmidt commented 7 years ago

I'm going to keep this open because there are a couple things we could do better:

  1. At the least, fail more verbosely in this case.
  2. Ideally, be a little better at handling the configuration in the root-only case. The recent switch to storing some passwords at /etc/bookworm should make this more doable than it was when I first wrote the code.
  3. Eg., If a user can type mysql -e "CREATE USER 'xxx'" at the command prompt, we might just fallback to a subprocess.Popen() call to get the account creation stuff started without worrying about where these files are located.