Creating MySQL Users
How to create MySQL users using the MySQL Console to start working on a database. (7/22/2009)
The first step to start working on MySQL thru PHP is creating a user and password. Is not a good idea to create a user without password because the lack of security.
To create a user, open the MySQL console and type the command: grant all privileges on *.* to user@domain identified by "password" with grant option;
where:
Here is an example below, I created a user "jose" with the password "pino":

mysql> grant all privileges on *.* to jose@localhost identified by "pino" with grant option; Query OK, 0 rows affected (0.53 sec) mysql> _
Now we can connect to MySQL using the user that we just created, here is an example of the code needed to connect:
<?php # get the Mysql username $user = "jose"; # Connect to the database, Server: Localhost (this machine), # User, password: pino $conn = mysql_connect("localhost", $user, "pino"); # check if the connection was successfully done if ($conn) { # If the connection was done, Set welcome message $msg="Welcome $user, you are connected to the MySql database"; } # If no connection, set a different message else { $msg="Sorry $user, you have no access to the database"; } ?> <html><head> <title>Conecting to MySQL</title> </head> <body> <h3><?php echo ($msg); ?></h3> </body> </html>
Here is the result:

In case the connection cannot be done, the message "Sorry $user, you have no access to the database" will appear.
< Hello PHP! | Homepage php Index |
Displaying Special Characters> |