简体   繁体   English

当我没有主机的“创建”权限时,如何在mysql数据库中创建表?

[英]How do i create a table in a mysql database when i dont have 'create' permission from my host?

So basically i have signed up to several free hosts who provide a free SQL database for testing. 所以基本上我已经注册了几个免费的主机,它们提供免费的SQL数据库进行测试。 But the problem is the the user_id they create for these free databases never seems to have 'CREATE' permission. 但是问题在于他们为这些免费数据库创建的user_id似乎从未获得过“ CREATE”权限。

I am using PHP and PDO to connect to the database and i need to programmatically create a table with PDO. 我正在使用PHP和PDO连接到数据库,并且需要以编程方式使用PDO创建表。

How do i get 'CREATE' permission for my user_id or create a new user who has the required permission? 如何获得我的user_id的“创建”权限或创建具有所需权限的新用户?

I use phpmyadmin to connect to these databases manually. 我使用phpmyadmin手动连接到这些数据库。

EDIT: Kindly note that i can create tables with PHPMyAdmin but not through PDO. 编辑:请注意,我可以使用PHPMyAdmin创建表,但不能通过PDO创建表。 When i use PDO, server tells me i don't have CREATE permssion 当我使用PDO时,服务器告诉我我没有创建权限

If you can create tables through PHPMyAdmin and not through your own PHP script then it might be because PHPMyAdmin is using different MySQL user. 如果可以通过PHPMyAdmin创建表,而不是通过自己的PHP脚本创建表,则可能是因为PHPMyAdmin使用了不同的MySQL用户。 In your PHPMyAdmin goto "SQL" button on top and enter this query: 在您的PHPMyAdmin中,转到顶部的“ SQL”按钮,然后输入以下查询:

SELECT CURRENT_USER();

It will show you the logged in user in PHPMyAdmin, try using this user in your PHP script. 它会向您显示PHPMyAdmin中的登录用户,请尝试在您的PHP脚本中使用该用户。

If you don't wish to use the same user. 如果您不想使用同一用户。 Then in the SQL query execute this: 然后在SQL查询中执行以下命令:

GRANT ALTER, CREATE ON your_db_name TO 'your_php_user'@'localhost';

This will give the CREATE and ALTER TABLE permission to your user. 这将向您的用户授予CREATE和ALTER TABLE权限。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM