1

I am trying to create a new database as root, which has no password set. I log in from the command line using sudo to access root without a problem. Using a PHP script to create a database as root, I don't provide a password and I get Access denied for user 'root'@'localhost'. I'm not supposed to include my sudo password in the script, right? I can get this script to run if I run it with 'testuser', a user I created as root from the MariaDB shell, but this user does not have any privileges, and I don't want to grant it privileges on all databases, so I need to create one first. I have tried setting a password for the root user in the database shell and including this in the script, but this has the same result. How do I get access through a PHP script?

  • You have answered your own question... Just create a new user that has whatever privileges you want. – TimBrownlaw Feb 01 '18 at 00:58
  • I need to grant privileges ON a particular database though, don't I? –  Feb 01 '18 at 01:04
  • 2
    Yes, newer versions of MariaDB / MySQL don't allow you to use the root user via PHP. https://stackoverflow.com/questions/16747035/mysql-creating-a-user-with-root-privileges – Brian Gottier Feb 01 '18 at 01:20
  • So in order to create a database through a script, I have to grant the user privileges on all databases? –  Feb 01 '18 at 01:25
  • I think the advice is to create a user with privileges on all databases, then create a new database as desired, create a user with only privileges on that new database, and if you'd like, delete the user with privileges on all databases. – TCooper Feb 01 '18 at 02:55
  • That makes sense. I have created a user with all privileges except grant, which I will use while I set everything up. Should I answer this question, to show that it is resolved? –  Feb 01 '18 at 03:40

0 Answers0