Richard Korts
asked on
Create MySQL DB User / Database
I want to set up a php program that will create a MySQL database & a MySql database user for that database.
I know how to do this in phpMyadmin; I have done it a hundred times.
For reasons I don't need to explain here, I want a php script, like create_db_user.php that will create a database & a user with a password. Of course I want that user to have privileges too, I'll cross that bridge later.
Everything I find on the web that shows how to create a database assumes the existence of a User and a password, but I can find NO WAY to create a user & a password without a database. So it's like the chicken & the egg.
See attached. I ran this, it did nothing and output this: "Notice: Array to string conversion in C:\xampp\htdocs\seba\creat e_db_user. php on line 8
Array"
I have NO CLUE what that means.
I would like CLEAR & CONCISE steps on how to do this from within a php program.
Thanks
create-db-user.php
I know how to do this in phpMyadmin; I have done it a hundred times.
For reasons I don't need to explain here, I want a php script, like create_db_user.php that will create a database & a user with a password. Of course I want that user to have privileges too, I'll cross that bridge later.
Everything I find on the web that shows how to create a database assumes the existence of a User and a password, but I can find NO WAY to create a user & a password without a database. So it's like the chicken & the egg.
See attached. I ran this, it did nothing and output this: "Notice: Array to string conversion in C:\xampp\htdocs\seba\creat
Array"
I have NO CLUE what that means.
I would like CLEAR & CONCISE steps on how to do this from within a php program.
Thanks
create-db-user.php
ASKER
Dave,
I am running XAMPP, which is a Apache / MySQL / php environment for Windows.
In this instance, I do NOT want to connect to a remote host, just localhost.
So can I use user 'root' to do this? How do I know what to use for a password?
Thanks
I am running XAMPP, which is a Apache / MySQL / php environment for Windows.
In this instance, I do NOT want to connect to a remote host, just localhost.
So can I use user 'root' to do this? How do I know what to use for a password?
Thanks
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Dave,
I accidentally found out how to change the root password, which I did.
Then I ran the attached script (in the script attached I removed the "real" root password).
It created the database & the user. Yea!!
But on the user, note the attached jpg users_overview, it assigned host % rather than localhost???
What does % mean?
Thanks
create-db-user-np.php
users-overview.jpg
I accidentally found out how to change the root password, which I did.
Then I ran the attached script (in the script attached I removed the "real" root password).
It created the database & the user. Yea!!
But on the user, note the attached jpg users_overview, it assigned host % rather than localhost???
What does % mean?
Thanks
create-db-user-np.php
users-overview.jpg
ASKER
Dave,
I think I know why the user was setup as it was, I was granting privileges to a user without first creating that user.
So I think I see it all now.
Thanks!
I think I know why the user was setup as it was, I was granting privileges to a user without first creating that user.
So I think I see it all now.
Thanks!
As usual, it did what you told it to. You should get rid of the 'Any' users. They don't have a password and 'Any'one can connect by using them.
Your code does not have a connection function along with proper username and password to access the MySQL server. Note also that if you create a user with 'localhost', they will not be able to connect remotely to the MySQL server.