Collections:
Selecting Other User's Database in MySQL
Can You Select Someone Else Database in MySQL?
✍: FYIcenter.com
If your MySQL server is provided by an Internet service company, they will provide you one database for your use only. There are many other databases on the server for other users. But your user account will have no privilege to select other databases. If you try to access other databases, you will get an error. The following tutorial exercise shows you a guest user trying to access the system "mysql" database:
<?php
$con = mysql_connect('localhost:8888', 'guest', 'pub');
if (mysql_select_db('mysql', $con)) {
print("Database mysql selected.\n");
} else {
print("Database selection failed with error:\n");
print(mysql_errno($con).": ".mysql_error($con)."\n");
}
mysql_close($con);
?>
You will get something like this:
Database selection failed with error: 1044: Access denied for user 'guest'@'%' to database 'mysql'
⇒ Execute SQL Statements in MySQL
⇐ Selecting an Existing Database in MySQL
2017-10-23, 2349🔥, 0💬
Popular Posts:
How to execute statements under given conditions in SQL Server Transact-SQL? How to use IF ... ELSE ...
What To Do If the StartDB.bat Failed to Start the XE Instance in Oracle? If StartDB.bat failed to st...
How to continue to the next iteration of a WHILE loop in SQL Server Transact-SQL? How to use CONTINU...
How To Verify a User name with SQLCMD Tool in SQL Server? The quickest way to verify a user name in ...
How Fixed Length Strings Are Truncated and Padded in SQL Server Transact-SQL? When the length of the...