Creating database and setting privilege in MySql dynamically - php

Is there a way to create a database on the online server dynamically where you can create the user and set the privilege from there it self.
i tried creating a database on my cpannel dynamically using php but it shows a error message of access denied. It only shows up a option to create the database statically and allocate the rights to a particular user.
this thing is to be done in PHP.

You have to use MySql commands in query in PHP for creating the database and setting the privileges.

Related

Testing privileges for PHP script's MySQL user

I am making a website that I expect to be hosted on several servers. I want to be able to check to make sure the MySQL user that has been created on those servers has sufficient privileges so that I can give a clear error if one of the privileges that the MySQL user requires is missing.
I found the MySQL command SHOW GRANTS FOR CURRENT_USER but its output looks like it would require a bunch of work to parse.
Is there a better way to verify that the MySQL user has sufficient permissions?
Hi try using the select statement below instead of SHOW GRANTS.
SELECT * FROM mysql.user WHERE USER LIKE 'root';

MySQL stored procedure on a read replica with PHP PDO

I've opened a bug report against MySQL http://bugs.mysql.com/bug.php?id=70793&thanks=4. There is a code example here that demonstrates this on this bug. There is also a workaround that I found that is included in the bug report. This workaround works for PHP and console
I'm running into a bizarre issue with a Stored Procedure and PHP PDO.
I am not allowed to post the body of the stored procedure, but I can provide the following information.
It works correctly on a read only replica when accessed from console with the same user that PHP PDO shares -- Edit: My initial report here is partially incorrect, the stored procedure will work if the temp table exists and will fail if the temp table doesn't exist in both console and pdo environments. See the linked bug report to MySQL for details.
I have verified that I am using the same user in both places.
The only write activity it performs is inside a temp table
It does utilize a cursor
The master and replica are both running MySQL 5.5.27
The MySQL servers are managed on AWS RDS; I have a single parameter group with a standard configuration.
My issue is that I cannot call this stored procedure from PHP PDO, I get this error
SQLSTATE[HY000]: General error: 1290 The MySQL server is running with the --read-only option so it cannot execute this statement
This makes absolutely no sense because I can call this on the read only replica as long as I'm not doing it from PHP.
Can anyone shed any light on what might be going on here?
Edit More bizarre information
I can get a console session to fail, but I can also make it succeed. It depends on if the temporary table that the stored proc uses has already been created. So let me explain my working and failing use cases
Fail
Login to the server on console
Try to call the stored proc
Fail The MySQL server is running with the --read-only option so it cannot execute this statement
Pass
Login to the server on console
Create the temp table
Try to call the stored proc
Success
Even stranger is that I most definitely drop that temp table inside the the stored proc and recreate it if it exists.
I'm reasonably certain at this point we are looking at a MySQL bug
Did you try adding the TEMPORARY keyword to the DROP TABLE command?
The TEMPORARY keyword has the following effects:
The statement drops only TEMPORARY tables.
The statement does not end an ongoing transaction.
No access rights are checked. (A TEMPORARY
table is visible only to the session that created it, so no check is
necessary.)
--read-only is only for non-root or non-replica-user. Thus, ROOT from console can still do anything but not the PHP user.

How to Import Local MySQL Database to Web Server

I have a database with two tables in it, and I have exported them into a "dump.sql" file in my computer.
I am using a free web hosting service (000webhost.com) and I have a database named "username_newdb" and I want the two tables to be imported in that database.
I tried "Import" from phpmyadmin page, but it gives the error access denied for user, I don't know why. Moreover, I prefer to import the tables into new database, not to import (and create) the whole database. Can I do this? Maybe with PHP code?
If not, creating a new database would be accepted, too.
Any help would be appreciated.
if you can connect to that database from your computer directly, you can use any mysql manager to do the import, assuming your login/password is right as backup sql is just text file with bunch of INSERTs and CREATE TABLEs (so basically phpmyadmin should not even complain).

Plesk assign privileges to database user. "No privileges" error

I am new with Plesk, I used cPlanel whole this time, and never had problems like this.
I created database on subdomain and add user to that database, and when I enter in phpMyAdmin i get error "No Privileges". I cannot connect to database trough php because of this.
This is how it looks
http://imageshack.us/photo/my-images/9/unledpyzx.png/
priv http://imageshack.us/photo/my-images/9/unledpyzx.png/
Thank you in advance
Plesk doesn't give you permissions to create databases through the phpMyAdmin tool, and instead gives you a different interface for creating databases. It looks like you've already completed that step, so you should be fine. The next thing you need to do is define your db structure, which you can do using phpMyAdmin.

php mysql connection confusion

had a bit of confusion going around in work earlier. Thought id run it by yous to see if anyone knows wats going on.
Were working on an internal administration system for our client, and its rite about to launch. Its comprised of TWO MySQL databases on the server [db_1 and db_2] and a PHP front end. [Both databases contain several tables].
There are maybe 90 different PHP files, some of which require a connection to our databases and ALL of these connections are made via a single PHP function which explicitly connects to the first database mentioned above [db_1] and supplies the login and password. And this works fine.
However, our second database, db_2, does not seem to require its own login and password to access its contents.
As soon as we connect to db_1, we seem to have full access to db_2, as long as we use the Full-Name for our tables [ie: db_2.usersTable] -> ("SELECT * FROM db_2.usersTable WHERE...").
And this is what was causing much confusion.
My question is this: Once you connect to a database on a server, do you have access to other databases on that server, or are we overlooking something???
Any feedback greatly appreciated lads...
You usually don't access a database server by a specific database, but by a user that has access to one or more databases.
for example:
mysql_connect("localhost", "user", "password") or die(mysql_error());
connects to the server and not a specific database.
Once connected to the database server you have access to all databases for which that user has permission. You just need to specify the database name in your queries if there are multiple databases that aren't the default.
mysql_select_db("myTable") or die(mysql_error());
sets myTable as the default, but you can still access other tables that the user has permission to.
I might be wrong, but doesn't PHP only connect and authenticate with the MySQL server with a user? And thus, based on that user's permissions, PHP can select any database that user has access to. I would check the permissions for the user you are connecting with...
Once you connect to a database on a
server, do you have access to other
databases on that server
If you have permissions to other databases, then yes. When you connect, you're connecting to the server and setting your default database to the one specified. Which is why you have to explicitly specify db_2 when you want to access it, but you don't have to specify db_1.

Categories